﻿/***************************/
//@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;

//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(){
	document.getElementById('PopUpImage').src = "";
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
	showFlashObjects();
}

//centering popup
function centerPopup(){
	/*
	var winWidth = getClientWidth();
    var winHeight = getClientHeight();
    
    var popUpWidth = popUpWindow.style.width;
    var popUpHeight = popUpWindow.style.height;
    var popUpWidth = 885;
    var popUpHeight = 670;
    alert(winWidth+"   "+winHeight+"   "+popUpWidth+"   "+popUpHeight+"   "+getScrollTop());
    popUpWindow.style.top = getScrollTop()+"px";
    */

	//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)+getScrollTop(),
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


function hideFlashObjects(){
	$("#pixelWallHeader").css({
		"visibility": "hidden"
	});
	$("#whoswhoContainer").css({
		"visibility": "hidden"
	});
	$("#onetooneContainer").css({
		"visibility": "hidden"
	});
	$("#SpecialOfferHeader").css({
		"visibility": "hidden"
	});
}


function showFlashObjects(){
	$("#pixelWallHeader").css({
		"visibility": "visible"
	});
	$("#whoswhoContainer").css({
		"visibility": "visible"
	});
	$("#onetooneContainer").css({
		"visibility": "visible"
	});
	$("#SpecialOfferHeader").css({
		"visibility": "visible"
	});
}



function popUp(fullName, occupation, aboutText, imgURL){
	
	var popUpWindow = document.getElementById('popupContact');
	var popUpCloseBtn = document.getElementById('popUpCloseBtn');
	
	// Populate text areas
	document.getElementById('PopUpName').innerHTML = fullName;
	document.getElementById('PopUpOccupation').innerHTML = occupation;
	document.getElementById('PopUpContent').innerHTML = aboutText;
	
	// Load Image
	document.getElementById('PopUpImage').src = imgURL;
	
	// Hide other flash objects
	hideFlashObjects();
	
	//$("#button").click();
	//centering with css
    centerPopup();
    //load popup
    loadPopup();
}

//-------------------------------------------------------------------------------------
	// Functions to retrieve window size and scroll position in all browsers
	
	function getClientWidth() {
		return getFilterResults (
			window.innerWidth ? window.innerWidth : 0,
			document.documentElement ? document.documentElement.clientWidth : 0,
			document.body ? document.body.clientWidth : 0
		);
	}
	function getClientHeight() {
		return getFilterResults (
			window.innerHeight ? window.innerHeight : 0,
			document.documentElement ? document.documentElement.clientHeight : 0,
			document.body ? document.body.clientHeight : 0
		);
	}
	function getScrollLeft() {
		return getFilterResults (
			window.pageXOffset ? window.pageXOffset : 0,
			document.documentElement ? document.documentElement.scrollLeft : 0,
			document.body ? document.body.scrollLeft : 0
		);
	}
	function getScrollTop() {
		return getFilterResults (
			window.pageYOffset ? window.pageYOffset : 0,
			document.documentElement ? document.documentElement.scrollTop : 0,
			document.body ? document.body.scrollTop : 0
		);
	}
	function getFilterResults(n_win, n_docel, n_body) {
		var n_result = n_win ? n_win : 0;
		if (n_docel && (!n_result || (n_result > n_docel)))
			n_result = n_docel;
		return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	}
//-------------------------------------------------------------------------------------


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	
	//Click the button event!
	$("#button").click(function(){
		alert("Btn clicked");
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//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();
		}
	});

});