function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

$(document).ready(function()
{
	$("#sectionTabs li a").click(function()
	{
		parent_li = $(this).parent();
		currentlySelected = "c"+$("li.active a").attr("id").substring(1);
		cID = "c"+$(this).attr("id").substring(1);
		if(!parent_li.hasClass("active"))
		{
			parent_li.siblings("li.active").removeClass("active");
			parent_li.addClass("active");
			$("#"+currentlySelected).slideUp(250,function(){$("#"+cID).slideDown(250);});
			setCookie("lastServiceTab"+$("#pvwrapper h1:first").text(),"s"+$("li.active a").attr("id").substring(1));
		}	
	});
	
	$("a.productLink").click(function(event)
	{
		event.preventDefault();
		bookmark = $(this).attr("href");
		currentlySelected = "c"+$("li.active a").attr("id").substring(1);
		$("li.active").removeClass("active");
		$("#s1").parent().addClass("active");
		$("#"+currentlySelected).slideUp(250,function(){$("#c1").slideDown(250,function(){location.hash=bookmark;});});
	});
	
	$("#notifyMe").click(function(event)
	{
		event.preventDefault();
		var serviceID = $(this).children(".serviceID").text();
		$.ajax(
		{
			type: "POST",
			url: "/account/add_notification.jsp",
			data: "service="+encodeURIComponent(serviceID),
			success: function(message)
			{
				createMessage(message);
			}
		});
	});
	
	var lastServiceTab = getCookie("lastServiceTab"+$("#pvwrapper h1:first").text());
	if(lastServiceTab!="")
	{
		$("#"+lastServiceTab).click();
	}
});