﻿/***************************/
//@Original Author: Adrian "yEnS" Mato Gondelle
//@Website: www.yensdesign.com
//@Email: yensamg@gmail.com
//@License: Feel free to use it, but keep this credits please!					

//@Amended For Multiple Popups By: Dan @ Digicution
//@Website: www.digicution.com
//@Email: dan@digicution.com
/***************************/

//Popup Setup
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//Popup Loading Code
function loadPopup(Element){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#" + Element + "Popup").fadeIn("slow");
		popupStatus = 1;
	}
}

//Popup Disabling Code
function disablePopup(Element){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$(".popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}


//Position At Top Of Trigger Element
function centerPopup(Element){
	
	//Request Data 4 Positioning
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#" + Element + "Popup").height();
	var popupWidth = $("#" + Element + "Popup").width();
	
	//Positioning
	$("#" + Element + "Popup").css({
		"position": "absolute",
		
		"top": jQuery(window).scrollTop()+30,
		"left": windowWidth/2-popupWidth/2,
		"display": "block",
		"overflow": "hidden"
	});
	
	//Force IE6
	$("#backgroundPopup").css({"height": windowHeight});
}


//ORIGINAL CODE Position At Top Of Trigger Element
//function centerPopup(Element){
//	
//	//Request Data 4 Positioning
//	var windowWidth = document.documentElement.clientWidth;
//	var windowHeight = document.documentElement.clientHeight;
//	var popupHeight = $("#" + Element + "Popup").height();
//	var popupWidth = $("#" + Element + "Popup").width();
//	var offset = $("#" + Element).offset();
//	alert(offset.top)
//
//	//Positioning
//	$("#" + Element + "Popup").css({
//		"position": "absolute",
//		"top": offset.top,
//		"left": windowWidth/2-popupWidth/2,
//		"display": "block"
//	});
//	//Force IE6
//	$("#backgroundPopup").css({"height": windowHeight});
//}

//Portfolio Popup Controllers
$(document).ready(function(){
	
	//PORTFOLIO LOADERS
	$("#Superhunt").click(function(){
		var Element = this.id;
		centerPopup(Element);
		loadPopup(Element);
	});
	$("#DWorld").click(function(){
		var Element = this.id;
		centerPopup(Element);
		loadPopup(Element);
	});
	$("#Dastardlies").click(function(){
		var Element = this.id;
		centerPopup(Element);
		loadPopup(Element);
	});
	$("#DTV").click(function(){
		var Element = this.id;
		centerPopup(Element);
		loadPopup(Element);
	});
	$("#SGE").click(function(){
		var Element = this.id;
		centerPopup(Element);
		loadPopup(Element);
	});
	$("#Champs").click(function(){
		var Element = this.id;
		centerPopup(Element);
		loadPopup(Element);
	});
	$("#SportI").click(function(){
		var Element = this.id;
		centerPopup(Element);
		loadPopup(Element);
	});
	$("#Store").click(function(){
		var Element = this.id;
		centerPopup(Element);
		loadPopup(Element);
	});
	$("#WebVideo").click(function(){
		var url = "http://vimeo.com/digicution";    
		$(location).attr('href',url);
	});
	$("#Newsletters").click(function(){
		var Element = this.id;
		centerPopup(Element);
		loadPopup(Element);
			//Add Slideshow Functionality To Eflyer Portfolio
			$('.NewsletterImages').cycle({
				fx: 'fade',
			    speed:  300, 
			    next:   '.NewsletterImages', 
			    containerResize: 1,
			    timeout: 0 			
			});
			//Add Scroll Options To Each Image
			$(".NewsletterImages").click(function(){ 
	                //perform scroll baby 
	                $.scrollTo("#NewslettersPopup",10)
			});  
	});
				
	//PORTFOLIO CLOSER
	//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();}
	});
	
});