function displayHulu(param)
{
	var oDiv = document.getElementById("result");
	oDiv.innerHTML = "&nbsp;";
	if(param.value.items[0] != undefined ) //&& param.value.items[0].title != "" )
	{
		var total = param.value.items.length;
		var table = document.createElement("table");
		table.border = "0";
		table.cellpadding = "3";
		table.cellspacing = "3";
		var tr;
		
		for (var i = 0; i < total; i++)
		{
			if(i%5 == 0)
			{
				tr=table.insertRow(-1);
			}
			if(tr != null)
			{
				var td = tr.insertCell(-1);
				var image = document.createElement("img");
				
				var myForm = document.createElement("form");
				myForm.id = "videoForm" + i;
				myForm.name = "videoForm" + i;
				myForm.action = "videolink.html";
				myForm.style.margin = "0px";
				td.appendChild(myForm);
				
				var item = param.value.items[i];
				
				var videoURLInput = document.createElement("input");
				
				videoURLInput.type = "hidden";
				videoURLInput.name = "url";
				videoURLInput.id   = "url";
				videoURLInput.value = encodeURIComponent(item.myurl);
				
				myForm.appendChild(videoURLInput);
				
				var videoTitleInput	= document.createElement("input");
				videoTitleInput.type = "hidden";
				videoTitleInput.name = "title";
				videoTitleInput.id   = "title";
				videoTitleInput.value = encodeURIComponent(item.title);
				
				myForm.appendChild(videoTitleInput);
				
				var videoInput	= document.createElement("input");
				videoInput.type = "hidden";
				videoInput.name = "desc";
				videoInput.id   = "desc";
				videoInput.value = encodeURIComponent(item.mydesc);
				
				myForm.appendChild(videoInput);
				
				image.border = "0";
				image.src = item.thumb;
				image.style.width = "145px";
				image.style.height = "80px";
				image.title = item.title;
				image.style.cursor = "pointer";
				
				if(item.myurl == "")
				{
					videoURLInput.value = encodeURIComponent(item.link);
					image.title = image.title + " [ ~ EXTERNAL SITE ~ ]";
					videoTitleInput.value = encodeURIComponent(image.title);
				}
				
				image.onclick = new Function( "setVideo(\"videoForm"+ i + "\");");
				td.appendChild(image);				
			}
			
		}
		oDiv.appendChild(table);
	}
	else
	{
		oDiv.innerHTML = "No Results Found. Please Try Again.";
	}
}
function continueOn(queryA)
{
	if(decodeURIComponent(queryA.title).indexOf("[ ~ EXTERNAL SITE ~ ]") == -1)
	{
		document.getElementById('videoForm').submit();
	}
	else
	{
		window.open(decodeURIComponent(queryA.url),'newWindow','width=600,height=400');
	}
	
}
function setVideo(formId)
{
	var theForm = document.getElementById(formId);
	theForm.submit();
}
function doCall(type,search)
{
	var search;
	if(search == 'search1')
	{
		search = document.getElementById(search).value;
	}
	else
	{
		search = document.getElementById("search").value;
	}
	
	//SEARCH BY KEYWORD
	var baseURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=2b5732c75d62768a80d9d058c85101f3&_render=json&_callback=displayHulu";	
	
	if(type == 1)
	{
	    baseURL += "&SearchString=" + search;
	}
	else if(type == 2)
	{
		//FAVORITES OF ALL TIME
		baseURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=673fa5e47ad06ef938cb70ad508fd88d&_render=json&_callback=displayHulu";
		//baseURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=358de09df572ef6f124a0ba334d3068b&_render=json&_callback=displayHulu";
	}
	else if (type == 3)
	{
		//TODAY's FAVORITES
		baseURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=jGfOif9X3RGjFRjgjUnRlg&_render=json&_callback=displayHulu";
	}
	else if (type == 4)
	{
		baseURL = "http://pipes.yahoo.com/pipes/pipe.run?_id=358de09df572ef6f124a0ba334d3068b&_render=json&_callback=displayHulu&url=" + decodeURIComponent("http://rss.hulu.com/HuluRecentlyAddedMovies");
	}
	
	var url = baseURL;

   var elem = document.getElementById('jsondiv');
   var script = document.createElement('script');
   script.type = 'text/javascript';
   script.src = url;
   elem.appendChild(script);
}