window.addEvent('domready', function(){
	//identify site prefix
		var site_prefix = '';
		
		switch(top.location.href.split("/")[2]){
			case "mburford:8080":
				site_prefix = 'http://mburford:8080/wwwAlbertSelezynovCom/www/';
				break;
			case 'www.martinburford.co.uk':
				site_prefix = 'http://www.martinburford.co.uk/came/';
				break;
			case 'www.cognitiveacceleration.co.uk':
				site_prefix = 'http://www.cognitiveacceleration.co.uk/';
				break;
		}
			
		var obj_h1 = document.getElementsByTagName("H1");
		obj_h1[0].onclick = function(){
			top.location.href = site_prefix + 'index.html';
		}
		
		//update targets for all links with attribute rel="external"
		var obj_links = document.getElementsByTagName("A");
		
		for(var i=0; i<=obj_links.length-1; i++){
			if(obj_links[i].rel == "external"){
				obj_links[i].target = "_blank";
			}
		}	
});

function video_player(mode,height,width,flash_path,video_title,video_description, windowHeight){	
	switch(mode){
		case "show":
			var obj_wrapper = $('wrapper');
			
			create_element("DIV","videoplayer_overlay","",obj_wrapper,"","","insert_before");
			create_element("DIV","video_player","",obj_wrapper,"","","insert_before");
			create_element("DIV","swf_player","",$('video_player'),"","","insert_after");
			create_element("IMG","video_close","",$('swf_player'),"",{src:"/images/video_player/close.gif",alt:"Close"},"insert_after");
			create_element("DIV","player","",$('swf_player'),"","","insert_after");
			
			$('video_close').onclick = function(){
				video_player('hide');
			}
			
			var window_height = window.getHeight();
			var window_width = window.getWidth();

			$('videoplayer_overlay').style.height = window.getScrollHeight() + "px";
			$('videoplayer_overlay').style.width = window_width + "px";

			window.scrollTo(0,0);

			if(windowHeight!=null){
				$('video_player').style.height = windowHeight+"px";
			}else{
				$('video_player').style.height = '360px';
				}
			$('video_player').style.width = '480px';

			$('video_player').style.left = ((window_width/2) - ($('video_player').getWidth()/2)) + "px";
			$('video_player').style.top = ((window_height/2) - ($('video_player').getHeight()/2)) + "px";
			
			//load the video into the player
			render_video(height,width,flash_path,video_title,video_description);
			
			break;
		case "hide":
			if($('videoplayer_overlay') != null){
				var obj_video_overlay = $('videoplayer_overlay');
				var obj_video_player = $('video_player');
				
				obj_video_overlay.parentNode.removeChild(obj_video_overlay);
				obj_video_player.parentNode.removeChild(obj_video_player);
			}
			break;
	}
}

function render_video(height,width,flash_path,video_title,video_description){
	var stage_height = height;
	var stage_width = width;
	
	var flashvars = {};
	//flashvars.imagePath	= "";
	flashvars.videoPath = flash_path;
	flashvars.title	= video_title;
	flashvars.description = video_description;
				
	//view information bar (title and description)
	flashvars.viewInfoButton = "true";

	//view scale buttons
	flashvars.viewScaleButton = "false";

	//view big middle button
	flashvars.viewBigPlayButton = "false";

	//double click for toggle size view
	flashvars.doubleClick = "false";
	
	//click the video for play/pause
	flashvars.oneClick = "true";
	
	//play/pause on SPACE key
	flashvars.spaceKey = "true";
	
	//timeline interval	
	flashvars.tlInterval = "100000";

	//sound volume at start (1=maximum, 0=minimum)
	flashvars.soundVolume = "0.8";
	
	//size the video starts at
	//1=normal
	//2=aspect
	//3=fullsize
	flashvars.fullSizeView = "3";
	
	flashvars.viewFullscreenButton = "true";
	flashvars.viewVolumeControls = "true";
	flashvars.viewTime = "true";
	flashvars.viewRightClickMenu = "false";
	flashvars.mouseHide = "true";
	flashvars.mouseHideTime	= "3";
	flashvars.videoLoop = "false";
	flashvars.videoAutoPlay = "true";
	flashvars.videoBufferTime =	"0.1";
	
	//spacing between the controls
	flashvars.spacing = "10";
	
	//control bar height
	flashvars.controlHeight = "25";
	
	//volume scrub length
	flashvars.volumeLengthW = "50";
	
	//controls background
	flashvars.color1 = "0x2e2e2e";
	flashvars.color2 = "0x000000";
	flashvars.alpha1 = "1";
	flashvars.alpha2 = "1";
	
	//controls border
	flashvars.borderColor = "0x555555";
	flashvars.borderAlpha = "1";
	
	//time view (backgrounds)
	flashvars.timeColor1 = "0x333333";
	flashvars.timeColor2 = "0x111111";
	flashvars.timeAlpha1 = "1";
	flashvars.timeAlpha2 = "1";

	//time view (text)
	flashvars.timeTextColor1 = "0xffffff";
	flashvars.timeTextColor2 = "0x888888";

	//scrubber
	flashvars.scrubberHeight = "3";

	//scrubber (background)
	flashvars.scrubberColor1 = "0x333333";
	flashvars.scrubberAlpha1 = "1";
	flashvars.scrubberColor2 = "0x47d2ff";
	flashvars.scrubberAlpha2 = "1";

	//scrubber glow filter
	flashvars.filterColor = "0x0066ff";
	flashvars.filterAlpha = "1";
	
	//control buttons
	//flashvars.buttonColor = "0x000000";
	
	//flashvars.titleColor = "0x47d2ff";
	//flashvars.descriptionColor = "0xD3D3D3";
	flashvars.titleColor = "0xffffff";
	flashvars.descriptionColor = "0xff0000";	
	flashvars.infoBackgroundColor = "0x000000";
	flashvars.infoBackgroundAlpha = "0.6";
	
	var params = {};
	params.scale = "noscale";
	params.allowfullscreen = "true";
	params.salign = "tl";
	params.bgcolor = "000000";
	
	var attributes = {};
	swfobject.embedSWF("/swf/video_player.swf", "player", stage_width, stage_height, "9.0.0", false, flashvars, params, attributes);	
}

function create_element(type,id,classname,append_to,inner_html,other,insert_mode){
	var obj;
	obj = document.createElement(type);
		
	if(id != ""){obj.id = id;}
	if(classname != ""){obj.className = classname;}
	if(inner_html != ""){obj.innerHTML = inner_html;}
	
	//loop through additional properties of object for dynamically adding via dot notation
	if(typeof(other) == "object"){
		for(property in other){
			obj[property] = other[property];
		}
	}
	
	switch(insert_mode){
		case "insert_after":
			append_to.appendChild(obj);
			break;
		case "insert_before":
			append_to.parentNode.insertBefore(obj,append_to);
			break;
	}	
}
