/**
*------------------------------------------------------------------------------------
* Video utils
*/

/**
* Trace into a debug window
* @param string String to be traced
*/
function trace(string){
	if(document.getElementById('debug')!=undefined){
		document.getElementById('debug').innerHTML+=string+"<br/>"
	}
}

/**
* Open a vid that has been clicked
* @param id The id of the vid in the videos array (not the key)
*/
function open_video(id, debug){

	var vid_key=get_video_by_id(id)
	var video=videos[vid_key]
	var url=video.url
	var width=parseInt(video.width)
	var height=parseInt(video.height)
	var title=video.title
	var description=video.description
	var image=video.image;
	var controlpanelHeight=32;
	var player_id="video_player"
	var express_install_url=base_url+"flash/expressInstall.swf"
	var player_url=base_url+"flash/player4.3.132.swf" // This player works from 9.0.28 onwards and skins well
	//player_url=base_url+"flash/player4.0.46.swf" // This player works with flash 9.0.16, but doesn't skin well
	var skin_url=base_url+"flash/stylish.swf"

	//var flash_version="9.0."
	//var flash_version="9.0.124"
	var flash_version="9.0.28"

	
	// Remove the previous video
	/*
	var container=document.getElementById("video_player_container")
	removeChildNodes(container)
	var new_div = document.createElement("div");
	new_div.id="video_player";
	container.appendChild(new_div);
	*/
	
	/*
	* Load in the flash player
	*/
	//trace("version2")
	var flashvars = {
		file:url,
		autostart:true,
		skin:skin_url,
		quality:true
	}
	var params = {
		allowfullscreen:true,
		allowscriptaccess:"always",
		wmode:"transparent"
	}
	var attributes = {
		id:player_id,
		name:player_id
	}
	swfobject.embedSWF(player_url, player_id, width,height+controlpanelHeight, flash_version, express_install_url, flashvars, params, attributes)

	
}

function get_video_by_id(id){
	for(var i=0;i<videos.length;i++){
		if(videos[i].id==id){
			return i
		}
	}
	return -1;
}

