	function getVideoPage(_cat, _min, _max, action)
	{
			//assignError("", errorContainer);
			document.body.style.cursor = 'wait';

			new Ajax.Request("" + "/consumer/videos/videosAJAX.do", {
				asynchronous: true,
				method: "get",
				parameters: "cat=" + _cat + "&min=" + _min + "&max=" + _max,
				onSuccess: function(request) {
					//alert("success");
					crawlXMLVideo(request.responseXML.documentElement,action);
					//alert(request.responseText);
					//alert(request.responseXML.documentElement);
				},
				onFailure: function(request) {
					//alert(request.statusText);
					alert("We're currently experiencing technical problems on this website; please try again later. We apologize for any inconvenience.");
				},
				onComplete: function(request) {
						document.body.style.cursor = 'default'
				}
			});
	}
	
	
	
	
	function crawlXMLVideo(doc,action)
	{
		//Check if we got any products back from AJAX call
		
		if(doc.hasChildNodes())
		{
			//Get all video elements
			var videos = doc.getElementsByTagName("video");
			var productCount = 0;
			var productTitle = "";
			var _id = "";
			
			//hide all tables that would display a video
			//this way, if there are not enough vidoeos returned, the unchanged tables will be hidden
			var _max = document.getElementById("max").innerHTML;
			if(_max != null)
			{
				for (j=0; j<parseInt(_max); j++)
				{
					document.getElementById("table-"  + (j+1)).style.display="none";
				}
			}
			//Loop through each product
			for (i=0; i<videos.length; i++)
			{
				var video = videos[i];

				//Loop through each element in the product
				for (j=0; j<video.childNodes.length; j++)
				{
					//Set the product row back to block style in the event that the previous link was clicked and the row was
					//hidden from a next link.
					//document.getElementById("row-"  + (i+1)).style.display = 'block';

					var videoElement = video.childNodes[j];
					
					
					if (videoElement.nodeName == "id")
					{
						_id = videoElement.childNodes[0].nodeValue
						//alert(document.getElementById("id-"  + (i+1)).innerHTML);
						//document.getElementById("id-"  + (i+1)).innerHTML = "<a href='/consumer/adspromotions/tvspotsvideo.do?videoID=" + videoElement.childNodes[0].nodeValue + "'>";
					}

					//Reset the appropriate span to the product value.
					if (videoElement.nodeName == "title")
					{
						var _cat = getQueryVariable("cat");
						
						if(_cat == "RECIPES" || _cat == "COOKING BASICS")
						{
							document.getElementById("title-"  + (i+1)).innerHTML = "<a href='/consumer/recipes/recipetvvideo.do?id=" + _id + "' style='text-decoration:none;'><strong style='color:#666666;'><img src='/images/universal_arrw.gif' width='9' height='7' alt='' border='0'>" + videoElement.childNodes[0].nodeValue + "</strong></a>";
							document.getElementById("img-url-"  + (i+1)).href = "/consumer/recipes/recipetvvideo.do?id=" + _id ;
						}
						else
						{
							document.getElementById("title-"  + (i+1)).innerHTML = "<a href='/consumer/adspromotions/tvspotsvideo.do?id=" + _id + "' style='text-decoration:none;'><strong style='color:#666666;'><img src='/images/universal_arrw.gif' width='9' height='7' alt='' border='0'>" + videoElement.childNodes[0].nodeValue + "</strong></a>";
							document.getElementById("img-url-"  + (i+1)).href = "/consumer/adspromotions/tvspotsvideo.do?id=" + _id ;
						}
						
						
						//document.getElementById("title-"  + (i+1) + "hidden").value = videoElement.childNodes[0].nodeValue;

						//Save off video title so we can use it in an alt tag.
						videoTitle = videoElement.childNodes[0].nodeValue;
						
						//alert(document.getElementById("title-"  + (i+1)).innerHTML);
						//change the url text
						//document.getElementById("id-"  + (i+1)).text="test";
						
						//display the hidden table
						document.getElementById("table-"  + (i+1)).style.display="";
					}
					
					else if(videoElement.nodeName == "thumb_url")
					{
						document.getElementById("image-"  + (i+1)).src=videoElement.childNodes[0].nodeValue;
					}
					

					else if (videoElement.nodeName == "description")
					{
						//document.getElementById("description-" + productContext + (i+1)).innerHTML = productElement.childNodes[0].nodeValue;
					}
				}
				productCount++;
			}

			//update the count at the top of the display
			var currentCat = document.getElementById("cat").innerHTML;
			var currentStartIndex = parseInt(document.getElementById("startIndex").innerHTML) - 1;
			var currentEndIndex = document.getElementById("endIndex").innerHTML;
			var totalCount = document.getElementById("totalCount").innerHTML;
			var nextStartIndex = 0;
			var nextEndIndex = 0;
			var nextStartIndexCommand = 0;
			var previousStartIndexCommand = 0;
			
			if(action == "inc")
			{
				document.getElementById("startIndex").innerHTML = parseInt(currentEndIndex) + 1;
					document.getElementById("endIndex").innerHTML = parseInt(currentEndIndex) + videos.length;
					nextStartIndexCommand = parseInt(currentStartIndex) + videos.length + videos.length;
					previousStartIndexCommand = parseInt(currentStartIndex);
				
			}
			else{
				
				document.getElementById("startIndex").innerHTML = parseInt(currentStartIndex) - videos.length + 1;
				document.getElementById("endIndex").innerHTML = parseInt(currentStartIndex) ;
				nextStartIndexCommand = parseInt(currentStartIndex);
				previousStartIndexCommand = parseInt(currentStartIndex) - videos.length - videos.length;

			}
			
			
			document.getElementById("nextCommand").innerHTML = " | <a href=\"javascript:getVideoPage('" + currentCat + "','"+ nextStartIndexCommand +"','"+ eval(nextStartIndexCommand + videos.length) +"','inc')\">Next</a>";
			
			if(parseInt(document.getElementById("endIndex").innerHTML) >= totalCount)
			{
				document.getElementById("nextCommand").style.display="none";
			}
			else
			{
				document.getElementById("nextCommand").style.display=""
			}
			
			if(document.getElementById("startIndex").innerHTML != "1")
			{
				var _max = getQueryVariable("max");
				document.getElementById("previousCommand").innerHTML = " | <a href=\"javascript:getVideoPage('" + currentCat + "','"+ previousStartIndexCommand +"','"+ eval(previousStartIndexCommand + parseInt(_max)) +"','dec')\">Previous</a>";
				document.getElementById("previousCommand").style.display="";
			}
			else
			{
				document.getElementById("previousCommand").style.display="none";
			}
				
					
	  }
}


function videoGo(loc)
{
	loc = loc.replace("'","''");
	loc = loc.replace(" & "," %26 ");
	document.location=loc;
}


function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}

} 


	function rollOver(obj)
	{
		var _src = obj.src.toString();
		var newSrc = _src.replace(/.jpg/i,"_roll.jpg");
		obj.src=newSrc;

	}

	function rollOut(obj)
	{
		var _src = obj.src.toString();
		var newSrc = _src.replace(/_roll.jpg/i,".jpg");
		obj.src=newSrc;
	}
	
