/**
 * requires jQuery
 */
var blibs;
if(!blibs) blibs = {};

blibs.DivLayer = function()
{
   this.init = function()
   {
      if(!$("#masterLayer").length)
         $('<div class="divLayer" id="masterLayer"></div>').appendTo("body");

      this.hide();
   };

   this.hide = function(divLayerId)
   {
      if(divLayerId)
         $("#"+divLayerId).hide();
      else
         $(".divLayer").hide();
   }

   this.show = function(content, divLayerId)
   {
      if(divLayerId && !$("#"+divLayerId).length)
         $("#masterLayer").clone().attr('id', divLayerId).appendTo("body").hide();

      var divLayer = divLayerId? $("#"+divLayerId) : $("#masterLayer");

      if(content)
         divLayer.empty().append(content).show();
      else
         divLayer.show();

      divLayer.find("iframe:first").height($(document).height());
   }




this.getIframeDimensions = function() {
    var viewportDim = this.getViewportDimensions();
    var documentDim = this.getDocumentDimensions();
    var scrollOffset = this.getScrollOffset();

    var iframeDim = {};
    iframeDim.greywidth = documentDim.width;//(documentDim.width > viewportDim.width)? documentDim.width : viewportDim.width;
    iframeDim.greyheight = (documentDim.height > viewportDim.height)? documentDim.height : viewportDim.height;

    iframeDim.layerwidth = (iframeDim.greywidth <= 637)? 637 : iframeDim.greywidth;
    iframeDim.layerheight = (viewportDim.height <= 700)? 700 : viewportDim.height;
    iframeDim.layeroffsettop = scrollOffset.top;

    return iframeDim;
}

this.getViewportDimensions = function() {
    var viewportDim = {};
    viewportDim.width = 0, viewportDim.height = 0;

    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        viewportDim.width = window.innerWidth;
        viewportDim.height = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        viewportDim.width = document.documentElement.clientWidth;
        viewportDim.height = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        viewportDim.width = document.body.clientWidth;
        viewportDim.height = document.body.clientHeight;
    }

    return viewportDim;
}

this.getDocumentDimensions = function() {
    var documentDim = {};
    documentDim.width = 0;
    documentDim.height = 0;

    var bodyMargin = this.getBodyMargin();

    if (document.body.scrollWidth) {
        documentDim.width = document.body.scrollWidth + bodyMargin.x;
        documentDim.height = document.body.scrollHeight + bodyMargin.y;

    } else {
        documentDim.width = document.documentElement.offsetWidth + bodyMargin.x;
        documentDim.height = document.documentElement.offsetHeight + bodyMargin.y;

        if (window.scrollMaxX) {
            documentDim.width += window.scrollMaxX;
        }
    }
    return documentDim;
}

this.getBodyMargin = function() {
    var bodyElt = document.getElementsByTagName('body').item(0);
    var bodyMargin = {};
    bodyMargin.top = 0, bodyMargin.right = 0,  bodyMargin.bottom = 0, bodyMargin.left = 0;
    bodyMargin.x = 0, bodyMargin.y = 0;

    if (window.getComputedStyle) { // standard
        var bodyStyle = window.getComputedStyle(bodyElt, '');
        bodyMargin.top = parseInt(bodyStyle.getPropertyValue('margin-top'));
        bodyMargin.right = parseInt(bodyStyle.getPropertyValue('margin-right'));
        bodyMargin.bottom = parseInt(bodyStyle.getPropertyValue('margin-bottom'));
        bodyMargin.left = parseInt(bodyStyle.getPropertyValue('margin-left'));
        bodyMargin.x = bodyMargin.right + bodyMargin.left;
        bodyMargin.y = bodyMargin.top + bodyMargin.bottom;
    } else if (bodyElt.currentStyle) { // IE
        bodyMargin.top = parseInt(bodyElt.currentStyle.marginTop);
        bodyMargin.right = parseInt(bodyElt.currentStyle.marginRight);
        bodyMargin.bottom = parseInt(bodyElt.currentStyle.marginBottom);
        bodyMargin.left = parseInt(bodyElt.currentStyle.marginLeft);
        bodyMargin.x = bodyMargin.right + bodyMargin.left;
        bodyMargin.y = bodyMargin.top + bodyMargin.bottom;
    }

    return bodyMargin;
}

this.getScrollOffset = function() {
    var scrollOffset = {};
    scrollOffset.left = 0, scrollOffset.top = 0;

    if (window.innerWidth) {
        /*
         * Alle Browser ausser dem IE
         */
        scrollOffset.left = window.pageXOffset;
        scrollOffset.top = window.pageYOffset;
    } else if (document.documentElement && document.documentElement.clientWidth ) {
        /*
         * IE6 mit Doctype
         */
        scrollOffset.left = document.documentElement.scrollLeft;
        scrollOffset.top = document.documentElement.scrollTop;
    } else if (document.body.clientWidth) {
        /*
         * IE456 ohne Doctype
         */
        scrollOffset.left = document.body.scrollLeft;
        scrollOffset.top = document.body.scrollTop;
    }

    return scrollOffset;
}

};


