function getNewLinks(rootDiv){
	/*
	var dTagChildren = $(rootDiv).getElementsByTagName("div");
	for(var i=0;i<dTagChildren.length;i++){
		if(dTagChildren[i].getAttribute('rel')=='link'){
			dTagChildren[i].fade({ duration: 3.0, from: 0, to: 1 });
		}
	}
	*/
	$(rootDiv).fade({ duration: 2.0, from: 0, to: 1 });
}

var cloudVisible = true;

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 toggleCloud(elm){
	if(cloudVisible){
		$('cloudterms').style.display = 'none';
		cloudVisible = false;
		elm.innerHTML = "[ + ]";
		setCookie('cloud','false',30);
	} else {
		$('cloudterms').style.display = 'block';
		cloudVisible = true;
		elm.innerHTML = "[ - ]";
		setCookie('cloud','true',30);
	}
}

function doSelectedAction(li){
	var qVal = li.getAttribute("q");
	location.href = "/tv_links/watch_"+qVal.replace(/\s+/g,"_")+"_online.html";
	$('autocomplete').value = qVal;
}

function doSearchAction(qVal){
	if(qVal!=='What do you want to watch?'){
		location.href = "/tv_links/watch_"+qVal.replace(/\s+/g,"_")+"_online.html";
	}
}

function inputOnKeyUp(elm){
	if(elm.value==''){
		elm.value = 'What do you want to watch?';
	}
}

function inputOnFocus(elm){
	if(elm.value=='What do you want to watch?'){
		elm.value = '';
	}
}

function inputOnBlur(elm){
	if(elm.value==''){
		elm.value = 'What do you want to watch?';
	}
}

function statUpdater(hash){
	var headers = new Array("Referer","http://www.tubezu.com/index.php");
	new Ajax.Request('/stats.php?hash='+hash,{requestHeaders: headers,onSuccess: function(transport){}});
/*	new Ajax.Request('http://www.google.com',
	  {
	     requestHeaders: headers,
	     onSuccess: function(transport) {
	       var response = transport.responseText || null;
	       mainDiv = $(containerToPop);
	       if(response==null){
		    mainDiv.innerHTML = "Error";
		}else{
		  mainDiv.innerHTML = response;
		}
	    }
	}); */
}

function genericPop(containerToPop,fileToRequestFrom,argsToBePassed,funcCalls){
	var sendMethod = 'get';
	//Where funcCalls is in the format: functionCalls={fCall: function(){dofunction();}}
	var mainDiv = $(containerToPop);
	if(mainDiv){
		mainDiv.innerHTML = "<table style=\"border:0px;background:#FFFFFF;\" cellspacing=\"0\" cellpadding=\"5\" width=\"100%\"><tr><td align=\"center\"><img border=\"0\" src=\"/images/default/ajax-loader.gif\" alt=\"\"></td></tr><tr><td style=\"font-size:12px;color:#1D1D1D;\" align=\"center\">Loading...</td></tr></table>";
		new Ajax.Request(fileToRequestFrom + '?' + argsToBePassed,
		{
			method:sendMethod,
			onSuccess: function(transport){
				var response = transport.responseText || null;
				if(response==null){
					mainDiv.innerHTML = "Error Loading - Please Try Again";
				} else {
					mainDiv.innerHTML = response;
					funcCalls['fCall']();
				}
		},
		onFailure: function(){
			mainDiv.innerHTML = "Error Loading - Close Window";
		}
		});
	}
}