﻿/***************************/
//@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;

//loading popup with jQuery magic!
function loadPopup(wipp, pheight){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#popup"+wipp).css({
			"width": pheight
		});
		$("#backgroundPopup"+wipp).css({
			"opacity": "0.7"
		});
		$("#backgroundPopup"+wipp).fadeIn("slow");
		$("#popup"+wipp).fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(wipp){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup"+wipp).fadeOut("slow");
		$("#popup"+wipp).fadeOut("slow");
		popupStatus = 0;
	}
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
//centering popup
function centerPopup(wipp, pheight){
	//request data for centering
	$("#popup"+wipp).css({
		"width": pheight
	});
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popup"+wipp).height();
	var popupWidth = $("#popup"+wipp).width();
	var toppos = f_scrollTop();
	//centering
	$("#popup"+wipp).css({
		"position": "absolute",
		"top": toppos + windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup"+wipp).css({
		"height": toppos + windowHeight
	});
	
}

