var body = document.body;
body.className = "yui-skin-sam";
body.id = "yahoo-com";	
function readCookie (cookieName) {
	var cookies = document.cookie;
	var start = cookies.indexOf(cookieName);
	if (start == -1 || cookieName === "") { return ""; }
	var end = cookies.indexOf(";", start);
	if (end == -1) { return ""; }
	return unescape(cookies.substring(start+cookieName.length+1, end));
}	

function yahooAjaxObject(url) {
	var ac = document.getElementById('tabContent');
	var tabContainer = document.getElementById('tabContainer');
	YAHOO.namespace("category");
	if (!YAHOO.category.wait) {
		YAHOO.category.wait = new YAHOO.widget.Panel("wait",
            {  width:"240px",  
			   fixedcenter:true,  
			   close:false,  
			   draggable:false,  
			   zindex:4, 
			   modal:false, 
			   visible:false 
            } );
		YAHOO.category.wait.setHeader("Updating Content...");
		YAHOO.category.wait.setBody("<img src=\"http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif\"/>");
		YAHOO.category.wait.render(tabContainer);
	} 	
	document.body.style.cursor="wait";
	var handleSuccess = function (o) {
		ac.innerHTML = o.responseText;
		ac.style.visibility = "visible";
		YAHOO.category.wait.hide();
		document.body.style.cursor="auto";
	};
	var handleFailure = function (o) {
		ac.style.visibility = "visible";
		YAHOO.category.wait.hide();
		document.body.style.cursor="auto";
	};
	var callback = 
	{
		success:handleSuccess,
		failure:handleFailure
	};
	YAHOO.category.wait.show();
	var request = YAHOO.util.Connect.asyncRequest("GET", url, callback);	
}

function updateContent(e,f)
{
	var activeCookieString = 'activeTabCat' + f;
	// If cookie is different OR Filter is set Fetch.
	var cookieRead = readCookie(activeCookieString);
	SetActive(e);
	if (cookieRead != e)
	{
		var exdate = new Date();
		exdate.setDate(exdate.getDate()+7);
		document.cookie = activeCookieString + "=" + escape(e) + ((7===null) ? "" : ";expires="+exdate.toGMTString());
		var url = "fetch/" + e + ".php?category=" + f;
		yahooAjaxObject(url);
	}
}

function SetActive(a)
{
	var active = document.getElementById(a);
	var deactivate = function (el) { YAHOO.util.Dom.removeClass(el,"active"); }
	var tabs = YAHOO.util.Dom.getChildren('tabNavUl');
	var batch = YAHOO.util.Dom.batch(tabs, deactivate);
	YAHOO.util.Dom.addClass(active, "active");
}
