function channelTransform(dirtyChannel)
{
	// This function is just a placeholder. Use it if URLencoding becomes necessary
	cleanChannel = dirtyChannel;
	return cleanChannel;	
}

function changePlayerChannel(channel)
{	
	
	// Changes the channel, channel image, HTML and the page background.
	// the player is expected to play a default clip
	// disables the default onVideoClipBegin behavior once

	
	updateChannelGraphics(channel);
	return true;	
	changePageChannel(channel);



	onChannelPlayed = function(oEvent)
	{
		// A NOTE ABOUT THIS CODE:
		// Since we are only changing to a channel, we do not want the synopsis to appear 
		// when the video starts. So we override the onVideoClipBegin event with a function
		// that does nothing except restore it to it's previous state (Since we only want to 
		// supress it one time)
		
		// This might look a bit strange in terms of scope, but javascript assumes global
		// scope unless the 'var' keyword was used, in which case the scope becomes that 
		// in which the var declairation ocurred.

		onChannelPlayed = function(oEvent)
		{
			// Call to change page HTML:
			changePageChannel(oEvent.channelName);
		}
	}
	
	vxDispatch('eChangeChannel', {channelName: channelTransform(channel)});
	vxDispatch('ePlayChannel', {'channelName': channelTransform(channel)});
	
	// return false to stop the browser following the hyperlink href.
	// (This code is fired from an onClick in an <a> tag)
	return false;
}

function preVxDispatch(sEvent, oParams)
{
	vxDispatch(sEvent, oParams);
	setBackground(oParams.channelName);
}

function changePlayerChannelClip(channel, clip)
{
	updateChannelGraphics(channel);
	return true;
	// Changes the channel, channel image, the clip andthe page background.
	// Also assigns a function to the onVideoClipBegin event which changes the
	// page HTML once the clip starts.
	
	
	
	onChannelPlayed = function(oEvent)
	{
		// Call to change page HTML:
		changePageChannelClip(oEvent.channelName, oEvent.clipId);
		document.title = "men7 - " + channel;
	}
	
	vxDispatch('eChangeChannel', {channelName: channelTransform(channel), clipId: clip});
	vxDispatch('ePlayChannel', {channelName: channelTransform(channel), clipId: clip});
	
	// return false to stop the browser following the hyperlink href.
	// (This code is fired from an onClick in an <a> tag)
	return false;
}

function changePageChannel(channel)
{
	// Changes the HTML in the page to the appropriate Series View Content via AJAX
	// Set loading graphic:
	document.title = "men7 - " + channel;
	document.getElementById("htmlContent").innerHTML = "<img src='resources/img/loading.gif' class='ajaxLoader' width='50' height='50' alt='Content is loading'>";
	document.getElementById("homeHeader").innerHTML="";
	
	// Request content from PHP:
	AjaxRequest.get(
		{
		'url':'views/body_series.php' , 'parameters': {'vxChannel':channel}
		,'onSuccess':function(req)
			{ 
			document.getElementById("htmlContent").innerHTML=req.responseText; 
			}
		}
	);
}

function addHomeHeader()
{
	onChannelPlayed = function(oEvent)
	{
		// A NOTE ABOUT THIS CODE:
		// Since we are only changing to a channel, we do not want the synopsis to appear 
		// when the video starts. So we override the onVideoClipBegin event with a function
		// that does nothing except restore it to it's previous state (Since we only want to 
		// supress it one time)
		
		// This might look a bit strange in terms of scope, but javascript assumes global
		// scope unless the 'var' keyword was used, in which case the scope becomes that 
		// in which the var declairation ocurred.
		onChannelPlayed = function(oEvent)
		{
			// Call to change page HTML:
			changePageChannelClip(oEvent.channelName, oEvent.clipId);
		}
	}
	insertPromoBoard();
}

function insertPromoBoard()
{
		AjaxRequest.get(
		{
		'url':'views/head_home.php' , 'parameters': {}
		,'onSuccess':function(req)
			{ 
			document.getElementById("homeHeader").innerHTML=req.responseText; 
			}
		}
	);	
	
}

function addContent(page)
{
	// Changes the HTML in the page to the appropriate Series View Content via AJAX
	
	// Set loading graphic:
	document.getElementById("htmlContent").innerHTML = "<img src='resources/img/loading.gif' class='ajaxLoader' width='50' height='50' alt='Content is loading'>";
	document.getElementById("homeHeader").innerHTML="";
	
	// Request content from PHP:
	AjaxRequest.get(
		{
		'url':'views/'+page , 'parameters': {}
		,'onSuccess':function(req)
			{ 
			document.getElementById("htmlContent").innerHTML=req.responseText; 
			}
		}
	);
}

function changePageChannelClip(channel, clip)
{
	// Changes the HTML in the page to the appropriate Episode View Content via AJAX
	
	// Set loading graphic:

	document.title = channel;
	document.getElementById("htmlContent").innerHTML = "<img src='resources/img/loading.gif' class='ajaxLoader' width='50' height='50' alt='Content is loading'>";
	document.getElementById("homeHeader").innerHTML="";
	if(channel.toUpperCase() == 'TOP MEN7')
	{
		insertPromoBoard();
		document.getElementById('channelBannerDiv').innerHTML="";
	}
	// Request content from PHP:
	AjaxRequest.get(
		{
		'url':'views/body_episode.php', 'parameters': {'vxClipId':clip , 'vxChannel':channel}
		,'onSuccess':function(req)
			{ 
			document.getElementById("htmlContent").innerHTML=req.responseText; 
			document.getElementById("vxFlashPlayerTertiaryIMUDisplay").innerHTML = document.getElementById("vxFlashPlayerTertiaryIMU").innerHTML
			}
		}
	);
}

function updateChannelGraphics(channel)
{
	setChannelLink(channel.toUpperCase());
	setBackground((channel.toUpperCase()).replace(/\s+/g,''));
	document.getElementById('channelBannerDiv').innerHTML="";
	loadChannelImage(channel);	
}

function setBackground(channelName)
{
	
	// Set the correct page background for the supplied channel name.
	var dd = document.getElementById("bg_container");
	dd.style.backgroundImage = 'url(resources/img/' + ((channelName.toUpperCase()).replace(/\s+/g,'')).replace('+', '') +".jpg)";
	
	
}
function setChannelLink(channelName)
{
	//alert(channelName);
	var ln = document.getElementById("channel_link");
	ln.href="?vxChannel=" + channelName;
}

// The following sets the system up to handle fscommand calls from the flash navigation.
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

// Handle all the FSCommand messages in a Flash movie.
function channelMenu_DoFSCommand(command, args) {
	var channelMenuObj = isInternetExplorer ? document.all.channelMenu : document.channelMenu;
	if (command == "setChannel") 
	{
		setBackground((args.toUpperCase()).replace(/\s+/g,''));
		changePlayerChannel(args);
		
	}
	}
	
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub channelMenu_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call channelMenu_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}