﻿/***************************/
//@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 changeEmbed(embedid){
	$('#embedcontainer').html("<center>"+embeds[embedid]+"</center>");
	$('.ui-tabs-selected').removeClass('ui-tabs-selected');
	$('.ui-state-active').removeClass('ui-state-active').addClass('ui-state-default');
	$('#selector'+embedid).removeClass('ui-state-default').addClass('ui-state-active').addClass('ui-tabs-selected');
	$('#embedcontainer iframe').width("100%");
	$('#embedcontainer object').width("100%");
	$('#embedcontainer embed').width("100%");
}


//loading popup with jQuery magic!
function loadPopup(id){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#"+id).fadeIn("slow");
		//$("#backgroundPopup").show();
		//$("#"+id).show();
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(id){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$(".popupcontact").fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(id){
	var windowWidth = $(window).width();
	var windowHeight = $(window).height();
	var scrollpos = document.body.scrollTop;
	
	var popupHeight = $("#"+id).height();
	var popupWidth = $("#"+id).width();
	$("#"+id).css({
		"position": "absolute",
		"top": scrollpos+(windowHeight/2-popupHeight/2),
		"left": windowWidth/2-popupWidth/2
	});

	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

$(document).ready(function(){
	$(".pop").click(function(){
	    var id = $(this).attr('rel');
		centerPopup(id);
		loadPopup(id);
	});				

	$(".closebutton").click(function(){
		disablePopup();
	});
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
