<!--
function MM_preloadImages() {
	var d=document;
	if(d.images) {
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){
			d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
		}
	}
}

function P7_JumpMenu(selObj,restore){
	var theFullString = selObj.options[selObj.selectedIndex].value;
	if (restore) selObj.selectedIndex=0;
	var theLength = theFullString.length;
	var endPos = theFullString.lastIndexOf("~");
	var theUrl, theTarget, theParent;
	if (endPos > 0) {
		theUrl = theFullString.substring(0,endPos);
	}
	else {theUrl = theFullString;}
	endPos++
	if (endPos < theLength) {
		theTarget = theFullString.substring(endPos,theLength)
	}
	else {theTarget = "window:Main";}
	if (theTarget == "window:New") {
		window.open(theUrl);
	}
	else if (theTarget == "window:Main") {
		eval("parent.location='"+theUrl+"'");
	}
	else {
		eval("parent.frames[\'"+theTarget+"\'].location='"+theUrl+"'");
	}
}

var javascript_version = 1.0;
var newwin;
function launchwin(winurl,winname,winfeatures) {
	newwin = window.open(winurl,winname,winfeatures);
	if(javascript_version > 1.0) {
 		setTimeout('newwin.focus();',250);
	}
}

function MM_swapImgRestore() {
	var i,x,a=document.MM_sr;
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) {
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n);
	return x;
}

function MM_swapImage() {
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){
		document.MM_sr[j++]=x;
		if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
	}
}

function popup(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function leapto(form) {
	var index=form.dest.selectedIndex
	window.location=(form.dest.options[index].value);
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function delete_query() {
	if (confirm('Are you sure you want to delete?')){
		document.forms['edit_form'].action.value='delete';
		document.forms['edit_form'].submit();
	}
}

function popopen(thePage,wt,ht){
	leftPos= (screen.width-wt)/2
	topPos = (screen.height-ht)/2
	newWin1 = window.open(thePage,'thirty','toolbars=no,resizeable=no,scrollbars=no,left='+leftPos+',top='+topPos+',width='+wt+',height='+ht)
}
/*
Example:
	var myTargetNameValue = 'login';
	var myTargetNameValueResult = getQueryStringValue(myTargetNameValue);
	if(myTargetNameValueResult == 'T') { 
		// Insert code here
	}
*/
function getQueryStringValue(targetNV) {
	var data = window.location.search.substring(1); // trims "?" from beginning:
	var items;
	var targetNvResult = '';
	
	if (data.length > 0) {
		allNVs = data.split("&") // Split the querystring into name/value pairs
		
		for (var nextNV = 0; nextNV < allNVs.length; nextNV++) {
			data = allNVs[nextNV].split("=");
			
			if (data[0].toLowerCase() == targetNV.toLowerCase() || data[0].toLowerCase() == targetNV.toUpperCase()) { 
				// Target name was found
				//targetNvResult = targetNV + '=' + data[1];
				targetNvResult = data[1];
				break;
			}
		}
	}
	
	return targetNvResult;
}




$(function(){
	// Preload close tab images.
	$("body").append('<img src="/watch/images/lightbox_close2_over.gif" style="display:none;" /> <img src="/watch/images/lightbox_close2.gif" style="display:none;" />');
	
	$("#hd_lightbox").click(function(e) {
		// create lightbox with flash at bottom of page
		
		$("body").append("<div id='lightbox'></div>");
		$("#lightbox").append("<div id='lightbox_bg'></div>");
		$("#lightbox").append("<div id='lightbox_container'></div>");
		$("#lightbox_container").append('<div id="lightbox_close" class="lightbox_close_up" onmouseover="this.className=\'lightbox_close_over\'" onmouseout="this.className=\'lightbox_close_up\'"></div>');
		
		$("#lightbox_close").click(function(e) {
				$("#lightbox").remove();
			});
		
		$("#lightbox_container").append("<div id='lightbox_contents'></div>");
		
		
		var movie_ratio = 16 / 9;
		var lightbox_ratio = 1.45; //1.34; //4 / 3; //79 / 50; //16 / 9; //31 / 20;
		var control_bar = 54; // 54px
		//var bottom_margin = 50;
		var bottom_margin = 80; // 100;
		var side_margin = 40; //100; //200;
		
		var mySwfContainerPadding = 10; 
		
		//var maxLightboxWidth = 896 + (mySwfContainerPadding * 2) + side_margin;
		//var maxLightboxHeight = 504 + (mySwfContainerPadding * 2) + bottom_margin + control_bar;
		
		var maxWidthMismatchAdj = -18;
		var maxHeightMismatchAdj = -10;
		var maxLightboxWidth = (896 + maxWidthMismatchAdj) + (mySwfContainerPadding * 2) + side_margin;
		var maxLightboxHeight = (504 + maxHeightMismatchAdj) + (mySwfContainerPadding * 2) + bottom_margin + control_bar;

		
		var minLightboxWidth = 570 + (mySwfContainerPadding * 2) + side_margin; // 590
		var minLightboxHeight = 310 + (mySwfContainerPadding * 2) + bottom_margin + control_bar; // 400
		
		var docWidth = $(window).width();
		var docHeight = $(window).height();
		
		/*
		if (window.console) {
			console.info("$('#hd_lightbox').click:");
			console.log("document.documentElement.clientWidth = " + document.documentElement.clientWidth);
			console.log("document.documentElement.offsetHeight = " + document.documentElement.offsetHeight);
			console.log("window.innerWidth= " + window.innerWidth);
			console.log("window.innerHeight = " + window.innerHeight);
		}
		*/
		
		if (document.documentElement.clientWidth && window.innerHeight) {
			//docWidth = window.innerWidth;
			docWidth = document.documentElement.clientWidth;
			docHeight = window.innerHeight;
		}
		else if (document.documentElement.clientWidth && document.documentElement.offsetHeight) {
			//docWidth = document.documentElement.offsetWidth;
			//for width in IE
			docWidth = document.documentElement.clientWidth;
			//for height in IE
			docHeight = document.documentElement.offsetHeight;
		}
		
		if (docWidth > maxLightboxWidth) {
			docWidth = maxLightboxWidth;
		}
		else if (docWidth < minLightboxWidth) {
			docWidth = minLightboxWidth;
		}
		
		if (docHeight > maxLightboxHeight) {
			docHeight = maxLightboxHeight;
		}
		else if (docHeight < minLightboxHeight) {
			docHeight = minLightboxHeight;
		}
		
		docHeight -= control_bar;
		
		var swfContainerHeight, swfContainerWidth;
		
		
		swfContainerHeight = docHeight;
		swfContainerWidth = docWidth;
		
		
		var myAdjustedSwfWidth = 0;
		var myAdjustedSwfHeight = 0;
		
		/*
		if (window.console) {
			console.info("$('#hd_lightbox').click:");
			console.log("movie_ratio = " + movie_ratio + ", docHeight = " + docHeight + ", docHeight * movie_ratio = " + (docHeight * movie_ratio) + ", docWidth = " + docWidth);
		}
		*/
		
		//if (docHeight * movie_ratio > docWidth) { // window is tall
		if (docHeight * lightbox_ratio > docWidth) { // window is tall
			/*
			if (window.console) {
				//console.info("$('#hd_lightbox').click:");
				console.info("window is tall");
			}
			*/
			var newDocWidth = docWidth - side_margin;
			swfContainerWidth = newDocWidth;
			swfContainerHeight = newDocWidth / movie_ratio;
			
			myAdjustedSwfWidth = newDocWidth - (mySwfContainerPadding * 2);
			myAdjustedSwfHeight = (newDocWidth / movie_ratio);
		} 
		else { // window is wide
			/*
			if (window.console) {
				//console.info("$('#hd_lightbox').click:");
				console.info("window is wide");
			}
			*/
			docHeight -= bottom_margin;
			swfContainerHeight = docHeight;
			swfContainerWidth = docHeight * movie_ratio;
			
			myAdjustedSwfHeight = docHeight - mySwfContainerPadding;
			myAdjustedSwfWidth = myAdjustedSwfHeight * movie_ratio;
		}
		
		swfContainerHeight += control_bar + mySwfContainerPadding;
		myAdjustedSwfHeight += control_bar;
		
		
		swfContainerHeight = parseInt(swfContainerHeight);
		swfContainerWidth = parseInt(swfContainerWidth);
		
		$("#lightbox_container").width(swfContainerWidth);
		
		$("#lightbox_contents").width(swfContainerWidth);
		$("#lightbox_contents").height(swfContainerHeight);
		
		var showDebug = '';
		
		var myTargetNameValue = 'debug';
		var myTargetNameValueResult = getQueryStringValue(myTargetNameValue);
		if(myTargetNameValueResult == '1') { 
			showDebug += '&showdebug=1';
		}
		
		var myTargetNameValue = 'streamcontrols';
		var myTargetNameValueResult = getQueryStringValue(myTargetNameValue);
		if(myTargetNameValueResult == '1') { 
			showDebug += '&showstreamcontroltools=1';
		}
		
		//http://dev.tbn.org/index.php/2.html?smilbaseurl=rtmp://cp114430.live.edgefcs.net/live&smilstreamname=test_reconnect@46220&smilbitrate=1104000
		
		var smilbaseurl = '';
		var myTargetNameValue = 'smilbaseurl';
		var myTargetNameValueResult = getQueryStringValue(myTargetNameValue);
		if(myTargetNameValueResult != '') { 
			smilbaseurl = '&smilbaseurl=' + myTargetNameValueResult;
		}
		
		var smilstreamname = '';
		var myTargetNameValue = 'smilstreamname';
		var myTargetNameValueResult = getQueryStringValue(myTargetNameValue);
		if(myTargetNameValueResult != '') { 
			smilstreamname = '&smilstreamname=' + myTargetNameValueResult;
		}
		
		var smilbitrate = '';
		var myTargetNameValue = 'smilbitrate';
		var myTargetNameValueResult = getQueryStringValue(myTargetNameValue);
		if(myTargetNameValueResult != '') { 
			smilbitrate = '&smilbitrate=' + myTargetNameValueResult;
		}
		
		/*
		// Start original embed method.
		var so = new SWFObject("/flash/hd_player.swf?allowFullScreen=true&scale=noscale&align=left&width="+swfContainerWidth+"&height="+swfContainerHeight+"&salign=tl"+showDebug,
							   "hd_stream",
							   swfContainerWidth,
							   swfContainerHeight,
							   "10",
							   "#000000");
		so.addParam("allowFullScreen", "true");
		so.addParam("scale", "noscale");
		so.addParam("salign", "tl");
		so.write("lightbox_contents");
		*/
		
		
		// Start alternate embed method
		$("#lightbox_contents").append('<div id="hd_stream" style="width:'+myAdjustedSwfWidth+'px; height:'+myAdjustedSwfHeight+'px"><br /><br /><h3 style="color:#FFF">Please install the latest flash player to view this site properly.</h3><p><a href="http://www.adobe.com/go/getflashplayer" target="_blank"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" border="0" /></a></p></div>');
		var flashvars = {
		};
		var params = {
		  name: "hd_stream",
		  bgcolor: "#000",
		  menu: "false",
		  wmode: "window",
		  allowscriptaccess: "always",
		  allowfullscreen: "true",
		  scale: "noscale",
		  salign: "tl"
		};
		var attributes = {};

		swfobject.embedSWF("/flash/hd_player.swf?v=7&allowFullScreen=true&scale=noscale&align=left&width="+myAdjustedSwfWidth+"&height="+myAdjustedSwfHeight+"&salign=tl"+showDebug+"&page_url="+window.location+"&betamode=1"+smilbaseurl+smilstreamname+smilbitrate, 
						   "hd_stream", 
						   myAdjustedSwfWidth, 
						   myAdjustedSwfHeight, 
						   "10", 
						   "/flash/expressInstall.swf", 
						   flashvars, 
						   params, 
						   attributes);
		
		
		// IE6 doesn't recognize "position:fixed", so emulate it
		
		/*
		$(window).scroll(function() {
			$('#lightbox').css('top', $(this).scrollTop() + "px");
		});
		*/
		$('#lightbox').css('top', $(window).scrollTop() + "px");
		
		
	});
});

//-->

