﻿var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;	
		player.sendEvent('STOP');
	}
}



//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	var x = 0;
	var y = 0;
//	alert(popupHeight + " " + popupWidth);
//	alert(windowHeight + " " + windowWidth);
//	alert((document.documentElement.scrollTop +(windowHeight-popupHeight)/2+y)+'px' + " " + (document.documentElement.scrollLeft+(windowWidth -popupWidth )/2+x)+'px');
//	
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"left": (document.documentElement.scrollLeft+(windowWidth -popupWidth )/2+x)+'px',
        "top": (document.documentElement.scrollTop +(windowHeight-popupHeight)/2+y)+'px'
	});
}




var player = null;
function playerReady(thePlayer) {
	player = window.document[thePlayer.id];
}





//LOADING POPUP
//Click the button event!
function popup(model, version, year){
    var modelVideo = model.split(" ");
    var s = new SWFObject("/Common/Flash/mediaplayer.swf","modelMovie","400","246","7");
    s.addParam("allowfullscreen","true");
    s.addVariable("width","400");
    s.addVariable("height","246");
    s.addVariable("displayheight","225");
    s.addVariable("file", "/Common/Videos/" + "2009" + "/" + modelVideo[0] + version + ".flv");
    s.addVariable("image","/Common/images/" +  modelVideo[0] + "_largethumb.jpg");
    s.addVariable("autostart", true);
    s.write("contactArea");
    centerPopup();
	loadPopup();
	document.getElementById("Desc").innerHTML = year + " " + model;
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
					
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});