/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupAgendaStatus = 0;

//loading popup with jQuery magic!
function loadPopupAgenda(){
	//loads popup only if it is disabled
	if(popupAgendaStatus==0) {
		$("#agendaPopup").fadeIn("slow");
		popupAgendaStatus = 1;
		//Cargar contenido
		$("#agendaPopupContenido").load('pajax.php?accion=popagenda', "",
	        function(responseText, textStatus, XMLHttpRequest) {
	            if(textStatus == 'error') {
	                $('#agendaPopupContenido').html('<p>Ocurri&oacute; un error al obtener la informaci&oacute;n</p>');
	            }
	        }
		);
	}
}

//disabling popup with jQuery magic!
function disablePopupAgenda(){
	//disables popup only if it is enabled
	if(popupAgendaStatus==1){
		$("#agendaPopup").fadeOut("slow");
		popupAgendaStatus = 0;
	}
}

//centering popup
function centerPopupAgenda() {
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#agendaPopup").height();
	var popupWidth = $("#agendaPopup").width();

//alert(screen.width);
//alert($("#popupWindow").width());
//alert((screen.width-popupWidth)/2);
		//centering
	$("#agendaPopup").css({
		"position": "absolute",
		"top": (windowHeight/2-popupHeight/2),
		"left": (screen.width - popupWidth)/2
	});
	//only need force for IE6

}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

	//LOADING POPUP
	//Click the buttonPopup event!
//	$("#buttonPopupAgenda").click(function(){
//		//centering with css
//		//centerPopup();
//		//load popup
//		loadPopup();
//	});

	//CLOSING POPUP
	//Click the x event!
	$("#popupAgendaClose").click(function(){
		disablePopupAgenda();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupAgendaStatus==1){
			disablePopupAgenda();
		}
	});

});