﻿/***************************/
//@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 imgNameUrl = '';
var obj1, obj2, obj3;

//loading popup with jQuery magic!
function loadPopup(){
    //alert('l');
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$(obj3).fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopup_c(obj){
    //alert('l');
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$(obj).fadeIn("slow");
		popupStatus = 1;
	}
}


//disabling popup with jQuery magic!
function disablePopup_c(obj){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#"+obj.id.replace('popupContactClose_', 'popupContact_')).fadeOut("slow");
		popupStatus = 0;
	}
}

function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$(obj3).fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
    //alert(obj3);
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(obj3).height();
	var popupWidth = $(obj3).width();
	//centering
	$(obj3).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2 < 0 ? 0 : windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2 < 0 ? 0 : windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function centerPopup_c(obj){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(obj).height();
	var popupWidth = $(obj).width();
	//centering
	$(obj).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2 < 0 ? 0 : windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2 < 0 ? 0 : windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	disablePopup();
	//LOADING POPUP
	//Click the button event!
	$(".track_hint").click(function(){
	    if(this.tagName=="IMG"){
	        if(this.id){
	            if (this.id.split("_").length>1){
	                if (document.getElementById('bigImageView')){
    	                document.getElementById('bigImageView').src = 'Images/EMags/'+this.id.split("_")[1]+'.jpg';
	                }
	            }
	        }
	        obj1 = this;
	        obj2 = '#popupContactClose_pd';
	        obj3 = '#popupContact_pd';
	    }
	    else {
	        obj1 = this;
	        obj2 = '#popupContactClose_' + this.id;
	        obj3 = '#popupContact_' + this.id;
	        
	        if ($("NEWSLETTERSUBSCRIBER1_newsletter")){
	            if ($("txtEmail")){
	                $("txtEmail").value = $("NEWSLETTERSUBSCRIBER1_newsletter").value;
	                $("NEWSLETTERSUBSCRIBER1_newsletter").value='';
	            }
	            if ($("NEWSLETTERSUBSCRIBER1_txtEmail")){
	                $("NEWSLETTERSUBSCRIBER1_txtEmail").value = $("NEWSLETTERSUBSCRIBER1_newsletter").value;
	                $("NEWSLETTERSUBSCRIBER1_newsletter").value='';
	            }
	        }
	        
	    }
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
			
	//CLOSING POPUP
	//Click the x event!
	$(obj2).click(function(){
		disablePopup();
	});

	//Click out event!
//	jQuery("#backgroundPopup").click(function(){
//		disablePopup();
//	});
	//Press Escape event!
	/*jQuery(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});*/

})
