var AKAMAI_RTMP_URI = "rtmp://cp45142.edgefcs.net/ondemand/45142/";
var LIVE_STREAM_URI = "rtmp://cp15458.live.edgefcs.net/live";

var HTML_STREAM_URI = "http://cdn-kwconnect.kw.com/";

var PLAYER = '/connect/static/swfs/player.swf';
//var PLAYER = 'http://developer.longtailvideo.com/player/trunk/fl5/player.swf';


function createPlayer(thePlaceholder, thePlayerId, theFile, theType, theImage, home){
	var myStream = null;
	var myPlugins = null;
	var flashvars = {};
		
	var myObj = {};
	myObj.autostart= true;
        if (home){
            myObj.height= 240;
            myObj.width= 320;
        }
        else {
            myObj.height= 360;
            myObj.width= 480;	
        }
	myObj.controlbar = 'bottom';
//	myObj.plugins = 'qualitymonitor-2';
		
	switch(theType){
		case 'vid':	
			myObj.streamer= AKAMAI_RTMP_URI;
			myObj.modes = [
				{type: 'flash', src: PLAYER,
					config: {file: theFile+'_155.flv', provider: 'rtmp'}
				}
//				,
//				{type:'html5',
//					config: {file: HTML_STREAM_URI+theFile, provider: 'video'}
//				}			
			]
//			player 5.5 does not support akamai bitrate switching yet	
//			myObj.playlist = [
//				{
//				streamer: AKAMAI_RTMP_URI,
//				levels:[
//					{bitrate:'70', width: '480', file: theFile+'_79.flv'},
//					{bitrate:'30', width: '280', file: theFile+'_79.flv'}
//				
//				]}
//			]
			break;
		
		case 'yt':
			myObj.modes = [
				//player does not support html5 audio tag as of v5.5
				//{type:'html5',
				//	config: {file: 'http://cdn-kwconnect.kw.com/'+theFile, provider: 'video'}
				//},
				{type: 'flash', src: PLAYER,
					config: {file: theFile}
				}
							
			]
			break;
			
		case 'mp3':
			myObj.streamer= AKAMAI_RTMP_URI;
			myObj.image = theImage;
			myObj.modes = [
				//player does not support html5 audio tag as of v5.5
				//{type:'html5',
				//	config: {file: 'http://cdn-kwconnect.kw.com/'+theFile, provider: 'video'}
				//},
				{type: 'flash', src: PLAYER,
					config: {file: theFile, provider: 'rtmp'}
				}
							
			]	
			break;
			
		case 'h264':
			myObj.streamer= AKAMAI_RTMP_URI;
			myObj.modes = [
				{type:'html5',
					config: {file: HTML_STREAM_URI+theFile, provider: 'video'}
				},
				{type: 'flash', src: PLAYER,
					config: {file: theFile, provider: 'rtmp'}
				}
					
			]	
			break;
			
		case 'live':
			myObj.streamer = LIVE_STREAM_URI;
			myObj.controlbar = 'bottom';		
			myObj.modes = [
				{type: 'flash', src: PLAYER,
					config: {file: theFile, provider: 'rtmp', 'rtmp.subscribe':'true'}
				}					
			]	

			break;
                        
                case 'initial':                    
                    myObj.controlbar = 'none';
                    document.getElementById("player").innerHTML = "<img border='0' alt='invalid security' src='"+theFile+"'/>";
                    return;
                    
                case 'popup':                    
                    myObj.controlbar = 'none';
                    document.getElementById("player").innerHTML = "<img border='0' alt='invalid security' src='"+theFile+"'/>";
                    return;
                    
                case 'skip':
			myObj.streamer= AKAMAI_RTMP_URI;
			myObj.modes = [
				{type: 'flash', src: PLAYER,
					config: {file: theFile, provider: 'rtmp'}
				}
							
			]	
			break;

		default:
			myObj.controlbar = 'none';
		
	}
	

		
   jwplayer(thePlaceholder).setup(myObj);
}

function deletePlayer(theWrapper, thePlaceholder, thePlayerId) { 
        //swfobject.removeSWF(thePlayerId);
        var tmp=document.getElementById(theWrapper);
        if (tmp) { tmp.innerHTML = "<div id=" + thePlaceholder + "></div>"; }
}

function initHomePlayer(id, theFile, theType, sessionTxt, partTxt, theImage){
    initPlayer(id, theFile, theType, sessionTxt, partTxt, theImage, true);
}

function initPlayer(id, theFile, theType, sessionTxt, partTxt, theImage, home) { 
        if (home == undefined || home == null){
            home = false;
        }
        deletePlayer('player', 'mediaplayer', 'player1'); 
        createPlayer('mediaplayer', 'player1', theFile, theType, theImage,home);
		if (!home){
			hideArrow();
		}
        if (!home && id != 'skip')
        {
            showPart(id);
        }
        if (sessionTxt == undefined)
        {
            sessionTxt = "";
        }
		if (!home){
			getItemData(sessionTxt, partTxt);
		}
        
}

function hideArrow(){
		var liTags = document.getElementById("project-sessions").getElementsByTagName("li");
		for (var i = 0; i < liTags.length ; i++){
			liTags[i].className= "inactive";				
        }
}


function showPart(id){
		document.getElementById(id).className= "active"; 
}

function getItemData(sessionTxt, partTxt) {
        var obj = sessionTxt
        
        if (partTxt == undefined || partTxt == null || partTxt == "")
        {
            ;//nothing
        }
        else
        {
            obj = sessionTxt +" - "+partTxt;
        }
        
		document.getElementById("now-playing").innerHTML = obj;
	};


	

