// JavaScript Document
var currentTitle;
var currentTime=0;
var currentRate='1mbps';
var currentVolume='0.8';

//the available formats/sizes
var vidFormats= new Array();
vidFormats["2mbps"]=new Array(1280,720);
vidFormats["1mbps"]=new Array(640,360);
vidFormats["700kbps"]=new Array(480,270);
vidFormats["300kbps"]=new Array(320,180);

//setup listeners
jQuery(document).ready(function($){
	//close btn
	$("#closeBtn img").click(function(){$("#vidPlayerWrap").html('').hide();$("#popWrap").hide();});
	
	//format nav
	$(".formatNav li").each(function(){$(this).click(function(){
		$("#vidPlayerWrap").html('').hide();
		var sel=$(this).attr('id').substr(1);
		//video  
		$('#vidPlayerStage').animate({width:vidFormats[sel][0],height:(vidFormats[sel][1]+30)},800);  
		$('#vidWrap').animate({width:vidFormats[sel][0],height:(vidFormats[sel][1]+90)},800,function(){updateVid();});
		
		currentRate=sel;  
		//nav
		$(".formatNav li").each(function(){$(this).removeClass('selected');});
		$(this).addClass('selected'); 		
	});});
	
	
	//clip nav
	$('#clipNav').hover(function(){$('ul',this).addClass('open');},function(){$('ul', this).removeClass('open');});
	$("#clipNav li").each(function(){$(this).click(function(){
		$("#vidPlayerWrap").html('').hide();
		currentTitle=$(this).attr('id').substr(1);
		currentTime=0;
		updateVid();
		$("#selectedClip").html($(this).html());
	});});
});
function launchDemos(){
	//set first clip
	currentTitle=jQuery("#clipNav ul li:first-child").attr('id').substr(1);
	jQuery("#selectedClip").html(jQuery("#clipNav ul li:first-child").html());
	//clear previous bitrate
	jQuery(".formatNav li").each(function(){jQuery(this).removeClass("selected");});
	jQuery("#b1mbps").addClass("selected");
	currentRate='1mbps';
	//set stage size
	jQuery('#vidPlayerStage').css({width:vidFormats['1mbps'][0],height:(vidFormats['1mbps'][1]+30)});  
	jQuery('#vidWrap').css({width:vidFormats['1mbps'][0],height:(vidFormats['1mbps'][1]+90)});
	currentTime=0;
	//do it
	jQuery("#popWrap").show();
	updateVid();
}
function updateVid(){
	var vidFile='/videos/'+currentTitle+'__'+currentRate;
	var flashQ=startTime='autoStart=1&video='+vidFile+'&startTime='+currentTime+'&width='+vidFormats[currentRate][0]+'&height='+vidFormats[currentRate][1]+'&volume='+currentVolume;
//	var flashContent='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="100%" height="100%">'
//					+'<param name="movie" value="/inc/video.swf?'+flashQ+'"><param name="quality" value="high"><param name="wmode" value="transparent">'
//					+'<embed src="/inc/video.swf?'+flashQ+'" quality="high" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" width="100%" height="100%"></embed></object>';
	
	
	//IE doesn't like classid and codebase on dynamic loads--which is dumb since IE is why there is codebase and classid in the first place
	flashContent='<object width="100%" height="100%">'
					+'<param name="movie" value="/inc/video.swf?'+flashQ+'"><param name="quality" value="high"><param name="wmode" value="transparent">'
					+'<embed src="/inc/video.swf?'+flashQ+'" quality="high" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" width="100%" height="100%"></embed></object>';
	

	//flashContent='not flash';
	//flashContent='<object data="/inc/video.swf?'+flashQ+'" type="application/x-shockwave-flash" width="100%" height="100%"><param name="movie" value="/inc/video.swf?'+flashQ+'"><param name="quality" value="high"><param name="wmode" value="transparent"></object>';
	jQuery("#vidPlayerWrap").html(flashContent).show();
	//document.getElementById("vidPlayerWrap").innerHTML=flashContent;
}
function updateCurrentTime(t,vol){
	currentTime=t;
	currentVolume=vol;
}
