// -------------------- functions used to enable the left side navigation control -----------------------
var g_leftNavSelected = null;

function iTalkiesMoviesLeftNavSelect (srcElement)
{
	// First unselect all but the current element
	var collAnchors = window.document.getElementById ("LeftNavTable").getElementsByTagName("span")
	
	if (collAnchors != null)
	{
		if (collAnchors.length != null)
		{
			for (var i=0; i < collAnchors.length; i++)
			{
				collAnchors[i].style.color = "#ffcc66";
			}
		}
		else
		{
			collAnchors.style.color = "#ffcc66";
		}
	}

	// Now select the correct element
	g_leftNavSelected = srcElement;
	if (srcElement != null)
		srcElement.style.color = "#ffffff";
}

function iTalkiesLeftNavOnMouseOver (srcSpanElement)
{
	if (srcSpanElement.style.color != "#ffffff")
		srcSpanElement.style.color = "#fffffe";
}

function iTalkiesLeftNavOnMouseOut (srcSpanElement)
{
	if (srcSpanElement.style.color != "#ffffff")
		srcSpanElement.style.color = "#ffcc66";
}

var g_leftNavFlyOut = null;

function iTalkiesLeftNavFlyOutHide ()
{
	if (g_leftNavFlyOut != null)
	{
		g_leftNavFlyOut.style.zIndex = -100;
		g_leftNavFlyOut.style.left = -200;
		g_leftNavFlyOut.style.top = -100;
		g_leftNavFlyOut = null;
	}
}

function iTalkiesLeftNavFlyOutShow (e)
{
	iTalkiesLeftNavFlyOutHide ();

	var srcElement;
	var normalizedEvent;
	if (ie)
	{
		srcElement = event.srcElement;
		normalizedEvent = event;
	}
	if (moz) 
	{
		srcElement = e.target;
		normalizedEvent = e;
	}
	
	// If the user clicked on the arrow image translate it as a click
	// on the span that encapsulates the arrow
	if ((srcElement.tagName == null) || (srcElement.tagName.toLowerCase() == "img"))
	{
		srcElement = srcElement.parentNode;
	}
	
	g_leftNavFlyOut = document.getElementById (srcElement.getAttribute ("flyoutsource"));
	
	iTalkiesOffsetElement (g_leftNavFlyOut, document.getElementById (srcElement.getAttribute ("flyoutimage")), 10, -5);
	g_leftNavFlyOut.style.zIndex = 100;
	g_leftNavFlyOut.style.height = g_leftNavFlyOut.getElementsByTagName("TABLE")[0].rows.length * 18;
	g_leftNavFlyOut.style.width = srcElement.getAttribute ("cols") * 100;
	
	iTalkiesCancelBubble (e);
	normalizedEvent.returnValue = false;
	return false;
}

function iTalkiesLeftNavFlyOutElementOnMouseOver (e)
{
	var srcElement;
	if (ie)
	{
		srcElement = e;
		if (srcElement == null)
			srcElement = event.srcElement;
	}
	if (moz) 
	{
		srcElement = e.target;
		if (srcElement == null) srcElement = e;
	}

	srcElement.style.backgroundColor = "#999900";
	srcElement.style.color = "#ffffff";
}


function iTalkiesLeftNavFlyOutElementOnMouseOut (e)
{
	var srcElement;
	if (ie)
	{
		srcElement = e;
		if (srcElement == null)
			srcElement = event.srcElement;
	}
	if (moz) 
	{
		srcElement = e.target;
		if (srcElement == null) srcElement = e;
	}

	srcElement.style.backgroundColor = "#cccc66";
	srcElement.style.color = "#666600";
}


function iTalkiesLeftNavFlyOutElementOnClick (e)
{
	var srcElement;
	if (ie)
	{
		srcElement = e;
		if (srcElement == null)
			srcElement = event.srcElement;
	}
	if (moz) 
	{
		srcElement = e.target;
		if (srcElement == null) srcElement = e;
	}

	window.location = redirector + "Movies.aspx?Show=ByReleaseYear&ShowParam=" + srcElement.id + "&Name=" + srcElement.id;
}


function iTalkiesLeftNavItemOnClick(srcElement, pathPrefix, page, showParam, showType, showAlpha, alternateSelect)
{
	if (showType != null)
	{
		showType = "&ShowType=" + showType;
	}
	else
	{
		showType = "";
	}
	
	if (showAlpha != null)
	{
		showAlpha = "&Alpha=" + showAlpha;
	}
	else
	{
		showAlpha = "";
	}
	
	if (showParam != null)
	{
		showParam = "?Show=" + showParam;
	}
	else
	{
		if ((showAlpha == "") && (showType == ""))
		{
			showParam = "";
		}
		else
		{
			showParam = "?a=a";
		}
	}

	if (pathPrefix == null)
	{
		pathPrefix = "";
	}
	
	window.document.getElementById ("ContentFrame").src = pathPrefix + page + ".aspx" + showParam + showType + showAlpha;
	// Select the nav item
	if (alternateSelect != null)
	{
		iTalkiesMoviesLeftNavSelect (window.document.getElementById (alternateSelect));
	}
	else
	{
		iTalkiesMoviesLeftNavSelect (srcElement);
	}
	
	if (g_leftNavFlyOut != null)
	{
		iTalkiesLeftNavFlyOutElementOnMouseOut (srcElement);
	}
	iTalkiesLeftNavFlyOutHide ();
}


function iTalkiesLeftNavByMoviePropertyOnClick (showType, showParam, name)
{
	var frameElement;
	
	frameElement = window.document.getElementById ("ContentFrame");
	
	frameElement.src = "Movies.aspx?Show=" + showType + "&ShowParam=" + showParam + "&Name=" + encodeURIComponent (name);

	iTalkiesMoviesLeftNavSelect (window.document.getElementById (showType));
	iTalkiesLeftNavFlyOutHide ();
}


function iTalkiesLeftNavByReleaseYearPropertyOnClick (e)
{
	var srcElement;
	if (ie) srcElement = event.srcElement;
	if (moz) srcElement = e.target;

	iTalkiesLeftNavByMoviePropertyOnClick ('ByReleaseYear', srcElement.id, srcElement.innerHTML);
}


function iTalkiesLeftNavFlyOutSubYearShow (e)
{
	iTalkiesLeftNavFlyOutHide ()

	var srcElement;
	if (ie) srcElement = event.srcElement;
	if (moz) 
	{
		srcElement = e.target;
		if (srcElement.id == null)
			srcElement = srcElement.parentNode;
	}

	var year;
	year = parseInt (srcElement.id);
	
	var date = new Date();
	
	var maxYear = date.getFullYear();
	if (maxYear > year + 9)
	{
		maxYear = year + 9;
	}
	delete date;
	
	var subYearTable = document.getElementById ("ByReleaseSubYearPopupTable");
	
	for (;subYearTable.rows.length != 0;)
	{
		subYearTable.deleteRow(-1);
	}
	
	var newRow = null;
	var newCell = null;
	
	newRow = subYearTable.insertRow(-1);
	newCell = newRow.insertCell(-1);
	newCell.className = "ITalkiesLeftNavFlyoutAnchor";
	newCell.height = "15";
	newCell.onclick = iTalkiesLeftNavFlyOutShow;
	if (ie)
	{
		newCell.onmouseover = iTalkiesLeftNavFlyOutElementOnMouseOver;
		newCell.onmouseout = iTalkiesLeftNavFlyOutElementOnMouseOut;
	}
	else
	{
		newCell.setAttribute ("onmouseover", "this.className = 'ITalkiesLeftNavFlyoutAnchorHover';");
		newCell.setAttribute ("onmouseout", "this.className = 'ITalkiesLeftNavFlyoutAnchor';");
	}
	newCell.setAttribute ("flyoutsource", "MovieLeftNav_ByReleaseYearPopupSource");
	newCell.setAttribute ("flyoutimage", "ByReleaseYearFlyoutImage");
	newCell.setAttribute ("rows", 1);
	newCell.setAttribute ("cols", 1);
	newCell.appendChild(document.createTextNode ("<<"));
	for (var i = maxYear; i >= year; i--)
	{
		newRow = subYearTable.insertRow(-1);
		newCell = newRow.insertCell(-1);
		newCell.id = i;
		newCell.height = "15";
		newCell.className = "ITalkiesLeftNavFlyoutAnchor";
		if (ie)
		{
			newCell.onmouseover = iTalkiesLeftNavFlyOutElementOnMouseOver;
			newCell.onmouseout = iTalkiesLeftNavFlyOutElementOnMouseOut;
			newCell.onclick = iTalkiesLeftNavFlyOutElementOnClick;
		}
		else
		{
			newCell.setAttribute ("onmouseover", "this.className = 'ITalkiesLeftNavFlyoutAnchorHover';");
			newCell.setAttribute ("onmouseout", "this.className = 'ITalkiesLeftNavFlyoutAnchor';");
			newCell.setAttribute ("onclick", "window.location = '" + redirector + "Movies.aspx?Show=ByReleaseYear&ShowParam=" + i + "&Name=" + i + "';");
		}
		newCell.appendChild(document.createTextNode (i));
	}
	
	iTalkiesLeftNavFlyOutShow (e);
	return false;
}

function iTalkiesGotoPrevReleaseYearPopup()
{
	window.document.getElementById ("ByReleaseYear").click();
}