﻿pandora.util.cookie.prototype = {
	initialize : function(){
	},

	// set cookie value
	set : function (sName, sValue, expireSeconds) {
		var sDomain = ".pandora.tv";
		var todayDate = new Date();
		var ExpireTime = new Date(todayDate.getTime()+expireSeconds*1000);
		document.cookie = sName + "=" + sValue + ";" + ((expireSeconds) ? "expires=" + ExpireTime.toGMTString() + ";" : "") + "domain=" + sDomain + ";path=/;";
	},

	// get cookie value
	get : function (sName) {
		var aCookie = document.cookie.split("; ");
		for (var i=0; i < aCookie.length; i++) {
			var aCrumb = aCookie[i].split("=");
			if (sName == aCrumb[0]) {
				return aCrumb[1];
			}
		}
		return null;
	},

	// delete cookie
	destroy : function (sName) {
		this.set(sName, "", 0);
	},

	// update cookie
	update : function (expireSeconds) {
		var CookieList = document.cookie.split("; ");
		for(var i=0;i<CookieList.length;i++) {
			var Cookies = CookieList[i].split("=");
			if(Cookies[0] == "SavedID") {
				continue;
			}
			this.set(Cookies[0], Cookies[1], expireSeconds);
		}
	}
};

var oCookie = new pandora.util.cookie();

/********************************************************************************
 * @projectDescription Macromedia Flash player - TSharedObject
 *
 * @author riho.kim@pandora.tv, tizie80@nate.com
 * @messanger (msn)kim2000version@hotmail.com, (nate)tizie80@nate.com
 * @site blog.ecmas4.com
 * @version 0.0.1
 * @usage var TClass = ;
 *
 * @sdoc
 * @namespace TSharedObject
 * @import %designHost%/so/sharedObj.swf
 ***********************************************************************************/
var TSharedObject = Class.create();
	TSharedObject.prototype = {
		/* interface */
		_globalStore : null,

		/* public */
		isLoaded : false,

		/* private */
		isIE : !!(window.attachEvent && !window.opera),

		initialize : function() {},

		/* private
		 * swf onLoade callback
		 */
		_isLoaded : function() {
			this.isLoaded = true;
		},

		/* private */
		_create : function() {
			var tag = [];
			var codeBase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0';
			var classid = 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000';

			switch(this.isIE) {
				case true :
						tag.push('<object id="globalStorage__" codebase="'+ codeBase +'" width="0" height="0" align="middle" classid="'+classid+'" >');
						tag.push('<param name="movie" value="'+ variable['designHost'] +'so/sharedObj.swf" />');
						tag.push('<param name="quality" value="high" />');
						tag.push('<param name="play" value="true" />');
						tag.push('<param name="loop" value="true" />');
						tag.push('<param name="scale" value="showall" />');
						tag.push('<param name="wmode" value="window" />');
						tag.push('<param name="devicefont" value="false" />');
						tag.push('<param name="bgcolor" value="#000000" />');
						tag.push('<param name="menu" value="true" />');
						tag.push('<param name="allowFullScreen" value="true" />');
						tag.push('<param name="allowScriptAccess" value="always" />');
						tag.push('<param name="salign" value="" />');
						tag.push('</object>');
				break;
				default:
						tag.push('<embed id="globalStorage__" name="globalStorage__" width="0" height="0" src="'+ variable['designHost'] +'so/sharedObj.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" align="middle" play="true" loop="true" scale="showall" wmode="window" devicefont="false" bgcolor="#000000" menu="true" allowFullScreen="true" allowScriptAccess="always" salign="" type="application/x-shockwave-flash" > </embed>');
				break;
			}

			new Insertion.Bottom(document.body, tag.join(''));
		},

		/* public */
		setup: function(){
			/* exist Shared Object Movie */
			if(this._globalStore != null) return true;

			this._create();

			this._globalStore = (this.isIE) ? window['globalStorage__'] : document['globalStorage__'];
		},

		/** public
		 * SharedObject.data[key] = value; use in Action script
		 * @param {String} key
		 * @param {String} value
		 * @param {String} so	Shared-Object filename
		 */
		setItem : function(key, value, so) {
			var value = encodeURIComponent(value);
			return this._globalStore.setItem(key, value, so);
		},

		/** public
		 *
		 * @param {String} key
		 * @param {String} so	Shared-Object filename
		 */
		getItem : function(key, so) {
			return decodeURIComponent(this._globalStore.getItem(key, so));
		},

		/** public
		 *
		 * @param {String} key
		 * @param {String} so	Shared-Object filename
		 */
		removeItem : function(key, so) {
			return this._globalStore.removeItem(key, so);
		}
	};

	/* singleton pattern */
	TSharedObject.__instance__ = null;
	TSharedObject.getInstance = function () {
		return (this.__instance__ == null)
			? this.__instance__ = new TSharedObject()
			: this.__instance__;
	};

	var SharedObject = TSharedObject.getInstance();

