/* Function to check if an element/object exists */
function testForObject(Id, Tag) {
	var o = document.getElementById(Id);
	if (o) {
		if (Tag) {
			if (o.tagName.toLowerCase() == Tag.toLowerCase()) {
				return o;
			}
		}
		else {
			return o;
		}
	}
	return null;
}

function positionIt() {
	thiswidth = document.body.scrollWidth;
	thisheight = document.body.scrollHeight;
	innerwidth = document.documentElement.clientWidth;
	innerheight = document.documentElement.clientHeight;
	
	if (navigator.appName == "Microsoft Internet Explorer") {
		scrollPosition = document.documentElement.scrollTop;
	}
	else {
		scrollPosition = window.pageYOffset;
	}
	//Resize opacity layer
	/*document.getElementById('opacityContainer').style.width = thiswidth + 'px';
	if (thisheight < innerheight) {
		document.getElementById('opacityContainer').style.height = innerheight + 'px';
	}
	else {
		document.getElementById('opacityContainer').style.height = thisheight + 'px';
	}*/
	
	//Position the order layer
	//This next following row (style.left) is changed because of flash banners on the right of the page that hiercic put them selfes above tv-tv
	//This row is replaced by the row below that with the static position of style.left
	//document.getElementById('tvtvLayer').style.left = innerwidth/2-651/2 + 'px';
	document.getElementById('tvtvLayer').style.left = '131px';
	document.getElementById('tvtvLayer').style.top = scrollPosition+innerheight/2-442/2 + 'px';
	
	//Set opacity and order layer to visible
	//document.getElementById('opacityContainer').style.visibility = 'visible';
	document.getElementById('tvtvLayer').style.visibility = 'visible';
	//Following row is to prevent Lightbox Image Viewer making the flash player hidden
	document.getElementById('jwplayer').style.visibility = 'visible';
	
	/*if (navigator.appName == "Microsoft Internet Explorer") {
		window.scrollTo(0, scrollPosition);
	}
	else {
		window.scrollTo(0, scrollPosition);
	}*/
}

function positionItOrNot() {
	var o = testForObject('tvtvLayer');
	if (o) {
		if (document.getElementById('tvtvLayer').style.visibility == 'visible') {
			positionIt();
		}
	}
}

//window.onload = positionIt;
window.onresize = positionItOrNot();

function hideTvtv() {
	//document.getElementById('opacityContainer').style.visibility = 'hidden';
	document.getElementById('tvtvLayer').style.visibility = 'hidden';
	//Following row is to prevent Lightbox Image Viewer making the flash player hidden
	document.getElementById('jwplayer').style.visibility = 'hidden';
}

/* THIS NEXT PART IS FOR CONTROLLING FLASH MOVIE (THE FLV PLAYER) VIA JAVASCRIPT  */
// Use a variable to reference the embedded SWF file.
var flashVideoPlayer;

/* When the HTML page loads (through the onLoad event of the <body> tag), it calls the initialize() function. */
function initialize() {
	/* Check whether the browser is IE. If so, flashVideoPlayer is
window.videoPlayer. Otherwise, it's document.videoPlayer. The
videoPlayer is the ID assigned to the <object> and <embed> tags. */
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	flashVideoPlayer = (isIE) ? window['tvtv02'] : document['tvtv02'];
}

/* When the user clicks the play button in the form, update the videoStatus text area, and call the playVideo() function within the SWF file, passing it the URL of the FLV file. */
function callFlashPlayVideo() {
	var comboBox = document.forms['videoForm'].videos;
	var video = comboBox.options[comboBox.selectedIndex].value;
	updateStatus("____" + video + "____");
	flashVideoPlayer.playVideo("http://www.helpexamples.com/flash/video/" + video);
}

// Call the pauseResume() function within the SWF file.
function callFlashPlayPauseVideo() {
	flashVideoPlayer.pauseResume();
}

/* The updateStatus() function is called from the SWF file from the onStatus() method of the NetStream object. */
function updateStatus(message) {
	document.forms['videoForm'].videoStatus.value += message + "\n";
}