/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!
/***************************/

//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){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");

		var imgRep = '<img src="/wp-content/themes/newsmojo-child/images/private-jet-video.jpg" width="250" height="157">';
		document.getElementById('videoDiv').innerHTML = imgRep;

		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");

		var vidRep = '<div style="position:absolute; top:0; left:0; z-index:1;"><iframe width="250" height="157" src="http://www.youtube.com/embed/SmHkFQFfnd8" frameborder="0" allowfullscreen></iframe></div>';
		document.getElementById('videoDiv').innerHTML = vidRep;

		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth;	// = document.documentElement.clientWidth;
	var windowHeight;	// = document.documentElement.clientHeight;
	var E;

	/////////// Handling Window Width + Height //////////////
		//var viewportwidth;
		//var viewportheight;

		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

		if (typeof window.innerWidth != 'undefined')
		{
			//alert('browser 1');
		  windowWidth = window.innerWidth;
		  windowHeight = window.innerHeight;
		  E = window.pageYOffset;
		}

		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

		else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
		{
			//alert('browser 2');
		   windowWidth = document.body.clientWidth;	//.documentElement.clientWidth;
		   windowHeight = document.body.clientHeight;	//.documentElement.clientHeight;
		   E = document.body.scrollTop;
		   //alert('windowWidth: '+windowWidth+"\nwindowHeight: "+windowHeight);
		}

		// older versions of IE

		else
		{
			//alert('browser 3');
		   windowWidth = document.getElementsByTagName('body')[0].clientWidth;
		   windowHeight = document.getElementsByTagName('body')[0].clientHeight;
		   E = document.getElementsByTagName('body')[0].scrollTop;
		}
	//////////////// end ////////////////////////////////////

	//var y = 50+(windowHeight/2);
	//alert('E: ' + E);

	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();

	//alert('popupHeight:'+popupHeight+', popupWidth:'+popupWidth);
	var pTop = E + (windowHeight/2-popupHeight/2);	//Math.max(0,y-(r/2));
	var pBot = windowWidth/2-popupWidth/2;
	//alert('top:'+pTop+', pBot:'+pBot);

	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": (E + 150),	//windowHeight/2-popupHeight/2,
		"left": pBot	//windowWidth/2-popupWidth/2
	});
	//only need force for IE6

	$("#backgroundPopup").css({
		"height": windowHeight,
		"width": windowWidth
	});

}

//My function to pop a message
function messagePop(msg){

	//LOADING POPUP
	//centering with css
	centerPopup();
	//load popup
	loadPopup();

	var elem = document.getElementById ("popupMessage");
	//elem.innerText = msg;
	elem.innerHTML = msg;

	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
}

/*
//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});

	$("#button2").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});

	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});*/
