/***************************/
//@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(divName) {
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#divPopup"+divName).mousedown(function(e) {
        	    var d = $(this);
		    if(e.target.nodeName != "DIV") return true;
        	    var dx = d.offset().left;
        	    var dy = d.offset().top;
        	    var xgap = e.pageX-dx;
        	    var ygap = e.pageY-dy;
                    if (!$.browser.msie) {
                        e.preventDefault();
                    }
    		    $(document).mousemove(function(e) {
        		var x = e.pageX-xgap;
        		var y = e.pageY-ygap;
                        if ($.browser.msie) {
                    	    // IE only here
                            e.preventDefault();  //IE's
                            if(e.pageX >= 0 && e.pageY >= 0) d.css({left: x, top: y });
                    	    return false;
                        }
                        // FF only here
            		if(e.pageX >= 0 && e.pageY >= 0) d.css({left: x, top: y });
                        return true;
    		    });
		}).mouseup(function(e) { $(document).unbind('mousedown');$(document).unbind('mousemove'); });
		$("#divPopup"+divName).fadeIn("slow");
		popupStatus = 1;
	}
}

function waitingPopup(divName) {
	$("#divPopup"+divName).html("<img src='/img/spinner.gif'> Please wait...");
}

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

//centering popup
function centerPopup(divName) {
	$("#divPopup"+divName).center({ vertical: true, horizontal: true });
}
