//onload_register('set_up_video()');
var takeOver = false;
var videoActive = false;
var videoType;
var div;
var vidBoxID;
var vidPlayerID = 'off';
var closeDivID;
var player;
var pID;
var n_height;
var n_width;
cookieUserData = Cookie.get('userdata');

if(cookieUserData) {
	//Decompress JSON values of userData
	userData = eval('(' + cookieUserData + ')');
}
function showVideoOverlay(iVal) {
	pID = iVal;
		videoType = "";
		vidBoxID = 'video_box';
		vidPlayerID = 'video_player';
		//linkTrack("video", "play_overview_video");
    	player = "/flash/content/stand_alone_player.swf";
		closeDivID = 'video_close';
		
	var windowHeight = window.getSize().scrollSize.y;
	this.vshade = new Element('div').setProperty('id', 'video_shade').injectInside(document.body);
	this.vshade.innerHTML = "<img src=\"/img/spacer.gif\" width=\"100%\" height=\"100%\" galleryimg=\"no\" />";
	
	this.vbox = new Element('div').setProperty('id', vidBoxID).injectInside(document.body);
	
	//create video close button
	this.vclose = new Element('div').setProperty('id', closeDivID).injectInside(this.vbox);
	this.vclose_a = new Element('a').injectInside(this.vclose);
	this.vclose_a.innerHTML = "&nbsp;";
	
	//create video player	
	this.vholder = new Element('div').setProperty('id', vidPlayerID).injectInside(this.vbox);
	
	//this.vshade.setStyles({opacity: '0.75'});// handled with a transparent png instead
	this.vshade.setStyles({height: windowHeight+'px'});
	this.vshade.setStyles({display: 'block'});
	this.vbox.setStyles({display: 'block'});
	this.vholder.setStyles({display: 'block'});
	this.vclose.setStyles({display: 'block'});
	this.vclose.setStyles({zIndex: 25});
	
	
	
	this.vshade.onclick = function(){
		//linkTrack("video", "close_" + eval("title_asset") + "_video");
		closePlayer();
	};
	
	this.vclose.onclick = function(){
		//linkTrack("video", "close_" + eval("title_asset") + "_video");
		closePlayer();
	};

	assetId = eval("assetId"+iVal);
	videoActive = true;
	showFlash(player, vidPlayerID, '', '');
}

////////////
function showSWFOverlay(swf_src,xml_src) {

		//eval(idVal+"_targetDiv");
		(!swf_src)?"":swf_src+= "?r=" + new Date().getTime();
		
		videoType = "";
		vidBoxID = 'video_box';
		vidPlayerID = 'video_player';
		closeDivID = 'video_close';
		closeLang = closeVal;
		n_height = temp_height;
		n_width = temp_width;
			
			
		(!swf_src)?player = swf_asset:player = swf_src;
		(!xml_src)?xml_loc = temp_xml:xml_loc = xml_src;
		//player = swf_asset;
		//xml_loc = flickr_xml;
		
		// cache buster for IE7 redraw issues
	

		
		var windowHeight = window.getSize().scrollSize.y;
	this.vshade = new Element('div').setProperty('id', 'video_shade').injectInside(document.body);
	this.vshade.innerHTML = "<img src=\"/img/spacer.gif\" width=\"100%\" height=\"100%\" galleryimg=\"no\" />";
	
	this.vbox = new Element('div').setProperty('id', vidBoxID).injectInside(document.body);
	
	//create video close button
	this.vclose = new Element('div').setProperty('id', closeDivID).injectInside(this.vbox);
	this.vclose_a = new Element('a').injectInside(this.vclose);
	this.vclose_a.innerHTML = closeLang;
	
	//create video player	
	this.vholder = new Element('div').setProperty('id', vidPlayerID).injectInside(this.vbox);
	
	(player == swf_src)?this.vholder.setStyles('height:'+n_height+';'):this.vholder.setStyles('height:'+n_height+';');
	
	//this.vshade.setStyles({opacity: '0.75'});// handled with a transparent png instead
	this.vshade.setStyles({height: windowHeight+'px'});
	this.vshade.setStyles({display: 'block'});
	this.vbox.setStyles({display: 'block'});
	this.vholder.setStyles({display: 'block'});
	this.vholder.setStyles({background: '#ffffff'});
	this.vclose.setStyles({display: 'block'});
	this.vclose.setStyles({zIndex: 25});
	
	if (navigator.appVersion.indexOf("Mac")!=-1){
		// if on a mac
		
			if($('flash_content')) {
				$('flash_content').setStyles({visibility: 'hidden'});
			}
		
	}
	
	this.vshade.onclick = function(){
		
		closePlayer();
	};
	
	this.vclose.onclick = function(){
	
		closePlayer();
	};

	videoActive = true;
	showFlash(player, vidPlayerID, "&xml_loc="+xml_loc, "");
	
}
////////////

function showHTML(inner_contents) {
	
	var windowHeight = window.getSize().scrollSize.y;
	this.hshade = new Element('div').setProperty('id', 'video_shade').injectInside(document.body);
	this.hshade.innerHTML = "<img src=\"/img/spacer.gif\" width=\"100%\" height=\"100%\" galleryimg=\"no\" />";
	
	this.hbox = new Element('div').setProperty('id', 'html_overlay').injectInside(document.body);
	this.hbox.innerHTML = inner_contents;

	this.hshade.setStyles({height: windowHeight+'px'});
	this.hshade.setStyles({display: 'block'});
	this.hbox.setStyles({display: 'block'});

	this.hshade.onclick = function(){
		//capture click
	};
}

function setJSON(){

	window.document[vidPlayerID+"_flash"].SetVariable("title", eval("title_asset"+pID));
	window.document[vidPlayerID+"_flash"].SetVariable("poster", eval("poster_asset"+pID));
	window.document[vidPlayerID+"_flash"].SetVariable("flv", eval("video_asset"+pID));
	window.document[vidPlayerID+"_flash"].SetVariable("disclaimer", eval("disclaimer_asset"+pID));
	window.document[vidPlayerID+"_flash"].SetVariable("auto_play", "autoplay");
	window.document[vidPlayerID+"_flash"].change();
	
}

function setEmbedLoaded(){
	embedLoaded = true;
	setJSON();

}
function closePlayer() {
	vshade.remove();
	vbox.remove();
	vholder.remove();
	vclose.remove();
	vclose_a.remove();
	videoActive = false;
	if (navigator.appVersion.indexOf("Mac")!=-1){
		// if on a mac
		if($('flash_content')) {
			$('flash_content').setStyles({visibility: 'visible'});
		}
		
	}
}
