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

var gShowHideRegistr = new Array();
function registrationShowHideElement(fDomainName, fElementId)
  {
     if(!Ext.isArray(fElementId))
        {
           if(!gShowHideRegistr[fDomainName])
             gShowHideRegistr[fDomainName] = new Array();

           gShowHideRegistr[fDomainName][fElementId] = document.getElementById(fElementId);
        }
     else
       for(var t = 0; t < fElementId.length; t++)
         registrationShowHideElement(fDomainName, fElementId[t]);
  }

var gControlElement = null;
function showHidePanel(fDomainName, fElementId, fControlElement, fHandler)
  {
     if(!gShowHideRegistr[fDomainName])
       return ;
     var tDomainContainer = gShowHideRegistr[fDomainName];
     //alert(fElementId);
     if(!tDomainContainer[fElementId])
       return ;
     //alert(tDomainContainer[fElementId]);
     for(var tElementName in tDomainContainer)
       {
          if(tDomainContainer[tElementName] && typeof(tDomainContainer[tElementName]) != 'function')
            tDomainContainer[tElementName].style.display = "none";
       }

     if(gControlElement)
       gControlElement.className = "unselected";

     if(fControlElement != gControlElement)
        {
           fControlElement.className = "selected";
           gControlElement = fControlElement;
           tDomainContainer[fElementId].style.display = "";
        }
     else
       gControlElement = null;

     if(fHandler)
       fHandler(fDomainName, fElementId, fControlElement);

  }

/**
 *
 */
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;
      }

   function getClientHeight()
      {
         return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
      }



   this.show = function(fContent, fSizeStrategy) {
      tShadow = jQuery('<div class="darkUnderground"></div>');
      tContainer = jQuery('<div class="popup"></div>');
      tWindow = jQuery('<div class="window"></div>');

      jQuery(document.body).append(tShadow);
      jQuery(document.body).append(tContainer);
      tContainer.append(tWindow);
      if(typeof fContent != 'undefined')
        tWindow.append(fContent);
      if(typeof fSizeStrategy != 'undefined')
         {
            tWindow.height(fSizeStrategy.height || (jQuery(tShadow).height() - fSizeStrategy*2 -/*padding+border*/ 12));
            if(fSizeStrategy.width != 'auto')
               tWindow.width(fSizeStrategy.width || (jQuery(tShadow).width() - fSizeStrategy*2 - /*padding+border*/ 12));

            var tTop = ((getClientHeight()-tWindow.height()) / 2);
            tTop = tTop < 0 ? 0 : tTop;
            tWindow.css('margin-top', tTop);//fSizeStrategy.top || fSizeStrategy || ((getClientHeight()-tWindow.height()) / 2));
         }

      tShadow.css('height', getPageSize().pageHeight);
      tContainer.css('top', getScrollPosition());
      jQuery('.hssCloser', tContainer).click(function(){ pThis.destroy(); return false; });

   }

   this.destroy = function() {
      tShadow.remove();
      tContainer.remove();
      delete tWindow;
      delete tContainer;
      delete tShadow;
   }
}
Lk.ShadowWindow.prototype = new Lk.ShadowWindow();