﻿//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");
		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");
		popupStatus = 0;
	}
}
//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();
	//centering
	var arrayXY=getScrollXY();
	var xScroll=arrayXY[0];
	var yScroll=arrayXY[1];
	$("#popupContact").css({
		"position": "absolute",
		"top": yScroll+windowHeight/2-popupHeight/2,
		"left":xScroll+ 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!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
	$("#feedbacklink").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});

	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		sendurl();								   
		disablePopup();

	});
	
	/////////////////////////////////////////////////Newsletter code strats here ///////////////////////	
	$("#buttonnewsletter").click(function(){
		//centering with css
		centerPopupnewsletter();
		//load popup
		loadPopupnewsletter();
	});
	$("#popupContactClosenewsletter").click(function(){
		disablePopupnewsletter();

	});
	
	
	$("#buttonnewsletter_unscribe").click(function(){
		//centering with css
		centerPopupnewsletter_unscribe();
		//load popup
		loadPopupnewsletter_unscribe();
	});
	$("#popupContactClosenewsletter_unscribe").click(function(){
		disablePopupnewsletter_unscribe();

	});
	
	
//////////////////////////////////////end of Newsletter code//////////////

	
	
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();

		}

	});



});

/////////////////////////////////////////////////////Newsletter code////////////////
function loadPopupnewsletter(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupnewsletter").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupnewsletter").fadeIn("slow");
		$("#popupContactnewsletter").fadeIn("slow");
		popupStatus = 1;
	}
}
//disabling popup with jQuery magic!
function disablePopupnewsletter(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopupnewsletter").fadeOut("slow");
		$("#popupContactnewsletter").fadeOut("slow");
		popupStatus = 0;
	}
}
//centering popup
function centerPopupnewsletter(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContactnewsletter").height();
	var popupWidth = $("#popupContactnewsletter").width();
	//centering
	var arrayXY=getScrollXY();
	var xScroll=arrayXY[0];
	var yScroll=arrayXY[1];
	$("#popupContactnewsletter").css({
		"position": "absolute",
		"top": yScroll+windowHeight/2-popupHeight/2,
		"left":xScroll+ windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	$("#backgroundPopupnewsletter").css({
		"height": windowHeight
	});
}


//////////////////////////////////////////
function loadPopupnewsletter_unscribe(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupnewsletter_unscribe").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupnewsletter_unscribe").fadeIn("slow");
		$("#popupContactnewsletter_unscribe").fadeIn("slow");
		popupStatus = 1;
	}
}
//disabling popup with jQuery magic!
function disablePopupnewsletter_unscribe(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopupnewsletter_unscribe").fadeOut("slow");
		$("#popupContactnewsletter_unscribe").fadeOut("slow");
		popupStatus = 0;
	}
}
//centering popup
function centerPopupnewsletter_unscribe(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContactnewsletter_unscribe").height();
	var popupWidth = $("#popupContactnewsletter_unscribe").width();
	//centering
	var arrayXY=getScrollXY();
	var xScroll=arrayXY[0];
	var yScroll=arrayXY[1];
	$("#popupContactnewsletter_unscribe").css({
		"position": "absolute",
		"top": yScroll+windowHeight/2-popupHeight/2,
		"left":xScroll+ windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	$("#backgroundPopupnewsletter_unscribe").css({
		"height": windowHeight
	});
}
/////////////////////////////////////////

/////// end of Newsletter code/////////


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}