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);
				}
				
				
				var awrap = document.createElement("a");
				awrap.href = "javascript:setVideo(\"videoForm" + i + "\");";
				awrap.appendChild(image);
				//image.onclick = new Function( "setVideo(\"videoForm"+ i + "\");");
				
				if(item.title)
				{
					awrap.appendChild(document.createElement("br"));
					var tSpan = document.createElement("div");
					tSpan.innerHTML = item.title.length > 75 ? item.title.substring(0,72) + "..." : item.title;
					tSpan.style.width = "145px";
					tSpan.style.fontSize = "9px";
					tSpan.style.overflow = "hidden";
					tSpan.style.marginTop = "2px";
					awrap.appendChild(tSpan);
				}
				
				td.vAlign = "top";
				
				
				td.appendChild(awrap);				
			}
			
		}
		oDiv.appendChild(table);
	}
	else
	{
		oDiv.innerHTML = "No Results Found. Please Try Again.";
	}
}



var titleType = 0;
function doTitle(type)
{
    titleType = type;
    var elem = document.getElementById('jsondiv');
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = "http://pipes.yahoo.com/pipes/pipe.run?_id=7hXfR4ah3RGv4ntMBRNMsA&_render=json&_callback=displayTitles";
    elem.appendChild(script);
}

function displayTitles(param)
{
	var oDiv = document.getElementById("titlesresult");
	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 = "5";
		table.cellspacing = "5";
		var tr;
		
		tr=table.insertRow(-1);
		var td = tr.insertCell(-1);
		td.colSpan = "5";
		td.align = "center";
		td.innerHTML = "Available Titles" + (titleType == 1 ? " - TV Shows" : titleType == 2 ? " - Movies" : "");
		td.style.fontSize = "17px";

		tr=table.insertRow(-1);
		var td = tr.insertCell(-1);
		td.colSpan = "5";
		td.align = "center";
		var anchors = document.createElement('div');
		anchors.id = 'anchors';
		td.appendChild(anchors);
		td.style.fontSize = "11px";
		
		
		tr=table.insertRow(-1);
		td = tr.insertCell(-1);
		td.align = "center";
		td.colSpan = "5";
		td.style.fontSize = "12px";
		td.innerHTML = "<div class='bar' style='color:black'>Filters:&nbsp;&nbsp;<a href=\"javascript:doTitle('0')\">ALL</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"javascript:doTitle('1')\">TV SHOWS ONLY</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"javascript:doTitle('2')\">MOVIES ONLY</a></div>";
		
		var count = 0;
		var firstLetter = null;
		for (var i = 0; i < total; i++)
		{
			var item = param.value.items[i];
			if(count%5 == 0)
			{
				tr=table.insertRow(-1);
			}
			
			count++;
			if (titleType == 1 && item.type == 'MOVIE')
			{
				count--;
				continue;
			}
			else if (titleType == 2 && item.type == 'TV')
			{
				count--;
				continue;
			}
			
			if(firstLetter == null || firstLetter != item.title.substring(0,1))
			{
				var doFirst = firstLetter;
				if((count-1)%5 != 0)
				{
					tr = table.insertRow(-1);
					count = 1;
				}
				td = tr.insertCell(-1);
				td.colSpan = "5";
				td.align = "center";
				td.style.fontSize = "12px";
				td.style.fontWeight = "bold";
				td.style.marginTop = "10px";
				firstLetter = item.title.substring(0,1);
				td.innerHTML = "<a name='" + firstLetter + "' id='" + firstLetter + "'></a>" + item.title.substring(0,1) + "&nbsp;&nbsp;<a href='#top'>(top)</a>";
				td.style.borderBottom = "1px solid #000000";
				anchors.innerHTML = anchors.innerHTML + (doFirst == null ? "" : " | ") + "<a href='#" + firstLetter + "'>" + firstLetter + "</a>"
				
				tr = table.insertRow(-1);
			}

			if(tr != null)
			{
				var td = tr.insertCell(-1);
				var awrap = document.createElement("a");
				var div = document.createElement("div");
				var item = param.value.items[i];
				/*
				var myForm = document.createElement("form");
				myForm.id = "videoForm" + i;
				myForm.name = "videoForm" + i;
				myForm.action = "http://www.tvharddrive.com/videolink.html";
				myForm.style.margin = "0px";
				td.appendChild(myForm);
					
				
				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);
				*/
				var isFull = false;
				if(item.type == 'MOVIE')
				{
					isFull = item.full.indexOf('full-movie-icon') != -1;
				}
				else if (item.type == 'TV')
				{
					isFull = item.full.indexOf('full-episode-icon') != -1;
				}
				awrap.innerHTML = item.title + " <span style='font-size:9px'>(" + (isFull ? "<span style='color:red'>FULL</span> " : "") +  item.type + ")</span>";
				awrap.style.width = "155px";
				awrap.style.fontSize = "11px";
				awrap.style.color = "#000000";
				div.style.width = "156px";
				div.style.marginTop = "3px";
				awrap.href = "http://seesimpsons.com/?search=" + encodeURIComponent(item.title);
				//awrap.appendChild(div);
				
				td.vAlign = "top";
				div.appendChild(awrap);
				td.appendChild(div);				
			}
			
		}
		oDiv.appendChild(table);
	}
	else
	{
		oDiv.innerHTML = "Titles are not currently available to view at this time.";
	}
}




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,searchI)
{
	var search;
	if(searchI == 'search1')
	{
		search = document.getElementById(searchI).value;
	}
	else
	{
		var sElem = document.getElementById("search");
		if(sElem)
		{
			search = sElem.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);
}