/**
* Load alternative style sheet (additional CSS doc. Overwrites styles)
* For template demo pages
* 
* All working, but the Style1/2 items need to be links for usability. No one is going to click them!
*/
var switcher = {
	init: function() {
		
		//Listen to switch link clicks
		$E.on($('switchLinks').getElementsByTagName('a'), 'click', switcher.setStyle);
	},
	
	setStyle:function(e) {
		$E.preventDefault(e);
		
		var link = $E.getTarget(e);
		var label = link.innerHTML.toLowerCase();
				
		//Add additional style sheet to doc
		if(label.search(/style 2/) > -1 || label.search(/style b/) > -1) {
			
			var css = document.createElement('link');
			css.href = 'css/style2.css';
			css.type = 'text/css';
			css.rel = 'stylesheet';
			css.id = 'style2css'; //Easy removal
			
			document.getElementsByTagName('head')[0].appendChild(css);
		}
		
		//Remove additional sheet
		else {
			
			//If IE then fallback to HTTP link. (Doesn't support removing CSS from DOM)
			if(navigator.userAgent.search(/msie/i) != -1) {
				window.location = $E.getTarget(e).href;
				return;
			}
						
			var style2 = $('style2css');
			if(!style2) return;
			style2.parentNode.removeChild(style2);
		}
	}
}
$E.onDOMReady(switcher.init);
