var playlistVideoUrls = new Array();
var videoUrls = new Array();
var latestVideo;
var playlistVideoIds = new Array();
var theCounter = 0;
var currentUrl;
var isSwfPlayerLoaded = false;

FT_playListManager = new function(){

	
	//console.debug("FT_playListManager");
		
	this.flashIsConnected = function(){
		//console.debug("FT_playlistManager.flashIsConnected ");
		this.thisMovie("theFlashPlayer").activatePlaylist();
		//this.thisMovie("theFlashPlayer").loadAndPlayVideo(latestVideo);
	}
	
	this.onVideoComplete = function(){
		theCounter++;

		displayVideoData(playlistVideoData[videoIdArray[theCounter]])

		var isSameUrl = false;

		if(theCounter >= videoUrls.length){
			this.thisMovie("theFlashPlayer").exitFullscreen();
			theCounter = 0;
			return;
		}
		else{
			//console.debug(theCounter);
			if( currentUrl == videoUrls[theCounter] ){
				isSameURL = true;
			}
			currentUrl = videoUrls[theCounter];
		}
		
		//getVideoInfo(videoIdArray[theCounter]);

		//console.debug("FT_playlistManager.onVideoComplete - " + currentUrl + " - " + theCounter);
		//console.debug(this.thisMovie("theFlashPlayer"));
		
		//$.post("../getVideoInfo.php",{videoId : videoIdArray[theCounter]} ,getVideoInfoCallback, "json");
		
		//if(isSameURL){
			//this.thisMovie("theFlashPlayer").playVideo();
		//}
		//else{
			this.thisMovie("theFlashPlayer").setFlvPath(currentUrl);
			this.thisMovie("theFlashPlayer").startVideo();
		//}

	}
	
	this.onVideoInfoCallback = function(){
		
	}
	
	this.loadPlaylistPlayer = function(videoUrlList){
		//playlistVideoIds = videoIdArray;
		
		videoUrls = videoUrlList;

		if(isSwfPlayerLoaded === false){
			this.startFirstLoad();
		}
	}
	
	this.startFirstLoad = function(){
		currentUrl = videoUrls[theCounter];
		setSwfVideoPlayer();
	}
	
	function setSwfVideoPlayer(){
		if(isSwfPlayerLoaded===true){
			return;
		}
		
		isSwfPlayerLoaded = true;
		var theFlashVars = {	theSourcePath : currentUrl,
								autoPlay : true,
								connectJSPlaylist : true	};
		var theParameters = { 	allowfullscreen:"true",
								wmode : "opaque",
								allowscriptaccess : "allways" };

		//$.post("../getVideoInfo.php",{videoId : videoIdArray[theCounter]} ,getVideoInfoCallback, "json");
		
		displayVideoData(playlistVideoData[videoIdArray[theCounter]])
		
		swfobject.embedSWF("../flash/videoPlayerFT.swf", "theFlashPlayer", "677", "381", "9.0.0", "scr/expressInstall.swf", theFlashVars, theParameters);
	}
	
	this.thisMovie = function(movieName) {	
		if (navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	}
}
