﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//CREANDO EL POP UP
//0 significa desactivado; 1 activado;
var popupStatus = 0;

//cargar el pop up
jQuery.noConflict(); //Para evitar conflictos con otras librerías
function loadPopup(){
	//carga el pop up sólo si está desactivado
	if(popupStatus==0){
		jQuery("#backgroundPopup").css({ //"jQuery" sustituye al "$" para evitar conflictos
			"opacity": "0.7"
		});
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//desactivando el pop up
jQuery.noConflict();
function disablePopup(){
	//desactiva el pop up sólo si está activado
	if(popupStatus==1){
		jQuery("#backgroundPopup").fadeOut("slow");
		jQuery("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centrando el pop up
jQuery.noConflict();
function centerPopup(){
	//recogida de datos para centrar el pop up
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#popupContact").height();
	var popupWidth = jQuery("#popupContact").width();
	//centrar pop up
	jQuery("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//sólo necesario para IE 6
	
	jQuery("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROL DE EVENTOS EN jQuery
jQuery.noConflict();
jQuery(document).ready(function(){
	
	//CARGAR POP UP
	//Muestra el elemento "#popup" al iniciar la página (index.asp)
	jQuery("#popup").show(function(){
		//centrando con css
		centerPopup();
		//cargar el pop up
		loadPopup();
	});
				
	//CERRAR POP UP
	//Evento de pulsar la x
	jQuery("#popupContactClose").click(function(){
		disablePopup();
	});
	//Evento de hacer click fuera del Pop up
	jQuery("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Evento de apretar ESC
	jQuery(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
