var IE = (-[1,])? false : true;
var activePopupId = "";
var currentPopupId = "";
var lockId = "default";
var stopTimerId = "";
var autoHidingPopups = new Array();
var activeTimerId="";

function autoHiding(id, msec) {
	if (activeTimerId == "")
		activeTimerId = setTimeout(function(){hidePopup(id);}, msec);	
}
function stopTimer() {
	if (activeTimerId != "") {
		clearTimeout(activeTimerId);
		activeTimerId = "";
	}
}
function movePopup(sourceID, targetID) {
	if (targetID == null)
		$("#" + sourceID).appendTo("#div_uniPopup");
	else 
		$("#" + sourceID).appendTo("#" + targetID);
}

function showCentPopup(popupId){		
	currentPopupId = popupId;
	centPopup();
	showPopup(popupId);	
	activePopupId = popupId;
}

function isString(str) {
	return typeof str == 'string' || str instanceof String;
}

function showPopup(id) {
	var popup = isString(id) ? ('#' + id) : id;
	IE ? $(popup).show() : $(popup).fadeIn("fast");
	if (activePopupId) {
		var active = isString(activePopupId) ? ('#' + activePopupId) : activePopupId;
		if ($(active).is('div.addtocartpopup')) {
			hidePopup(activePopupId);
		}
	}
	activePopupId = id;	
}

function hidePopup(id) {
	if (id != lockId) {
		var popup = isString(id) ? ('#' + id) : id;
		IE ? $(popup).hide() : $(popup).fadeOut("fast");
		activePopupId = false;
	}
}


function centPopup(){
	//request data for centering
	

	var windowWidth = $(window).width();//document.documentElement.clientWidth;	
	var windowHeight = $(window).height();//document.documentElement.clientHeight;
	var qPopupId = "#" + currentPopupId;
	var popupHeight  = $(qPopupId).height();
	var popupWidth = $(qPopupId).width();
	var popupTopPosition = windowHeight/2-popupHeight/2;
	
	
	//centering
	$(qPopupId).css({		
		"height": popupHeight,
		"width": popupWidth,
		"position": "absolute",
		"top": getBodyScrollTop() + windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	
}

function getBodyScrollTop()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
