﻿/***************************/
//@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 popupAdvertiseStatus = 0;

//loading popup with jQuery magic!
function loadAdvertisePopup(){
	//loads popup only if it is disabled
	if(popupAdvertiseStatus==0){
		$("#backgroundAdvertisePopup").css({
			"opacity": "0.7"
		});
		$("#backgroundAdvertisePopup").fadeIn("slow");
		$("#popupAdvertise").fadeIn("slow");
		popupAdvertiseStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disableAdvertisePopup(){
	//disables popup only if it is enabled
	if(popupAdvertiseStatus==1){
		$("#backgroundAdvertisePopup").fadeOut("slow");
		$("#popupAdvertise").fadeOut("slow");
		popupAdvertiseStatus = 0;
	}
}

//centering popup
function centerAdvertisePopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupAdvertise").height();
	var popupWidth = $("#popupAdvertise").width();
	//centering
	$("#popupAdvertise").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundAdvertisePopup").css({
		"height": windowHeight
	});
	
}

function showAdvertisePopup(){
	window.open('#', '_self');
	//centering with css
	centerAdvertisePopup();
	//load popup
	loadAdvertisePopup();
}

function sendAdvertiseForm(){
	$("#add-submit").click(function() {
		$(this).parents().filter("form").trigger("submit");
	});
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#popup-click").click(function(){
		//centering with css
		centerAdvertisePopup();
		//load popup
		loadAdvertisePopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupAdvertiseClose").click(function(){
		disableAdvertisePopup();
	});
	//Click out event!
	$("#backgroundAdvertisePopup").click(function(){
		disableAdvertisePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupAdvertiseStatus==1){
			disableAdvertisePopup();
		}
	});

});
