// OPEN UP A CONSOLE AND PASS IN THE VIDEO PATH VARIABLE TO ENABLE AUTOSTART
function watchInConsole(page,video,console,name) {
	// stop any streaming video before launching console
	//stop();
	//document.getElementById('mediaPlayer').controls.stop();
	sweetChildOfMine = eval("window.open('" + console + "?thePage=" + page + "&videoPath=" + video + "','SportalCentre','width=660,height=540,toolbars=no,scrolling=auto,left=80,top=80')");
}

// AUTOSTART - IF THERE IS A VIDEO PASSED IN THE URL
function autoStarty() {
	
	//alert("starting autostarty");
	
	// lets see if there the a video to play in the url...look for the ?
	var areThereVars = document.URL.indexOf('?');
	
	if (areThereVars != -1)	{ 		
		// Grab everything after the ?
		theVars = document.URL.substring(areThereVars+1, document.URL.length);
		var posOfPage = theVars.indexOf('thePage=');
		var posOfVideoPath = theVars.indexOf('videoPath=');
		
		// first lets see what page we are meant to be on...if no page then stay where we are.
		if (posOfPage != -1) {
			//	go from the page= to the first videoPath or end (if there is no videoPath)
			if (posOfVideoPath != -1) {
				var endOfPage = posOfVideoPath-9;
			} else {
				var endOfPage = theVars.length;
			}
			var thePage = theVars.substr(posOfPage+8,endOfPage);
			if (thePage != "null" && thePage != "") {
				loadContent(thePage);
			}
		}
		
		// now lets see if there is a video to play
		// go from the videoPath= to the first end
		if (posOfVideoPath != -1) {
			var endOfVideo = theVars.length;
			var theVideoPath = theVars.substr(posOfVideoPath+10,endOfVideo);
			if (theVideoPath != "null" && theVideoPath != "") {
				changeParentMediaFile(theVideoPath);
			}
		}
	}
	
	//alert("ending autostarty");
	
}

// PRELOAD THE ROLLOVERS
var playerStatus = "";
if (document.images) {
	play_img = new Image();
	play_img.src = "/Images/Video_Centre/play_off.gif"
	stop_img = new Image();
	stop_img.src = "/Images/Video_Centre/stop_off.gif"
	big_screen_img = new Image();
	big_screen_img.src = "/Images/Video_Centre/big_screen_off.gif"
}

// START THE MEDIA FILE...CHANGE THE BUTTONS
function start(console) {

	//alert("you called - start function");
	
	var player = document.getElementById('mediaPlayer');
	if (player)  {	
		if (player.filename != "") {	 
			player.stop();
			player.play();
			playerStatus = "";
			if (console=="LIVE") {
				playerStatus = "sportal_live_play";
				window.parent.ItemRollover('sportal_live_play');
				window.parent.ItemRollout('sportal_live_stop');				
			} else {
				playerStatus = "play";
				window.parent.ItemRollover('play');
				window.parent.ItemRollout('stop');				
			}			
		} else {
			alert("Please select a clip to play");
		}
	}
}

// STOP THE MEDIA FILE THAT IS PLAYING...CHANGE BUTTONS
function stop(console) {

	//alert("you called - stop function");

	var player = document.getElementById('mediaPlayer');
	if (player) {
		player.stop();
		playerStatus = "stop";
		if (console=="LIVE") {
			window.parent.ItemRollout('sportal_live_play');
			window.parent.ItemRollover('sportal_live_stop')
			playerStatus = "sportal_live_stop";
		} else {
			window.parent.ItemRollout('play');
			window.parent.ItemRollover('stop');
			playerStatus = "stop";
		}		
		
	}
}

// BIG SCREEN
function fullscreen() {
	var player = document.getElementById('mediaPlayer');
	if (playerStatus == "play") {
		player.DisplaySize=3; 
		player.play();
	}	
}

// CHANGE VIDEO FILE - WITHIN SAME WINDOW - don't have the play buttons etc to change
function changeMediaFile(source) {	
	
	//alert("you called - chaneMedia function");
	
	var player = document.getElementById('mediaPlayer');
	player.stop();	
	player.filename = source;	
}

// CHANGE VIDEO FILE - FOR USE WITH IFRAMES
function changeParentMediaFile(source) {	
	
	//alert("you called - changeParentMediaFile function");
	
	var player = document.getElementById('mediaPlayer');
	stop();	
	player.filename = source;	
	start();
}

// CHANGE AUDIO FILE - WITHIN SAME WINDOW - don't have the play buttons etc to change
function changeAudio(source) {
	var player = document.getElementById('mediaPlayer');
	if (source.substr(0,5) == "http:") {
		mfn = source;
	} else {
		mfn = "http://audio.teamtalk.com/" + source;	
	}	
	player.stop();				
	player.filename = mfn;
}

// CHANGE AUDIO FILE - FOR USE WITH IFRAMES
function changeParentAudio(source) {
	var player = document.getElementById('mediaPlayer');
	if (source.substr(0,5) == "http:") {
		mfn = source;
	} else {
		mfn = "http://audio.teamtalk.com/" + source;	
	}	
	stop();				
	player.filename = mfn;
	start();	
}


// PLAYER BUTTON ROLLOVER
function ItemRollover(item) {	
	// don't rollover if it is the selected menu item
	if (playerStatus == item) return;
	
	var image = document.getElementById(item + '_img');
	if (image) {
		image.src = "/Images/Video_Centre/" + item + "_on.gif"
	}
}

// PLAYER BUTTON ROLLOUT
function ItemRollout(item) {	
	// don't rollout if it is the selected menu item
	if (playerStatus == item) return;

	var image = document.getElementById(item + '_img');
	if (image) {
		image.src = "/Images/Video_Centre/" + item + "_off.gif"
	}	
}

// LOAD THE CONTENT INTO THE FRAME 
function loadContent(theURL) {
	ItemRollout('stop');
	theFrame.location=theURL;
	if (playerStatus == 'play') {
		start();
	}
}

// WRITE TO A SPAN TAG - prev/next buttons 
function writeContent(id, content) {
	var myContent = document.getElementById(id);
	myContent.innerHTML = content;
}

function maus (mrItem) {
	if (mrItem.className == 'cell_out') {
		mrItem.className='cell_over';
	} else {
		mrItem.className='cell_out';
	}
}