var totalTime			= 0;		//total time of the current clip playing
var initNextTime		= 0;		//time when the next clip in json string will be initiated, and buffered
var videoTime 			= 0;		//current playback time (constantly updated)

var syncVideoInterval 	= 0;		//start interval for video synchronization

var billboardType		= "";		//type of billboard, either 'img' or an 'swf'
var timeBillboard		= 0;		//timer for billboard
var durationBillboard	= 0;		//minimum duration, the billboard is displayed (set in json string)

var prevMediaType 		= '';		//type of medium previous to current clip
var mediaType 			= 'WMV';		//type of medium of current clip
var nextMediaType 		= '';		//type of medium of upcoming clip

var preBufferTime 		= 20;		//duration taken from the total time of clip to establish 'initNextTime"
var firstStart 			= true;		//set to true whenever a new clip is chosen from mainnav
var killAdOverlayTime	= 0;		//of duration for an overlay has been defined in json string this time will be set upon starting the overlay

var swfCheckDone		= false;	//set to true once json string has been searched for AdOverlays which get stored in array
var swfAdArray			= new Array();// array which stores all AdOverlays for the currently playing medium
var curSwfAd			= "";		//variable that holds next AdOverlay, which is being preloaded in flash layer

var waitForNext			= false;	//set to true if ASX is in use and the next medium has been initiated
var wmvItemDone			= false;	//set to true once a WMV item has finished playing, necessary for transition of subsequent WMV
var playStatus			= 'stopped' //status of wmb playback
var resetPlayer			= false;
var nextMediaInit		= false;


//Jochens
var curVideo 			= "";		//variable that holds current video information , taken from json string
var curAd 				= "";		//variable that holds information for ad assigned to the currently playing medium
var flagLoadNewVideo 	= true;		//set to true once upcoming video has been initiated
var doAutoPlay			= false;	//set to true if medium should start playing upon buffer finished (ie clip with no billboard)
var	videoAdSchedule 	= "";		//json string

var	trackingStr 		= "";		//string that contains the tracking code
var bufferValue			= 0;
var buffering			= 3;

//set visibility of various divs (mainly flashOver)
function setVisibility(div, status){
	debugThis('setVisibility --- div ' + div + " "+status);
	
	if(!document.getElementById(div)){
		//escape if div doesnt exist
		debugThis('escape this '+div+' '+document.getElementById(div));
		return;	
	}

	if(div == 'flashOverlay'){
		if(!silverlight){
			setVisibilityVideo(status, div);
			var objFlash = getObject("objFlashPlayer");
			if(objFlash)
				objFlash.setVisibilityVideo(status);
			
			return;
		}
	}
	
	if(status){
		setCssStyle(document.getElementById(div), 'marginLeft', '0');
	}else{
		setCssStyle(document.getElementById(div), 'marginLeft', '-2000');
		if(doDebug){
			setCssStyle(document.getElementById(div), 'marginLeft', String(videoWidth));
			if(div == 'allOverlay')
				setCssStyle(document.getElementById('allOverlay'), 'marginLeft', '1500');
		}
	}

	debugThis('setVisibility done ' + div);
}


function setVisibilityVideo(status, div){
	debugThis('setVisibilityVideo ' + status);
	
	if(status){
		setCssStyle(document.getElementById(div), 'marginTop', '0');
		setCssStyle(document.getElementById(div), 'height', '297');
	}else{
		setCssStyle(document.getElementById(div), 'marginTop', String(videoHeight));
		setCssStyle(document.getElementById(div), 'height', '25');
	}
	
	debugThis('setVisibilityVideo done');
}



function clickThrough(url, target, depth, width, height, acl){
	var newWindow = false;
	if(url == 'null' || url == null	){
		return newWindow;
	}
	
	leftVal = (screen.width - width) / 2;
	topVal = (screen.height - height) / 2;
	if(acl == '1'){
		tools = "location=yes,scrollbars=yes,resizable=yes,width="+width+",height="+height+",left="+leftVal+",top="+topVal;
	}else{
		tools = "location=no,scrollbars=yes,resizable=yes,width="+width+",height="+height+",left="+leftVal+",top="+topVal;
	}
	
	debugThis('url  '+url);
	debugThis('target  '+target);
	debugThis('depth  '+depth);
	debugThis('width  '+width);
	debugThis('height  '+height);
	debugThis('acl  '+acl);
	debugThis('tools  '+tools);
	
	if(target == "Same"){
		//open location in same window
		location.href=url;
		return true;
	}else{
		if(window.open(url, 'newWin', tools)){
			debugThis('newWindow  true');
			return true;
		}else{
			debugThis('newWindow  false');
			return false;
		}
		
		//define the focus
		/*if(depth == 'Front'){
			newWindow.focus();
		}else{
			//alert('self focus');
			self.focus();
		}*/
	}
	debugThis('end click thru  ');
}




//set css style for divs
function setCssStyle(target, property, value){
	switch(property){
		case 'width':
		case 'height':
		case 'left':
		case 'top':
		case 'marginLeft':
		case 'marginTop':
			if(navigator.appName.indexOf("Microsoft") != -1)
				target.style[property] = value;
			else
				target.style[property] = value+"px";
			break;
			
		case 'backgroundImage':
			target.style.backgroundImage = "url("+value+")";
			break;
		
		default:
			target.style[property] = value;
	}
}
