﻿isScrollable=false;
isLayerVisible=false;
isOpen=false;
LB_ROOT_DIR="";

function AutoSize(_height,_width){$("#_divGB_Iframe").css({height:_height + "px",width:_width + "px"});}

$(function(){
    var iframe=document.createElement("IFRAME");
    if(isLayerVisible)
    {
        var layer=document.createElement("DIV");
        $(layer).attr("id","_divGB_ShowLayer").fadeTo("slow",0.43);
        $(layer).css({
                        position:"absolute",
                        top:"0px",
                        left:"0px",
                        width:($(window).width())+"px",
                        height:($(document.body).height())+"px",
                        display:"none",
                        background:"#000000",
                        zIndex:"200000"
                    });
        $(document.body).append(layer);
    }
    
    $(iframe).attr({
                    id:"_divGB_Iframe",
                    src:LB_ROOT_DIR+"/loader_frame.html",
                    scrolling:"auto",
                    frameBorder:"0",
                    allowTransparency:"true"
                  });
                   
    var outerDiv=document.createElement("DIV");
    $(outerDiv).append(iframe);
    $(outerDiv).attr({id:"_divGB_Show"})
    $(outerDiv).css({
                        position:"absolute",
                        top:"0px",
                        left:"0px",
                        display:"none",
                        zIndex:"2000001"
                   });
    $(document.body).append(outerDiv);
});

function GB_Show(url,heght,width,element,relativeTop,relativeLeft)
{
    if(isOpen)return false;
    $("#_divGB_Show").css({width:width+"px",height:heght+"px"});
    $("#_divGB_Iframe").css({width:width+"px",height:heght+"px"});
    
    document.getElementById('_divGB_Iframe').contentWindow.location.href=url;
    if(isLayerVisible)$("#_divGB_ShowLayer").show();
    if(element)
    {
        var rTop=relativeTop?relativeTop:0;
        var rLeft=relativeLeft?relativeLeft:0;
        $("#_divGB_Show").css({
                                top:($(element).offset().top+rTop)+"px",
                                left:($(element).offset().left+$(element).width()+rLeft)+"px"
                             }).slideDown("slow");
    }
    else
    {
        isScrollable=false;
        var t = document.body.scrollTop + 10;
        var l=($(document.body).width()-width)/2;
        $("#_divGB_Show").css({top:t+"px",left:l+"px"}).show();
    }
    
    if(isScrollable)
        $.scrollTo({top:($(element).offset().top-20)+'px',left:'0px'},1000,{queue:true});
        
    isOpen=true;
    return false;
}

function GB_Hide()
{
    try
    {
        if(isLayerVisible)
            $("#_divGB_ShowLayer").hide();
            
        isOpen=false;
        $("#_divGB_Show").hide();
        document.getElementById('_divGB_Iframe').contentWindow.location.href=LB_ROOT_DIR+"/loader_frame.html";
    }
    catch(e){}
}
