//	alert('styleswitch');               
   

// 	INSTRUCTIONS:
//	Default theme: set name below and on <link> title; rel="stylesheet"
//	Alternate theme: set name on <link> title; rel="alternative stylesheet"
//  Styleswitch links: link to stylesheet.css; set class="styleswitch"; set rel to title name as above     



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

$(document).ready(function() {
	
	var theme = readCookie('style');
	
	// READ COOKIE ON LOAD AND SET STYLE IF COOKIE IS PRESENT (OTHERWISE LOAD DEFAULT STYLESHEET)
	if (theme) {
		switchStylestyle(theme);
			/* this is for a THEME SELECT menu
			if ( $('#theme_select .styleswitch[@selected]').attr('rel') != theme ) { 
				set_theme_select(theme); 
			*/
		}
	else { 
		   
		
		// ********************************* 
		
			// SET DEFAULT THEME
			theme = 'curtain'; 
			  
		// *********************************
		
		
		$('body').addClass(theme); // used for sIFR
	}
	
	
	// ASSIGN STYLESWITCH TO LINKS
	$('.styleswitch').click(function() {
		$('body').removeClass(theme);
		theme = this.getAttribute('rel')
		switchStylestyle(theme); // set new theme
		this.blur();
		return false;
	});
	

	
});


function switchStylestyle(theme) {
	// ACTIVATE STYLESHEET
		$('link[@rel*=style][@title]').each(function(i) {
			this.disabled = true;
			if (this.getAttribute('title') == theme) this.disabled = false;
		});
	// SET CLASS FOR sIFR
		$('body').addClass(theme);
		try {
			sIFR.rollback();
			sIFR.activate(headings); // this function call doesn't work
		} catch(e) {}
	// CREATE COOKIE LATER
		createCookie('style', theme, 365);
}


// SET SELECT TO STYLESHEET
function set_theme_select(theme) {
	// alert('setting style select');
	$('#theme_select .styleswitch').each(function() {
			$(this).removeAttr('selected');
	});
	$('#theme_select .styleswitch').each(function() {
		if ( $(this).attr('rel') == theme ) {
			$(this).attr('selected','selected'); 
		}
	});
}


/*	REQUIRES COOKIE FUNCTIONS */
