/*  
	- use CB_Cookie to store values in flash file between different sessions and browser types...
	- check if flash is ready (CB_Is_Ready) before you use CB_Cookie
	
	uses: swfobject.js - 2.0 
	uses: CB_Cookie.swf
	
	on the page you use it declare vars:	
		var CB_flash_id  = 'CBFlash';   * flash id 
		var CB_flash_holder_id ='CBFlashHolder';  * div id
	add DomLoaded.load(CB_create_Flash);
*/



/* 
	create flash file
	/interface/script/CB_Cookie.swf
*/
function CB_create_Flash(){
	var flashvars = false;
	var params = {  
		quality: "high",
		allowScriptAccess:  "always",
		swliveconnect: "true"
	};
	var attributes = {  
		id: CB_flash_id,  
		name: CB_flash_id
	};
	swfobject.embedSWF("/common/pokerFlash/CB_Cookie.swf", CB_flash_holder_id, "0", "0", "9.0.0","expressInstall.swf", flashvars, params, attributes);
}


function CB_Is_Ready(){
	if (!CB_Cookie) return false; 
	if (CB_Cookie.is_ready()) return true;
	return false;	
}


/*  initialized from flash using flash_ready function (below) ... */
var CB_Cookie =
{
	init: function(flash_id)
	{
		this.flash_id  		= flash_id;
		this.flash_ready 		= false;
		this.flash_able 		= false;
		this.flash_cookie  	= null;
		this.flash_alert  		= true;

		this.flash_is_ready();
	},

	flash_is_ready: function()
	{
		if(!document.getElementById || !document.getElementById(this.flash_id)) return;
		if(!this.get_movie(this.flash_id)) return;

		this.flash_ready = true;
		this.flash_able  = this.flash_cookie.f_cookie_able();
	},


	get_movie: function()
	{
    	if (navigator.appName.indexOf("Microsoft") != -1)
    	{
    		this.flash_cookie = window[this.flash_id];
    	}
    	else
    	{
    		this.flash_cookie =  document[this.flash_id];
    	}

    	return ((this.flash_cookie) ? true : false);
	},

	is_able: function()
	{
		if(this.flash_alert && !(this.flash_ready && this.flash_able))
		{
			alert("CB_Cookie not initialized correctly.");
		}
		return (this.flash_ready && this.flash_able);
	},
	
	is_ready: function(){
		return (this.flash_ready && this.flash_able);
	},

	del: function(key)
	{
		if(!this.is_able()) return;
		this.flash_cookie.f_delete_cookie(key);
	},

	get: function(key)
	{
		if(!this.is_able()) return;
		var ret = this.flash_cookie.f_get_cookie(key);
		return ((ret == 'null') ? '' : ret);
	},

	set: function(key,val)
	{
		if(!this.is_able()) return;
		this.flash_cookie.f_set_cookie(key,val);
	}
};



/* used internaly from flash */
function CB_flash_ready()
{
	CB_Cookie.init(CB_flash_id);
}

