var Spry;
if (!Spry.Utils) Spry.Utils = {};
var cp1; var cp2; var cp3;

Spry.Utils.addUnLoadListener = function(handler)
{
if (typeof window.addEventListener != 'undefined')
	window.addEventListener('unload', handler, false);
else if (typeof document.addEventListener != 'undefined')
	document.addEventListener('unload', handler, false);
else if (typeof window.attachEvent != 'undefined')
	window.attachEvent('onunload', handler);
};

Spry.Utils.CheckArray = function(a, s){
	for (i=0; i<a.length; i++){if (a[i] == s)return i;}return null;
};

Spry.Utils.Cookie = function(type,string,options){
	if(type == 'create'){
		var expires='';
		if(options.days != null){
			var date = new Date();
			var UTCString;
			date.setTime(date.getTime()+(days*24*60*60*1000));
			expires = "; expires="+date.toUTCString();
		}
		var thePath = '; path=/';
		if(options.path != null){
			thePath = '; path='+options.path;
		}
		document.cookie = options.name+'='+escape(string)+expires+thePath;
	}else if(type == 'get'){
		var nameEQ = options.name + '=';
		var ca = document.cookie.split(';');
		for (var i=0; i<ca.length; i++){
			var c = ca[i];
			while (c.charAt(0)==' '){
			c = c.substring(1,c.length);
		}if (c.indexOf(nameEQ)==0) return unescape(c.substring(nameEQ.length,c.length)).split(",");
		}return null;
	}else if(type == 'destory'){
		Spry.Utils.Cookie('create','',{
			name: options.name
		});
	}else if(type == 'add'){
		var c = Spry.Utils.Cookie('get','',{name:options.name});
		if (typeof string == 'object') {
			for (i = 0, str; str = string[i], i < string.length; i++) {
				if (Spry.Utils.CheckArray(c, str) == null)c.push(str);
			}
		}else{
			if (Spry.Utils.CheckArray(c, string) == null) c.push(string)
		}
		Spry.Utils.Cookie('create',c,{name:options.name});		
	}
};

	// * check if we have a panel to set from cookie value
	Spry.Utils.addLoadListener(function(){
		var col = Spry.Utils.Cookie('get','',{name:'tdtp10'});
		if(col)
			  {
				if(col[0] == 'false')cp1 = new Spry.Widget.CollapsiblePanel("cp1",{contentIsOpen:false});
				else cp1 = new Spry.Widget.CollapsiblePanel("cp1");
				
				if(col[1] == 'false')cp2 = new Spry.Widget.CollapsiblePanel("cp2",{contentIsOpen:false});
				else cp2 = new Spry.Widget.CollapsiblePanel("cp2");
				
				if(col[2] == 'false')cp3 = new Spry.Widget.CollapsiblePanel("cp3",{contentIsOpen:false});
				else cp3 = new Spry.Widget.CollapsiblePanel("cp3");
	
			  }else{
				  
				cp1 = new Spry.Widget.CollapsiblePanel("cp1",{contentIsOpen:true});
				cp2 = new Spry.Widget.CollapsiblePanel("cp2",{contentIsOpen:true});
				cp3 = new Spry.Widget.CollapsiblePanel("cp3",{contentIsOpen:true});
		}
	 });

Spry.Utils.addUnLoadListener(function(){
	var panel = new Array(cp1.isOpen(),cp2.isOpen(),cp3.isOpen());
	Spry.Utils.Cookie('destory','',{name:'tdtp10'});
	Spry.Utils.Cookie('create',panel,{name:'tdtp10'});
});
