﻿/***************************/
//@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 popupStatus = 0;
var mapStatus = 0;

      jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
        return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback); 
      };



//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").slideDown("slow");
		popupStatus = 1;
		showButtons(0);
	}
	
}
function displayMap(){
if(mapStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.00"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#map").slideFadeToggle("slow");
		mapStatus = 1;
	}
}
//loading popup with jQuery magic!
function loadMap(){
	doMove(true);
	centerMap();
	//window.setTimeout("displayMap()", 300);
	//loads popup only if it is disabled
}

function centerMap(){
	var windowHeight = document.documentElement.clientHeight;
	var top = $("#dropdownwrapper").position().top+$("#dropdownwrapper").height()-6;
	var windowWidth = document.documentElement.clientWidth;
	var mapWidth = $("#map").width();
	//centering
	$("#map").css({
		"position": "absolute",
		"top": top,
		"left": windowWidth/2-mapWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}

function toggleMap(trig){   
  $(this).next().fadesliderToggle({ 
    speed:300, 
    easing : "swing" 
  }) 
  return false; 
}


//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
	if(mapStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#map").slideFadeToggle("slow");
		mapStatus = 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 sliderload(){
	
	$("#qtcontent").css("margin-top", "0px");
//			$("#slider").easySlider({
//				auto: true, 
//				continuous: true,
//				vertical: true,
//				controlsShow: false
//			});
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#quicktourbutton").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		sliderload();
	});
	
	$("#mapclose").click(function(){
		disablePopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
