//Google Analytics flag; True=Tracking data sent.
var gaSent=false;

//The currently playing item (filename)
var currentItem='';

//Create the video player

function createPlayer(container, w, h, url, rand, stream, auto, image) {

	setCurrentItem(url);	

	window["playerFLV"] = new Object();
	
	var so = new SWFObject('/includes/player/flvplayer.swf','playerFLV',w,h,'8');
	so.addParam('wmode','transparent');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','true');	
	so.addVariable("javascriptid","playerFLV");
	so.addVariable('enablejs','true');
	so.addVariable('width',w);
	so.addVariable('height',h);
	if (image) {
		so.addVariable('image','/videos/bt/large_'+url+'.jpg?'+rand);
	}
	
	so.addVariable('usefullscreen','true');
	so.addVariable('autostart',auto);
	
	//if (stream) {
	//	so.addVariable('file','rtmpt://telecomtv.fcod.llnwd.net/a1411/o16/andhp');	
	//	so.addVariable('id', url);
	//}
	//else {
		so.addVariable('file','http://video.telecomtv.com/web2/ugc/flv/'+url+'.flv');	
	//}		

	so.write(container);
	
	SWFFormFix("playerFLV");

   
};

//Set the current playing item (filename)
function setCurrentItem(str) {
	currentItem=str;
}


//Video player Javascript update functions

function sendEvent(swf,typ,prm) { 
  thisMovie(swf).sendEvent(typ,prm); 
};

function getUpdate(typ,pr1,pr2,swf) {

		if(typ == "time") {
			currentPosition = pr1;
			duration = parseInt(pr1) + parseInt(pr2); 
			//&& document.forms[0].inTOout.checked
			
			var pl=getLength('playerFLV')
			pl--;			
			
			if (currentPosition == end && parseInt(currentItem) != parseInt(pl)) {
				sendEvent('next'); 
			}
		}
		else if(typ == "item") { 
			//currentItem = pr1;  
			
  		}		
		else if(typ == "state") { 
			state = pr1;      
			
			//alert(state +' Sent?:'+ gaSent);
			
			//If the video is playing send data to Google Analytics
			if (state == "2" && gaSent==false) { 
				//alert(state +'Calling Google: pageTracker._trackPageview("/videos/'+ currentItem +'.flv);"');
				pageTracker._trackPageview('/videos/'+ currentItem +'.flv');
				
				//Set the flag to tell the page that tracking has been done
				gaSent=true;
			}
		}
		else if(typ == "load") { 
			buffer = pr1;      
		}    
		else if(typ == "volume") { currentVolume = pr1; }  
		
	//	var id = document.getElementById(typ);
	//	id.innerHTML = typ+ ": "+Math.round(pr1);
	
	//	pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
	//	if(pid != "null") {
	//		document.getElementById("pid").innerHTML = "(received from the player with id <i>"+pid+"</i>)";
	//	}

};


function thisMovie(swf) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[swf];
  } else {
    return document[swf];
  }
};

