/**
* Styleswitch stylesheet switcher built on jQuery
* initial version
* By Kelvin Luck ( http://www.kelvinluck.com/ )
* (Attribution, Share Alike License)
**/

var CookieVersion = "v2";

function getContrast() {
	/* retrieves a value for the contrast */	
	var theContrast;
	if(readCookie('contrast' + CookieVersion)) {
		theContrast = readCookie('contrast' + CookieVersion);
	}
	else {
		theContrast = "contrastlo";
	}
	createCookie('contrast' + CookieVersion, theContrast, 365);
	return theContrast;
}

function getFont() {
	
	var theFont;
	if(readCookie('font' + CookieVersion)) {
		theFont = readCookie('font' + CookieVersion);
	}
	else {
		theFont = "font1";
	}
	createCookie('font' + CookieVersion, theFont, 365);
	return theFont;
}

function contrastClick(theContrast) {
	//switchStylestyle(getFont(), theContrast);
	switchStylestyle(theContrast);
}

function fontClick(theFont) {
	//switchStylestyle(theFont, getContrast());
	switchStylestyle(getContrast());
}

function setInactive(title) {
	$('#toggle_' + title).removeClass(title + "_active");
	$('#toggle_' + title).addClass(title + "_inactive");
	$('#toggle_' + title).html("<img src=\"fileadmin/site/digid/img/" + title + "_inactive.gif\" alt=\"laag contrast\" id=\"toggle_" + title + "_img\" />");
}
function setActive(title) {
	$('#toggle_' + title).removeClass(title + "_inactive");
	$('#toggle_' + title).addClass(title + "_active");
	$('#toggle_' + title).html("<img src=\"fileadmin/site/digid/img/" + title + "_active.gif\" alt=\"hoog contrast\" id=\"toggle_" + title + "_img\" />");
}

//function switchStylestyle(theFont, theContrast) {
function switchStylestyle(theContrast) {
	
	//var styleName = theFont + "_" + theContrast;
	var styleName = theContrast;

	//setInactive("font1");
	//setInactive("font2");
	//setInactive("font3");
	setInactive("contrastlo");
	setInactive("contrasthi");
	//setActive(theFont);
	setActive(theContrast);

	$('link[@rel*=style][@title]').each(function(i) 
	{
		var matchPattern = /alter/;
		if(this.getAttribute('rel').match(matchPattern)) {
			// alternative stylesheet
			this.disabled = true;
		}
		else {
			// do nothing, do not disable style sheet
		}

		if (this.getAttribute('title') == styleName) {
			this.disabled = false;
		}
	});

	//createCookie('font' + CookieVersion, theFont, 365);
	createCookie('contrast' + CookieVersion, theContrast, 365);
}

// 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+"="+value+expires+"; path=/";
}
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
