/* streamvideo.js - Functions used to control streaming video window
 *
 *
 * Copyright (c) 2003, 2004, 2005 ODS Technologies, L.P.  DBA TVG
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ODS Technologies, L.P. 
 * DBA TVG; the contents of this file may not be disclosed to third parties, 
 * copied or duplicated in any form, in whole or in part, without the prior 
 * written permission of ODS Technologies, L.P.  DBA TVG
 */

function popMediaPlayerWindow(replayParameters){
   
    var cookieValue=getSpeedCookie()
	var streamingVideoPath = BaseURL + 'livevideo/'
	var streamingVideoLink;
	var streamingVideoCheckLink;
	
	var replayvideo = false;
	try {
		var replayvideo = (replayParameters.indexOf("replay=1") >= 0);
	} 
	catch (ex) {}
	
	if (replayvideo) {
		streamingVideoLink = streamingVideoPath + 'replayvideo.asp?speed=' + cookieValue + "&" + replayParameters
		streamingVideoCheckLink = streamingVideoPath + 'checkPlugin.asp?' + replayParameters
	} else {
		streamingVideoLink = streamingVideoPath + 'livevideo.asp?speed=' + cookieValue
		streamingVideoCheckLink = streamingVideoPath + 'checkPlugin.asp'
	}
	
	if (cookieValue!=""){
		// pick a random location, otherwise they will be created exactly on top of each other 
		// making it appear that the other video window was removed.
		var randomTop = Math.floor(Math.random()*400)
		var randomLeft = Math.floor(Math.random()*400)
		var modelFeatures = 'dialogLeft:' + randomLeft + 'px;dialogTop:' + randomTop + 
			'px;help:no;resizable:yes;status:no;dialogWidth:365px;dialogHeight:400px;scroll:no;';
		if (replayvideo) {
			modelFeatures = 'dialogLeft:' + randomLeft + 'px;dialogTop:' + randomTop + 
				'px;help:no;resizable:yes;status:no;dialogWidth:365px;dialogHeight:400px;scroll:no;';
		}
		
		if (window.showModelessDialog != null) {
			window.showModelessDialog(streamingVideoLink, window.top, modelFeatures)
		} else {
		    streamingVideoLink = streamingVideoLink + "&dialogue=no"
			window.open(streamingVideoLink, "", "width=365,height=400,resizable=yes")
		}
			
			
	}else{
		//alert('streamingVideoCheckLink:' + streamingVideoCheckLink)
		window.open(streamingVideoCheckLink, "", "width=510,height=130");
	}
}

function changeBottomFrame(loc){
	top.bottomframe.location=loc;
}


	
var speedCookieName="connectionSpeed"
	
function getSpeedCookie(){
	var cookieLabelLen=speedCookieName.length +1
	var cookieLength=document.cookie.length
	var i=0
	var cEnd
	while(i<cookieLength){
		var j = i + cookieLabelLen
		if (document.cookie.substring(i,j)==speedCookieName + '='){
			cEnd=document.cookie.indexOf(";",j)
			if(cEnd==-1){
				cEnd=document.cookie.length
			}
			return unescape(document.cookie.substring(j,cEnd))
		}
		i++
	}
	return ""
}
	
function setSpeedCookie(speed){
	var cookieStr=speedCookieName + "=" + speed + "; expires="
	document.cookie=cookieStr
}