﻿/***************************/
//@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;

function preloadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#archive-overlay-bg").css({
			"opacity": "0.7"
		});
		$("#archive-overlay-bg").fadeIn("slow");
		$("#archive-overlay-loading").fadeIn("slow");
	}
}

function completeloadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
	    $("#archive-overlay-loading").css({
			"display": "none"
		});
		$("#archive-overlay").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#archive-overlay-bg").fadeOut("slow");
		$("#archive-overlay").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#archive-overlay").height();
	var popupWidth = $("#archive-overlay").width();
	var isIE6 = $("#archive-overlay").css("left"); 

	//centering
	$("#archive-overlay").css({
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});

    if (isIE6 == '-10000px') { //ie6 hack
	    $("#archive-overlay").css({
		    "left": windowWidth/2-popupWidth+popupWidth/6
	    });		
	    
	    //only need force for IE6
	    $("#archive-overlay-bg").css({
		    "height": windowHeight
	    });
	}
}


function clickLaunch(testid) {
	//darken screen 
	preloadPopup();
	
	//get the data for the popup
	var id = testid;
	$("#frame").html("<iframe id='archivePopup' src='/Popup.aspx?id=" + id.toString() + "' frameBorder='0' scrolling='no'></iframe>");
	centerPopup();
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

$("body").append("<div id='archive-overlay'><div id='hide-button-overlay' onclick='disablePopup()'><a href='javascript:;'><img src='/includes/img/project/portfolio-listbox_hide.gif' oversrc='/includes/img/project/portfolio-listbox_hide-roll.gif'></a></div><div id='frame'></div></div><div id='archive-overlay-bg' onclick='disablePopup();'></div><div id='archive-overlay-loading'><img src='/includes/img/global/loadingAnimation.gif' alt='loading, please wait' /></div>");
    
//Press Escape event!
$(document).keypress(function(e){
	if(e.keyCode==27 && popupStatus==1){
		disablePopup();
	}
});   

});


