/***************************/
//@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 popupStatus2 = 0;

//loading popup with jQuery magic!
function loadPopup3(str){

	var div1;
	if (str == null){
		div1 = '#clubInvitationRequest';
	} else {
		div1 = '#clubInvitation'+str;
	}

	//loads popup only if it is disabled
	if(popupStatus2==0){
		$("#backgroundPopup3").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup3").fadeIn("slow");
		$(div1).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;

		popupStatus2 = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup2(str){

	var div1;
	if (str == null){
		div1 = '#clubInvitationRequest';
	} else {
		div1 = '#clubInvitation'+str;
	}

	//disables popup only if it is enabled
	if(popupStatus2==1){
		$("#backgroundPopup3").fadeOut("slow");
		$(div1).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;

		popupStatus2 = 0;
	}
}

//centering popup
function centerPopup3(str){

	var div1;
	if (str == null){
		div1 = '#clubInvitationRequest';
	} else {
		div1 = '#clubInvitation'+str;
	}

	//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 popupHeight = $(div1).height();
	var popupWidth = $(div1).width();

	//alert('popupHeight:'+popupHeight+', popupWidth:'+popupWidth);
	var pTop = windowHeight/2-popupHeight/2;
	var pBot = windowWidth/2-popupWidth/2;
	//alert('top:'+pTop+', pBot:'+pBot);

	//centering
	$(div1).css({
		"position": "absolute",
		"top": (E + 50),	//windowHeight/2-popupHeight/2,
		"left": pBot	//windowWidth/2-popupWidth/2
	});
	//only need force for IE6

	$("#backgroundPopup3").css({
		"height": windowHeight,
		"width": windowWidth
	});

}


//My function to pop a form
function popFormClub(str){	//msg,items,quote)

	if (str == null){
		//do not show any message
	} else {
		//alert(str);
		document.getElementById('popupClubMessage').innerHTML = str;
	}


	//LOADING POPUP
	//centering with css
	centerPopup3();
	//load popup
	loadPopup3();


	//CLOSING POPUP
	//Click the x event!
	$("#clubInvitationRequestClose").click(function(){
		disablePopup2();
	});
	//Click out event!
	$("#backgroundPopup3").click(function(){
		disablePopup2();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus2==1){
			disablePopup2();
		}
	});
}

function popClubThankYou(str){	//msg,items,quote)

//alert('str: ' + str);

	if (str == null){
		//do not show any message
	} else {
		//alert(str);
		document.getElementById('popupClubThankYouMessage').innerHTML = str;
	}


	//LOADING POPUP
	//centering with css
	centerPopup3('ThankYou');
	//load popup
	loadPopup3('ThankYou');


	//CLOSING POPUP
	//Click the x event!
	$("#clubInvitationThankYouClose").click(function(){
		disablePopup2('ThankYou');
	});
	//Click out event!
	$("#backgroundPopup3").click(function(){
		disablePopup2('ThankYou');
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus2==1){
			disablePopup2();
		}
	});
}

