//Google Analytics flag; True=Tracking data sent.
var gaSent=false;

//The currently playing item (filename)
var currentItem='';

//Id of the player object
var playerID='playerFLV';

//Location of the swf of the player
var swf_url='http://dbms.telecomtv.com/js/flvplayer.swf';
//var swf_url='http://itu.telecomtv.com/js/eventplayer.swf';

//Create the video player

function createPlayer(container, w, h, url, stream, auto, live, controlbar, volume) {

	//Clear the container that the player will be written to
	if (document.getElementById(container)) { document.getElementById(container).innerHTML=''; }

	//Set the current item to url
	setCurrentItem(url);

	//Set the player's characteristics
	window[playerID] = new Object();
	var so = new SWFObject(swf_url,playerID,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);
  	so.addVariable('backcolor','000000');	
  	so.addVariable('frontcolor','FFFFFF');
	so.addVariable('usefullscreen','true');
	so.addVariable('autostart', auto);
	so.addVariable('volume', volume);
	so.addVariable('type', 'video');
	
	if (!controlbar) { so.addVariable('controlbar', 'none'); }

	//If the file is a live stream, from a streaming server or a progressive download
	if (live) {
		so.addVariable('streamer','rtmpt://telecomtv.fc.llnwd.net/telecomtv/');	
		so.addVariable('file', url);
		so.addVariable('subscribe', 'true');
	}
	else if (stream != "false") {
		so.addVariable('streamer','rtmpt://telecomtv.fcod.llnwd.net/a1411/o16/');	
		so.addVariable('file', url);
	}
	else {
		so.addVariable('file','http://video.telecomtv.com/web2/ugc/flv/'+ url +'.flv');	
	}		

	//Write the object to the container
	so.write(container);
	
	//Apply IE patch to the player
	SWFFormFix(playerID);
};

//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;      
			
			//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; }  

};

function thisMovie(swf) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[swf];
  } else {
    return document[swf];
  }
};

