////////////////////////////////////////////////////////////////////////////////
///                       DSLayerBox (DSLayerBox.js)                         ///
///                             Version: 1.0.4                               ///
///                               30.07.2009                                 ///
///                Copyright © 2007-2009 by Daniel Seichter                  ///                         
///                                                                          ///
///--------------------------------------------------------------------------///
///                                                                          ///
/// -> License/Lizenz <-                                                     ///
///                                                                          ///
/// You can modify and use this script in your own homepages/scripts for     ///
/// free, but if you use it or only parts of it, you have to add the name    ///
/// and the author of the following script in your homepages/scripts.        ///
///                                                                          ///
/// Sie dürfen dieses Script nach belieben modifizieren und benutzten,       ///
/// unter der Bedienung, dass eine Erwähnung des Scriptes inkl. Autor        ///
/// innerhalb des Programms erfolgt, wenn das Script in irgendeiner          ///
/// Art und Weise benutzt wird.                                              ///
///                                                                          ///
///--------------------------------------------------------------------------///
///                                                                          ///
/// -> ChangeLog <-                                                          ///
///                                                                          ///
///  22.07.2009: First Release (Version 1)                                   ///
///  24.07.2009: Ajax-Request-Fix                                            ///
///  29.07.2009: IE-Visibility-Fix                                           ///
///  30.07.2009: Some general changes                                        ///
///                                                                          ///
////////////////////////////////////////////////////////////////////////////////

/*******************************************************************************
* class DSLayerBox
* @access public
* @param integer box_height viewer height 
* @param integer box_width viewer width 
* @param string box_title title of the layerbox
* @param string box_loadpic_src path to the loading animation 
*/
  function DSLayerBox(box_height,box_width,box_loadpic_src) {  
    /***************************************************************************
    *  Variable that holds box_height
    */
      this.box_height = parseInt(box_height);
    /***************************************************************************
    *  Variable that holds box_width
    */      
      this.box_width = parseInt(box_width);      
    /***************************************************************************
    *  Variable that holds the path to the loading animation
    */      
      this.box_loadpic_src = null;
      this.box_loadpic_src = box_loadpic_src;
    /***************************************************************************
    *  Variables that hold the inforamtion
    */     
      this.box_title = null; 
      this.box_inner_text = null;
     //pointer to lb_layerboxwindow 
      this.obj = null;       
  }
    
    var thisDSLayerBox = DSLayerBox.prototype;
   
   /***************************************************************************
    * execute (user have to define it) 
    * @access public 
    */  
      thisDSLayerBox.Execute = function () {
          /**/
      };
   
    /***************************************************************************
    * Pos_windows (pos each window(divlayer)) 
    * @access private
    * @param pointer _this pointer to this class  
    */
      thisDSLayerBox.pos_windows = function(_this) {
         //get vars 
          var ClientWindowSize = get_clientwindowsize();
          var PageSize = get_pagesize();
          var PageScrollPos = get_page_scrollpos();
          
         //pos OverlayWindow
          var OverlayWindow = document.getElementById("lb_overlaywindow");
          
          set_element_style(OverlayWindow,"width",(ClientWindowSize[0] > PageSize[0]) ? ClientWindowSize[0]+"px" : (PageSize[0])+"px");  
          set_element_style(OverlayWindow,"height",(ClientWindowSize[1] > PageSize[1]) ? ClientWindowSize[1]+"px" : (PageSize[1])+"px");  
          
          if ((_this.box_width < ClientWindowSize[0]) && (_this.box_height < ClientWindowSize[1])) {
           
           //pos LayerBoxWindow
            var LayerBoxWindow = document.getElementById("lb_layerboxwindow");
            set_element_style(LayerBoxWindow,"left",(PageScrollPos[0] + (ClientWindowSize[0] - _this.box_width)/2)+"px");
            set_element_style(LayerBoxWindow,"top",(PageScrollPos[1] + (ClientWindowSize[1] - _this.box_height)/2)+"px"); 

           //pos LayerBoxContentWindow
            var LayerBoxContentWindow = document.getElementById("lb_layerboxcontentwindow");
            set_element_style(LayerBoxContentWindow,"left",(PageScrollPos[0] + (ClientWindowSize[0] - _this.box_width)/2)+"px");
            set_element_style(LayerBoxContentWindow,"top",(PageScrollPos[1] + (ClientWindowSize[1] - _this.box_height)/2)+"px");                      
          }
      } 

    /***************************************************************************
    * browse (browse url) 
    * @access public 
    * @param string url url to browse    
    */
      thisDSLayerBox.Browse = function(box_title,url) {
         //set important var 
          this.box_title = box_title;  
          var _this = this;
         //loading animation
          this.box_inner_text = "<img src='"+this.box_loadpic_src+"'>";
          this._change_content(_this);
         //init ajax request          
          var XMLHttp = false;
         //for Internet Explorer
          try {
            XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
          } 
          catch(e) {
            try {
              XMLHttp  = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e) {
              XMLHttp  = false;
            }
          }
         //for Mozilla, Opera, Safari 
          if (!XMLHttp && typeof XMLHttpRequest != 'undefined')
            XMLHttp = new XMLHttpRequest();
          XMLHttp.open("GET", url , true);       
          XMLHttp.onreadystatechange = function() {            
                                            switch(XMLHttp.readyState) {
                                              case 4:
                                                if (XMLHttp.status!=200)
                                                  _this.box_inner_text = "Fehler:"+XMLHttp.status;
                                                else    
                                                  _this.box_inner_text = "<div id='lb_layerboxcontentinnerwindow' style='height:"+(_this.box_height-68)+"px; width: "+(_this.box_width-30)+"px'>"+XMLHttp.responseText+"</div>";
                                                  thisDSLayerBox._change_content(_this);
                                                break;
                                              default:
                                                return false;
                                                break;     
                                            }                
                                        };
          XMLHttp.send(null);
      }
      
    /***************************************************************************
    * _change_content (change content of the box) 
    * @access private
    * @param pointer _this pointer to this class    
    */
      thisDSLayerBox._change_content = function(_this) {
         //change innerHTML 
          _this.obj.innerHTML = "<p align='center'><table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' width='"+_this.box_width+"'>"
                               +"<tr><td height='10'></td></tr>"
                               +"<tr><td height='14'><p align='center'>"+_this.box_title+"</p></td></tr>"
                               +"<tr><td height='10'></td></tr>"
                               +"<tr><td height='"+(_this.box_height-68)+"'><table border='0' align='center' cellpadding='0' cellspacing='0' style='border-collapse: collapse' height='100%'><tr><td>"+_this.box_inner_text+"</td></tr></table></td></tr>"
                               +"<tr><td height='10'></td></tr>"
                               +"<tr><td height='14'><p align='center'><a href='javascript:thisDSLayerBox.Hide()'>Schlie&szlig;en</a></p></td></tr>"
                               +"<tr><td height='10'></td></tr>"
                               +"</table></p>";                     
      }
    
    /***************************************************************************
    * Show (open viewer) 
    * @access public
    * @param string box_title title of of the layer
    * @param pointer obj pointer to the object which have to edit
    * @param string url url to browse      
    */
      thisDSLayerBox.Show = function(box_title,url) {
         //set important vars                 
          var _this = this;

         //override window-functions 
          window.onscroll = function() {    
                                thisDSLayerBox.pos_windows(_this);
                            }  
          window.onresize = function() {
                                thisDSLayerBox.pos_windows(_this);
                            }
 
         //get vars 
          var ClientWindowSize = get_clientwindowsize();
          var PageScrollPos = get_page_scrollpos();
          var PageSize = get_pagesize();
          
         //create OverlayWindow
          var OverlayWindow = document.createElement("div");
          OverlayWindow.setAttribute("id","lb_overlaywindow");
          
          set_element_style(OverlayWindow,"left","0px");
          set_element_style(OverlayWindow,"top","0px"); 
          set_element_style(OverlayWindow,"width",(ClientWindowSize[0] > PageSize[0]) ? ClientWindowSize[0]+"px" : (PageSize[0])+"px");  
          set_element_style(OverlayWindow,"height",(ClientWindowSize[1] > PageSize[1]) ? ClientWindowSize[1]+"px" : (PageSize[1])+"px");  
          
         //show layer (visibility is just for fix flickering) 
          set_element_style(OverlayWindow,"visibility","hidden");
          document.body.appendChild(OverlayWindow);
          set_element_style(OverlayWindow,"visibility","visible");
          fade_to_opacity('lb_overlaywindow',0,40,300); 
     
         //create LayerBoxWindow
          var LayerBoxWindow = document.createElement("div");
          LayerBoxWindow.setAttribute("id","lb_layerboxwindow");
          set_element_style(LayerBoxWindow,"left",(PageScrollPos[0] + (ClientWindowSize[0] - this.box_width)/2)+"px");
          set_element_style(LayerBoxWindow,"top",(PageScrollPos[1] + (ClientWindowSize[1] - this.box_height)/2)+"px"); 
          set_element_style(LayerBoxWindow,"width",this.box_width+"px");  
          set_element_style(LayerBoxWindow,"height",this.box_height+"px");
          
         //show layer (visibility is just for fix flickering)
          set_element_style(LayerBoxWindow,"visibility","hidden");
          document.body.appendChild(LayerBoxWindow);
          set_element_style(LayerBoxWindow,"visibility","visible");
          fade_to_opacity('lb_layerboxwindow',0,70,500);   

         //create LayerBoxContentWindow
          var LayerBoxContentWindow = document.createElement("div");
          LayerBoxContentWindow.setAttribute("id","lb_layerboxcontentwindow");
          set_element_style(LayerBoxContentWindow,"left",(PageScrollPos[0] + (ClientWindowSize[0] - this.box_width)/2)+"px");
          set_element_style(LayerBoxContentWindow,"top",(PageScrollPos[1] + (ClientWindowSize[1] - this.box_height)/2)+"px"); 
          set_element_style(LayerBoxContentWindow,"width",this.box_width+"px");  
          set_element_style(LayerBoxContentWindow,"height",this.box_height+"px");
          this.obj = LayerBoxContentWindow;
         
         //browse url  
          this.Browse(box_title,url); 
 
         //show layer (visibility is just for fix flickering)
          set_element_style(LayerBoxContentWindow,"visibility","hidden");
          document.body.appendChild(LayerBoxContentWindow);
          set_element_style(LayerBoxContentWindow,"visibility","visible");
          setTimeout("fade_to_opacity('lb_layerboxcontentwindow',0,100,50)",400);     
      }

      
    /***************************************************************************
    * Hide (close viewer)
    * @access public
    */
      thisDSLayerBox.Hide = function() {
         //fade out
          fade_to_opacity('lb_layerboxcontentwindow',100,0,50);   
          setTimeout("fade_to_opacity('lb_layerboxwindow',70,0,300)",100);   
          setTimeout("fade_to_opacity('lb_overlaywindow',40,0,300)",100);   

         //delete layer after fade 
          setTimeout("document.body.removeChild(document.getElementById('lb_overlaywindow'))",420);
          setTimeout("document.body.removeChild(document.getElementById('lb_layerboxwindow'))",420);
          setTimeout("document.body.removeChild(document.getElementById('lb_layerboxcontentwindow'))",420);

         //restore window-functions 
          window.onscroll = function() {    
                                window.onscroll= null;
                            }  
          window.onresize = function() {
                                window.onresize = null;
                            }
      }

////////////////////////////////////////////////////////////////////////////////
///                       DSLayerBox (DSLayerBox.js)                         ///
///                Copyright © 2007-2009 by Daniel Seichter                  ///                         
////////////////////////////////////////////////////////////////////////////////
