var popupStatus = 0;

//loading popup with jQuery magic!
function loadOverlayPopup(){
    //loads popup only if it is disabled    

    if(popupStatus==0){
        $("#overlayWrap").css({
            "opacity": ".5",
            "filter": "alpha(opacity=50)"
        });
        $("#overlayWrap").fadeIn("slow");
        $("#overlayContentWrap").fadeIn("slow", function(){
            $("#overlayContentWrap").css({
                "opacity": "1"
            });
        });
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disableOverlayPopup(){
    //disables popup only if it is enabled
    if(popupStatus==1){
        $("#overlayWrap").fadeOut("slow");
        $("#overlayContentWrap").fadeOut("slow");
        popupStatus = 0;
    }
    
    if ( $.browser.msie && $.browser.version<7) {        
        $("html").css({
            "overflow":"scroll"
        });
    }
}

function adjustHeight(){
    
}

function winResize(){
     
}

//centering popup
function centerOverlayPopup(){
    //request data for centering
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();
    var popupHeight = $("#overlayContentWrap").height();
    var popupWidth = $("#overlayContentWrap").width();
    var top = (windowHeight/2-popupHeight/2)-160;    
    var overflow = "hidden";
    var position = "fixed";
    var height = popupHeight;   
        
    if((popupHeight+40)>windowHeight){        
        overflow = "scroll";        
        height = windowHeight - 80;
    }   
        
    if(top<0){
        top = 10
    }
    
    //centering
    $("#overlayContentWrap").css({
        "position": position,
        "top": top,
        "left": windowWidth/2-popupWidth/2,
        "height":height,
        "overflow":overflow
    });
    
    //only need force for IE6            
    $("#overlayWrap").css({
        "height": windowHeight,
        "width": windowWidth
    });	
    
    if ( $.browser.msie && $.browser.version<7) {
        $("#overlayContentWrap").css({
            "position": "absolute",
            "top": top,
            "left": windowWidth/2-popupWidth/2,
            "height": height,
            "overflow": overflow
        });
        
        $("html").css({
            "overflow":"hidden"
        });
    }
}

//function for popup
function overlayPopup(){

    centerOverlayPopup();
    loadOverlayPopup();
}
