/**
* Styleswitch stylesheet switcher built on jQuery
* Under an Attribution, Share Alike License
* By Kelvin Luck ( http://www.kelvinluck.com/ )
**/

(function($)
{
	var divHolder="";
	
	$(document).ready(function() {
		divHolder = $("#sliderWrap").html();
		$('.styleswitch').click(function()
		{
			switchStylestyle(this.getAttribute("rel"));
			$('#slider').nivoSlider({
				effect:'fade',
				animSpeed:500,
				pauseTime:5000,
				directionNav:false, //Next & Prev
				directionNavHide:false, //Only show on hover
				controlNav:true, //1,2,3...
				controlNavThumbs:true, //Use thumbnails for Control Nav
				keyboardNav:true, //Use left & right arrows
				pauseOnHover:false, //Stop animation while hovering
				manualAdvance:false //Force manual transitions
			});
			return false;
			
		});
		var c = readCookie('style');
		if (c) {
			switchStylestyle(c);
		}else{
			$(".styles2").remove();			
			$(".styles3").remove();			
			
		}
		
	});

	function switchStylestyle(styleName)
	{
		$("#sliderWrap").html(divHolder);
		$('link[@rel*=style][title]').each(function(i) 
		{
			var toHide = "." + this.getAttribute('title');
			this.disabled = true;
			if (this.getAttribute('title') == styleName) {
				
				this.disabled = false;			
			}else{	
				$(toHide).remove();			
			}
		});
		//Because the javascript is dynamically rewriting the images, the nivoSlider needs to be re-initialized
		//So the dance:
		//1. Hold the inital images from all colors in a variable
		//2. Remove the classes from the other colors not selected
		//3. Call the slider function

		createCookie('style', styleName, 365);


	}

})(jQuery);
// 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
