$(function(){
	
	$(".tab_bar ul li a").click(function(){
		showRemoteTab($(this).attr('href').substr(1));
		return false;
	});
		
	var cookie = readCookie('remote_state');
	if(cookie == null){
		showRemoteTab('places');
	}else{
		showRemoteTab(cookie);
	}
	
});

function showRemoteTab(tab)
{
	//JSON
	//createCookie('remote_state','{"active":"'+$(this).attr('href').substr(1)+'"}',30);
	createCookie('remote_state',tab,30);
	
	$(".tab_content ul").hide();
	if (tab == "causes"){
		$(".tab_bar").addClass('switch');
	} else {
		$(".tab_bar").removeClass('switch');
	}
	$('#'+tab).show("fast", function(){
		if(showScrollbars()){
			//$('#placescauses').jScrollPane({'showArrows':true});
		}
	});	
}

// 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)
{
	this.createCookie(name,"",-1);
}

