﻿function videoComplete(obj) {
	if(obj.newstate == 'COMPLETED')
		window.location = '/index.php';
}

var player;
function playerReady(obj) {
	player = document.getElementById(obj['id']);
	player.addModelListener("STATE","videoComplete");
};

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		if(!(jQuery.browser.mozilla && jQuery.browser.version.substr(0,3)=="1.8"))
			$("#backgroundPopup").fadeIn("slow");
	
		$("#popupIntro").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
	//	if(!(jQuery.browser.mozilla && jQuery.browser.version.substr(0,3)=="1.8"))
			$("#backgroundPopup").fadeOut("slow");
		
		$("#popupIntro").fadeOut("slow");
		popupStatus = 0;
		
		var player = document.getElementById('mediaplayer');
		player.sendEvent('STOP');
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupIntro").height();
	var popupWidth = $("#popupIntro").width();
	//centering
	$("#popupIntro").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
//$(document).ready(function(){
//	//LOADING POPUP
//	//Click the button event!
//	$("#tv_spot").click(function(){
//		//centering with css
//		centerPopup();
//		//load popup
//		loadPopup();
//	});
//			
//	//CLOSING POPUP
//	//Click the x event!
//	$("#popupIntroClose").click(function(){
//		disablePopup();
//	});
//	//Click out event!
//	$("#backgroundPopup").click(function(){
//		disablePopup();
//	});
//	//Press Escape event!
//	$(document).keypress(function(e){
//		if(e.keyCode==27 && popupStatus==1){
//			disablePopup();
//		}
//	});
//
//});
