﻿//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopupCisco(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopupCisco").css({
			"opacity": "0.5"
		});
		$("#backgroundPopupCisco").fadeIn("slow");
		$("#popupCisco").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupCisco(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopupCisco").fadeOut("slow");
		$("#popupCisco").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopupCisco(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupCisco").height();
	var popupWidth = $("#popupCisco").width();
	//centering
	$("#popupCisco").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopupCisco").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$('#buttonCisco a').click (function(){
		//centering with css
		centerPopupCisco();
		//load popup
		loadPopupCisco();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupCiscoClose").click(function(){
		disablePopupCisco();
	});
	//Click out event!
	$("#backgroundPopupCisco").click(function(){
		disablePopupCisco();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopupCisco();
		}
	});

});
