/* © Copyright 2007, Entriq Inc. This code is the property of Entriq Inc. 
All rights reserved. This code can be used only for the purposes specified 
in your Master Service Agreement (MSA) with Entriq. You may not copy, sell, 
distribute, modify, extend, or use the code in any way that is not authorized 
and not in accordance with your agreement with Entriq without prior written 
permission from Entriq. */


/* This version requires SWFObject */


/**
    FlashCookieBaker.init(
    
        strSwfPath:String,            Path to SWF file.
        
        strDivID: String,             ID of target DIV in which to place SWF. Will become ID of Object/Embed when done
        
        strCallback: String,          Name of your arbitrary callback function AS A STRING. Will be called 
                                      with "true" as single argument when Baker can be used.
                                   
        strCookieSpace: String,       Arbitrary name of cookie namespace to use. Optional: Defaults to "FlashCookieBaker"
                                      Basically a way to organize cookies beyond the cookie name, if needed.
    )


Once your callback handler has been called, you can use:

FlashCookieBaker.write(keyName, keyVal, [cookiespace]);
FlashCookieBaker.read(keyName, [cookiespace]);
FlashCookieBaker.clear([cookiespace]);


*/

var FlashCookieBaker = {

    ID:"",
    CallbackHandler:null,
    CookieSpace: null,
    isReady: false,
    
    thisMovie: function(movieName) {
        if (navigator.appName.indexOf("Microsoft") != -1) {
            return window[movieName];
        } else {
            if(document[movieName].length != undefined){
                return document[movieName][1];
            }
            return document[movieName];
        }
    },
    
    write: function(keyName, keyVal, ns){
        var oBaker = FlashCookieBaker.thisMovie(FlashCookieBaker.ID);
        if(oBaker){
            oBaker.BakerPut(keyName, keyVal, ns);
        }
        return true;
    },
    
    read: function(keyName, ns){
        var oBaker = FlashCookieBaker.thisMovie(FlashCookieBaker.ID);
        if(oBaker){
            return oBaker.BakerGet(keyName, ns);
        }
        return null;
    },
    
    clear: function(ns) {
        var oBaker = FlashCookieBaker.thisMovie(FlashCookieBaker.ID);
        if(oBaker){
            oBaker.BakerClear(ns);
        }
        return true;
    },
    
    init: function(strMoviePath, ID, CallbackHandler, CookieSpace){
        FlashCookieBaker.CallbackHandler = CallbackHandler;
        FlashCookieBaker.ID = ID || "FlashBaker";
        FlashCookieBaker.CookieSpace = CookieSpace || "FlashBakerCookieSpace";
        strMoviePath = strMoviePath || "FlashBaker.swf";
        var minVers = "9.0.0";
        var DOMParams = null;
        var FlashVars = {CallbackHandler:FlashCookieBaker.CallbackHandler, CookieSpace:FlashCookieBaker.CookieSpace};
        var MovieParams = {allowScriptAccess:"always", wmode: "transparent"};
        swfobject.embedSWF(strMoviePath, FlashCookieBaker.ID, "1", "1", minVers, DOMParams, FlashVars,  MovieParams );
        return true;
    }
}



