var Spry;
if (!Spry.Utils) Spry.Utils = {};
var acc1; //declare vars outside the function so u can use then acc panel everywhere

// This function will fire anything when u leave the current page.

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});		
	}
};
	  
var accset = gAccSet;

Spry.Utils.addLoadListener(function(){
	var acc = Spry.Utils.Cookie('get','',{name:'acc_history'});
	
	if (accset) acc1 = new Spry.Widget.Accordion("navAccordion", {useFixedPanelHeights: false, defaultPanel: (accset-1) });
	else if(acc)//checks if acc contains data
		  {
		  	acc1 = new Spry.Widget.Accordion("navAccordion", {useFixedPanelHeights: false, defaultPanel:(acc-0)});
		  }else{
		  acc1 = new Spry.Widget.Accordion("navAccordion", { useFixedPanelHeights: false, defaultPanel: -1 } );
	}
	

  	
 });
 
 

Spry.Utils.addUnLoadListener(function(){
	var panelNumber = acc1.getCurrentPanelIndex();
	Spry.Utils.Cookie('destory','',{name:'acc_history'});
	Spry.Utils.Cookie('create',panelNumber,{name:'acc_history'});
});

Spry.Utils.addLoadListener(function makeMenus(){
	Spry.$$(".MenuBarHorizontal").forEach(function(n) {window[n.id] = new Spry.Widget.MenuBar(n);});
	var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1");
	});
