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

(function($)
{
	$(document).ready(function() {
	
	$("#loading").animate({opacity: "0"}, 1000);
	
		$('.styleswitch').click(function()
		{
			switchStylestyle(this.getAttribute("rel"));
			return false;
		});
//		var c = readCookie('style');
//		if (c) switchStylestyle(c);

		$('a.more').click(function() {
			var id = this.getAttribute("id");
			var id_pieces = id.split('_');
			if (id_pieces.length==2)
			{
				var more_id = 's_'+id_pieces[1];
//alert(more_id);
				$('ul#'+more_id).slideToggle("slow");
			}
			
			return false;	
		});
		
		$('li.tips a').tooltip({
		    track: true, 
   			delay: 0, 
			showURL: false, 
			showBody: " - ", 
			fade: 250 
		});
	});

	function switchStylestyle(styleName)
	{
		$('link[rel*=style][title]').each(function(i) 
		{
			this.disabled = true;
			if (this.getAttribute('title') == styleName) this.disabled = false;
		});
		
		//change the weather image path - TODAY
		changeWeather($('#weather_today'),styleName);
		//change the weather image path - TOMORROW
		changeWeather($('#weather_tmw'),styleName);
		
		//save the style
		createCookie('style', styleName, 365);
	}


/* 

SHOW/HIDE Remember Media Feeds 
Each media feed will have wrapper div with same class
These divs will show or hide by putting a class on it
The classes will be read/written by the cookie

1. Create a Cookie
2. 


*/	


//END SHOW/HIDE	
	
	
})(jQuery);

function changeWeather(weather,styleName)
{
	weather_path = weather.css("background");
	//replace /weather[]/ with /weather and the new style
	weather_path = weather_path.replace(/\/weather(.)*\//g,'/weather_'+styleName+'/');
	weather.css("background",weather_path);
}

// 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