﻿
//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var $jq = jQuery.noConflict();

//CONTROLLING EVENTS IN jQuery
$jq(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	if ($jq('.bubbleInfo') != null) {
	$jq('.bubbleInfo').each(function () {
    
    	var trigger = $jq('.trigger', this);
    	var popup = $jq('.popup', this); //.css('opacity', 0);
 		var closepopup = $jq('#popupClose', this);
		var background = $jq('#backgroundPopup', this);
	
    	// set the mouseover and mouseout on both element
    	$jq([trigger.get(0), popup.get(0)]).click(function () {
			//centering with css
			//centerPopup();
			var windowWidth = document.documentElement.clientWidth;
			var windowHeight = document.documentElement.clientHeight;
			var popupHeight = $jq(".popup").height();
			var popupWidth = $jq(".popup").width();
			//centering
			$jq(popup).css({
				"position": "absolute",
				"top": windowHeight/2-popupHeight/2
				//"left": windowWidth/2-popupWidth/2
			});
			//only need force for IE6
	
			$jq(background).css({
				"height": windowHeight
			});
		
		
			//load popup
			//loadPopup();
			if(popupStatus==0){
				$jq(background).css({
					"opacity": "0.7"
			});
			$jq(background).fadeIn("slow");
			$jq(popup).fadeIn("slow");
			popupStatus = 1;
		}
	
			return false;
		});
				
		//CLOSING POPUP
		//Click the x event!
		$jq([closepopup.get(0), background.get(0)]).click(function(){
			//disablePopup();
			if(popupStatus==1){
				$jq(background).fadeOut("slow");
				$jq(popup).fadeOut("slow");
				popupStatus = 0;
			}
			return false;
		});
	
	});

	//Press Escape event!
	$jq(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
  
	}
});
