﻿/***************************/
//@Base Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com

//@Mod. Author: Graziano
//Modified script to place popup in right place when the page is scrolled down. I used script from lightbox. Also added few things so it could view handle more than one popup plus function for my site.
/***************************/

//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){
			$("#announcement_background").css({
				"opacity": "0.8"
			});
			$("#announcement_background").fadeIn("slow");
			$(popupSelect).fadeIn("slow");
			popupStatus = 1;
		}
	}

//disabling popup with jQuery magic!
	function disablePopup(){
		//disables popup only if it is enabled
		if(popupStatus==1){
			$("#announcement_background").fadeOut("slow");
			$(popupSelect).fadeOut("slow");
			popupStatus = 0;
		}
	}

	function ___getPageScroll() {
				var xScroll, yScroll;
				if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};

//centering popup
	function centerPopup(){
		___getPageScroll();
		//request data for centering
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var popupWidth = $(popupSelect).width();
		var arrPageScroll = ___getPageScroll();
		//centering
		$(popupSelect).css({
			"position": "absolute",
			"top":150+arrPageScroll[1],
			"left": (windowWidth-popupWidth)/2-30
		});
		//only need force for IE6
		
		$("#announcement_background").css({
			"height": windowHeight
		});
	
	}
//functions for flash menu
	function _show_offer()  
   {  
		popupSelect = "#announcement";
		centerPopup();
		loadPopup(); 
   } ;
   function _show_about()  
   {  
		popupSelect = "#popup_about";
		centerPopup();
		loadPopup(); 
   } 

$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button_offer_1,#button_offer_2").click(function(){

		popupSelect = "#announcement";
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
	$("#button_about").click(function(){

		popupSelect = "#popup_about";
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	})
				

});

