var popupStatus = 0;
var scrollCachePosition = 0;
var srcFrame;
var menuActual;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		
		if (scrollCachePosition > 0) {
			window.top.scroll(0,scrollCachePosition);
			//Reseteamos la variable scrollCachePosition a 0 para poder ejecutar el script tantas veces sea necesario.
			scrollCachePosition = 0;
		}
		
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function PreguntaFrecuente(idpregunta)
{
	srcFrame = 'faq.php?id=' + idpregunta;
	
	var iframe = $('#frame');
	$(iframe).attr('src', srcFrame);
	scrollCachePosition = $(window).scrollTop();
	window.top.scroll(0,0);
	//centering with css
	centerPopup();
	//load popup
	loadPopup();
}

function ejemplos()
{	
		$("a[rel=fotos]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
}

$(document).ready(function(){


	
	$("#ordenar-ahora").click(function(){
		location.href="ordenar-ahora.php";
	});
	
	$('div .w-h-menu').filter(':not(:has(.seleccionado))')
		.mouseover(function () {
			$(this).addClass("over-celest");					
		})
		.mouseout(function (){
			$(this).removeClass("over-celest");							
		});
	
	$('#seccion-inicio-menu').filter(':not(.seleccionado)')
		.mouseover(function () {
			$("#seccion-inicio").addClass("over-izquierdo");
		})
		.mouseout(function () {
			$("#seccion-inicio").removeClass("over-izquierdo");
		});
		
	$('#seccion-contacto-menu').filter(':not(.seleccionado)')
		.mouseover(function () {
			$("#seccion-contacto").addClass("over-derecho");
		})
		.mouseout(function () {
			$("#seccion-contacto").removeClass("over-derecho");
		});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
