
$("document").ready(function(){
		if(autoShow){
			centerPopup();
        	loadPopup();
        }
        
    	$("#popupBackground").click(function(){
        	disablePopup();
    	});
    	$("#messageBox").click(function(){
        	disablePopup();
    	});
    	    	
    	$("#news").click(showMessage);
    
    	$("#calendar").click(showCalendar);
    	
});

var popupStatus=0;
function loadPopup(){
	
	if(popupStatus==0){

		$("#popupBackground").css({"opacity":"0.7"});
		$("#popupBackground").fadeIn("slow");
        $("#messageBox").fadeIn("slow");
   		$("#messageBox").CreateBubblePopup({ innerHtml: 'Click anywhere to Close'});
   		$("#messageBox").SetBubblePopupOptions({
   			position:'top',align:'right',
   			tail:{align:'right'},
   			innerHtml:'<span style="color:black; font-family:verdana; text-shadow:2px 2px 5px #999;">Click anywhere to close</span>',
   			themeName:'all-yellow',
   			themePath:'jquerybubblepopup-theme'
   		});
        popupStatus=1;
	}
}

function centerPopup(){

        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var popupHeight = $("#messageBox").height();
        var popupWidth = $("#messageBox").width();

        $("#messageBox").css({
            "position": "absolute",
            "top": windowHeight/2-popupHeight/2,
            "left": windowWidth/2-popupWidth/2
        });
                
        $("#popupBackground").css({
            "height": windowHeight
        });
}

function showMessage(){
		centerPopup();
        loadPopup();
    
    	$("#popupBackground").click(function(){
        	disablePopup();
    	});
    	$("#messageBox").click(function(){
        	disablePopup();
    	});
}
function disablePopup(){
    if(popupStatus==1){
        $("#popupBackground").fadeOut("slow");
        $("#messageBox").fadeOut("slow"); 
        $("#messageBox").RemoveBubblePopup();   
        popupStatus=0;
    }
    
}


function showCalendar(){
		centerCalendar();
		loadCalendar();
		$("#popupBackgroundCalendar").click(function(){
        	disableCalendar();
    	});
    	$("#calendarBox").click(function(){
        	disableCalendar();
    	});
}
function centerCalendar(){

		var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var popupHeight = $("#calendarBox").height();
        var popupWidth = $("#calendarBox").width();

        $("#calendarBox").css({
            "position": "absolute",
            "top": windowHeight/2-popupHeight/2,
            "left": windowWidth/2-popupWidth/2
        });
                
        $("#popupBackgroundCalendar").css({
            "height": windowHeight
        });
}
function disableCalendar(){
	if(popupStatus==1){
		$("#calendarBox").fadeOut("slow"); 
        $("#calendarBox").RemoveBubblePopup(); 
        $("#popupBackgroundCalendar").fadeOut("slow");      
        popupStatus=0;
    }
}
function loadCalendar(){
	
	if(popupStatus==0){

		$("#popupBackgroundCalendar").css({"opacity":"0.7"});
		$("#popupBackgroundCalendar").fadeIn("slow");
        $("#calendarBox").fadeIn("slow");
   		$("#calendarBox").CreateBubblePopup({ innerHtml: 'Click anywhere to Close'});
   		$("#calendarBox").SetBubblePopupOptions({
   			position:'top',align:'right',
   			tail:{align:'right'},
   			innerHtml:'<span style="color:black; font-family:verdana; text-shadow:2px 2px 5px #999;">Click anywhere to close</span>',
   			themeName:'all-yellow',
   			themePath:'jquerybubblepopup-theme'
   		});
        popupStatus=1;
	}
}


