if(typeof Lk == 'undefined') Lk = {};

/**
 *
 */
Lk.ShadowWindow = function(){
   var pThis = this;
   var tShadow;
   var tContainer;
   var tWindow;

   var getScrollPosition = function()
      {
         var tScrollTop = document.body.scrollTop;
         if (tScrollTop == 0)
           {
              if (window.pageYOffset)
                tScrollTop = window.pageYOffset;
              else
                tScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
           }
         return tScrollTop;
      }

   var getPageSize = function()
      {
         var xScroll, yScroll;
         if (window.innerHeight && window.scrollMaxY) {
            xScroll = document.body.scrollWidth;
            yScroll = window.innerHeight + window.scrollMaxY;
         } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
         } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
         }

         var windowWidth, windowHeight;
         if (self.innerHeight) {	// all except Explorer
            windowWidth = self.innerWidth;
            windowHeight = self.innerHeight;
         } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
         } else if (document.body) { // other Explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
         }

         // for small pages with total height less then height of the viewport
         if(yScroll < windowHeight){
            pageHeight = windowHeight;
         } else {
            pageHeight = yScroll;
         }

         // for small pages with total width less then width of the viewport
         if(xScroll < windowWidth){
            pageWidth = windowWidth;
         } else {
            pageWidth = xScroll;
         }


         var tResult = { pageWidth:pageWidth, pageHeight:pageHeight, windowWidth:windowWidth, windowHeight:windowHeight };
         return tResult;
      }

   this.show = function(fContent, fSizeStrategy) {
      tShadow = jQuery('<div class="darkUnderground"></div>');
      tContainer = jQuery('<div class="container"></div>');
      tWindow = jQuery('<div class="window"></div>');
      tWindow.append(jQuery("<a href='#' class='closer'>&times;</a>").click(function(){ pThis.destroy(); }));

      jQuery(document.body).append(tShadow);
      jQuery(document.body).append(tContainer);
      tContainer.append(tWindow);
      if(typeof fContent != 'undefined')
        tWindow.append(fContent);
      if(typeof fSizeStrategy != 'undefined')
         {
            for(var tSt in fSizeStrategy.strategies)
              {
                 Lk.ui.strategies[fSizeStrategy.strategies[tSt]](tWindow, fSizeStrategy);
              }
         }

      tShadow.css('height', getPageSize().pageHeight);
      tContainer.css('top', getScrollPosition());
   }

   this.destroy = function() {
      tShadow.remove();
      tContainer.remove();
      delete tWindow;
      delete tContainer;
      delete tShadow;
   }

   this.getRootElement = function() {
      return tWindow;
   }
}
Lk.ShadowWindow.prototype = new Lk.ShadowWindow();

Lk.ui = {

    functions:{
       getClientHeight: function(){
         return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
       }
    }
   ,strategies : {
       size: function(fWindow, fConfig) {
              var tWidth = fConfig.width || 0;
              var tHeight = fConfig.height || 0;

              fWindow.height(tHeight);
              fWindow.width(tWidth);
           }
      ,center: function(fWindow, fConfig) {
              with(Lk.ui.functions) {
                 fWindow.css('margin-top', ((getClientHeight()-fWindow.height()) / 2));
              }
           }
    }
}
