// JavaScript Document

function openPlayerBox(title,product_id,user_id)
{
	document.getElementById('player_background').style.display = "block";
	
	var height_in = new Tween(document.getElementById('player_background').style,'height',Tween.strongEaseOut,0,700,1,'px');
	var top_in = new Tween(document.getElementById('player_background').style,'top',Tween.strongEaseOut,625,275,1,'px');
	
	top_in.start();
	height_in.start();
	

	
	height_in.onMotionFinished = function()
	{
		var http = createObject();
		
		
		var nocache = Math.random();
		http.open('get', 'ajax/get_video_file.php?user_id='+user_id+'&product_id='+product_id+'&nocache='+nocache);
		http.onreadystatechange = function()
		{
			if(http.readyState == 4)
			{	
			
			
				var videoFileName = http.responseText;
				
				document.getElementById('player_wrapper').style.height = '600px';
				document.getElementById('player_wrapper').style.display = "block";
				document.getElementById('player_wrapper').innerHTML = '<div class="player_top"><div class="player_top_left">'+title+'</div><div class="player_top_right" onclick="closePlayerBox();"><img src="./images/exit.jpg" border="0" alt="" /></div></div><div id="mediaspace" style="float:left;"></div>';
				
				//var so = new SWFObject('http://download.sii-stream.com/player/player.swf','ply','890','550','9','#ffffff');
				var so = new SWFObject('player/securePlayer.swf','ply','733','550','9','#ffffff');
				//var so = new SWFObject('player/player.swf','ply','733','550','9','#ffffff');
				//so.addVariable('streamer', 'lighttpd');
				so.addVariable('skin', 'player/skin.swf');
				so.addParam('allowfullscreen','true');
				so.addParam('allowscriptaccess','always');
				so.addParam('wmode','opaque');
				so.addVariable('playlistfile', 'ajax/playlist.php?product_id='+product_id );
				so.addVariable('autostart', 'true');
				so.addVariable('streamer', 'rtmp://flashcc-05.crossmediaventures.com/sibaeDocuLink');
				so.addVariable('type', 'rtmp');
				so.addVariable('stretching','fill');
				so.addVariable('duration','30');
				so.addVariable('repeat','list');
				so.addVariable('bufferlength','0.01');
				so.addVariable ("displayheight", "600") ;
				so.addVariable ("displaywidth", "800") ;
				so.addVariable ("height", "550") ;
				so.addVariable ("width", "733") ;

				so.addVariable ("overstretch", "true") ;//fit, true, false
				so.write('mediaspace');
			}
		}
		http.send(null);
		

	}
	
	ajaxcurl("ajax/update_watched.php?product_id="+product_id+"&user_id="+user_id);
}
function closePlayerBox()
{
	document.getElementById('player_wrapper').style.height = '0px';
	document.getElementById('player_wrapper').innerHTML = '';
	
	var height_out = new Tween(document.getElementById('player_background').style,'height',Tween.strongEaseOut,700,0,1,'px');
	var top_out = new Tween(document.getElementById('player_background').style,'top',Tween.strongEaseOut,275,625,1,'px');
	height_out.onMotionFinished = function()
	{
		document.getElementById('player_background').style.display = 'none';
	}
	
	top_out.start();
	height_out.start();
}
