/**
* Styleswitch stylesheet switcher built on jQuery
* Under an Attribution, Share Alike License
* By Kelvin Luck ( http://www.kelvinluck.com/ )
**/

$(document).ready(function() {
	var c = readCookie('pstyle');	
	if (c) switchStylestyle('pstyle',c);
	var d = readCookie('pstyleimg');
	if (d) switchStylestyle('pstyleimg',d);

	if(d.match(/(on){1}/gi)!=null){

		$("img.onbut").src("/style/EPFA/img/share_buttons/funview_on.gif");
		$("img.offbut").src("/style/EPFA/img/share_buttons/funview_off.gif");					

		}else{		
		$("img.onbut").src("/style/EPFA/img/share_buttons/funview_off.gif");
		$("img.offbut").src("/style/EPFA/img/share_buttons/funview_on.gif");		
			}
	
});
function switchStylestyle(cn,styleName)
{
	//alert(cn);
	var closed = "";
	var opened = "";	
	$('link[@rel*=style][@title]').each(function(i) 
	{
		if(this.getAttribute('title')!=null){
		  //alert(this.getAttribute('title').match(/^[a-z]+/gi));
			if(this.getAttribute('title').match(/^[a-z]+/gi)== cn){closed = closed+this.getAttribute('title')+"\n";this.disabled = true;}			
			if (this.getAttribute('title') == styleName){
			   opened  = opened+this.getAttribute('title')+"\n";
				//alert(document.cookie+"\ncookie:"+readCookie(cn)+"\ngoto:"+styleName);
				this.disabled = false;} 					
			}
	});
	//alert("========Closed========\n"+closed+"======Opened========\n"+opened+"\n===============Cookie==============\n"+readCookie(cn));
	createCookie(cn, styleName);
}

// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+escape(value)+expires+";";
}
function readCookie(name)
{
	var nameEQ = 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 c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions
function dismode(mode){
	var c = readCookie('pstyle');
	var d = readCookie('catpstyle');	
	switchStylestyle('pstyle','pstyle.'+mode);
}
function toggle_image_on(){
	var c = readCookie('pstyleimg');

		$("img.onbut").src("/style/EPFA/img/share_buttons/funview_on.gif");
		$("img.offbut").src("/style/EPFA/img/share_buttons/funview_off.gif");		
	switchStylestyle('pstyleimg','pstyleimg.on');
	}
function toggle_image_off(){
	var c = readCookie('pstyleimg');
		$("img.onbut").src("/style/EPFA/img/share_buttons/funview_off.gif");
		$("img.offbut").src("/style/EPFA/img/share_buttons/funview_on.gif");			
	switchStylestyle('pstyleimg','pstyleimg.off');
	}	
