var hover_videoIntro;
var hover_videoIntroShadow;
var hover_videoFlash;
var button_closeIntro;
var button_intro;
var introPlayer;
var introSetup = false;
var oldEvt = window.onload;

window.onload = function() {
	if (oldEvt) oldEvt();

	hover_videoIntro = document.getElementById("videoIntroContainer");
	hover_videoIntroShadow = document.getElementById("videoIntroShadow");
	hover_videoFlash = document.getElementById("flash_fallback_introVideo");
	button_closeIntro = document.getElementById("closeIntroVideo");

	if (document.getElementById("button_watchIntroVideo")) {

		button_intro = document.getElementById("button_watchIntroVideo");

		if (playIntroVideo) {
			showVideo();
		}

		button_intro.onclick = showVideo;
		if (button_intro.captureEvents) button_intro.captureEvents(Event.CLICK);

		button_closeIntro.onclick = hideVideo;
		if (button_closeIntro.captureEvents) button_closeIntro.captureEvents(Event.CLICK);
		hover_videoIntroShadow.onclick = hideVideo;
		if (hover_videoIntroShadow.captureEvents) hover_videoIntroShadow.captureEvents(Event.CLICK);
	
	}
}

function showVideo(e) {
	hover_videoIntro.style.display = "block";
	hover_videoIntroShadow.style.display = "block";
	if(!introSetup) {
		introPlayer = VideoJS.setup("introVideo");
	    introSetup = true;
	}
	if(supports_video()) introPlayer.play();
}

function hideVideo(e) {
	hover_videoIntro.style.display = "none";
	hover_videoIntroShadow.style.display = "none";
	if(supports_video()) introPlayer.pause();
	if(hover_videoFlash.pausePlayback) hover_videoFlash.pausePlayback();
	return false;
}

function supports_video() {
  return !!document.createElement('video').canPlayType;
}
