/**
 * @name glassbox
 * @overview  Javascript User Interface (UI) Library
 
 * @homepage <a href="http://www.glassbox-js.com">www.glassbox-js.com</a>
 * @status development 
 * @version 1.3.0
 * @last&nbsp;mod 2008/03/10

 * @supported<br/>browsers 
   Internet Explorer 6 higher <br/>
   Firefox 1.5 higher <br/>
   Opera 9.x higher <br/>
   Safari 2.x higher <br/>

 * @author Uli Preuss</a>
 * @copyright &copy; 2006-2008 <a href="http://www.glassbox-js.com">glassbox-js</a>
 
 * @licence The MIT License:
   <br/><br/>
   Permission is hereby granted, free of charge, to any person obtaining a copy 
   of this software and associated documentation files (the "Software"), to deal 
   in the Software without restriction, including without limitation the rights 
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
   copies of the Software, and to permit persons to whom the Software is 
   furnished to do so, subject to the following conditions:
   <br/><br/> 
   The above copyright notice and this permission notice shall be included in all 
   copies or substantial portions of the Software.
   <br/><br/> 
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
   SOFTWARE.
   <br/><br/>
*/

/* Configuration */
var path_to_glassbox = "_scripts/glassbox/";
var path_to_background_images = "images/backgrounds/";
/* End Configuration */

// You must define path to root directory in any html-pages outside the root directory
// Relative path (for example "../")
var path_to_root_dir = ""; // Default

if ( typeof(GlassBox) == 'undefined' ) {
  /** 
  * @constructor 
  * @desc GlassBox object
  * @example
  * var myBox = new GlassBox();
  */ 
  GlassBox = function() {
  
    THIS = this,
    /** 
    * @memberOf GlassBox
    * @desc GlassBox Version
    * @type string
    * @example
    * alert( myBox.version );
    */
    this.version = "1.3.0",
    this.version_comment = "Changed: double click event | Extended: ajax content loading",
    /** 
    * @memberOf GlassBox
    * @desc Date of last modification
    * @type string
    * @example
    * alert( myBox.last_mod );
    */
    this.last_mod = "2008/03/10",
  
    this.bb_hor = "25px",
    this.bb_ver = "21px",
    this.gb_path = path_to_root_dir + path_to_glassbox,
    this.img_bg_path = path_to_root_dir + path_to_background_images,
    this.skin_path =  path_to_root_dir + path_to_glassbox + "skins/",
    this.skin_default = "default",
    this.multicontent_arr = new Array(),
    this.exists = false,
    this.is_false = true,
    this.dblclick = true;
      
    /** 
    * @memberOf GlassBox
    * @desc Object Initialization 
    * @param {string} id Id of the XHTML element 
    * @param {string} width Width of the new GlassBox (use CSS property values)
    * @param {string} height Height of the new GlassBox (use CSS property values)
    * @param {string} overflow Overflow/Scrollbars (use CSS property values)
    * @param {string} skinname Name of the Border Style (default, white, ..)
    * @param {string} multicontent_num (optional) Number of XHTML element 
    * @example
    * myBox.init( 'myBox', '150px', '270px', 'hidden', 'white' );
    */
    this.init = function( id, width, height, overflow, skinname, resize, dblclick, multicontent_num ) {
      this.width = width;
      this.height = height;
      this.overflow = overflow;
     
      if( resize != null && resize != "" ) {
         if( resize == false ) this.resize = false;
         else if( resize == true ) this.resize = true;
	  }
      if( dblclick == false ) this.dblclick = false;
      else if( dblclick == true ) this.dblclick = true;
       
	  if( skinname != null && skinname != "" ) this.skinfolder = this.skin_path + skinname;
      else this.skinfolder = this.skin_path + this.skin_default;
           
	  if( this.exists == false ) {
        this.id = id;
        this.glassbox = document.getElementById( this.id );
    
        if( multicontent_num != null ) {
          if( this.is_false == true ) {
            var pageArray = new Array();
            var className = "glassbox_mc";
            var divs = document.getElementsByTagName("div");
            var pattern = new RegExp( "\\b" + className + "\\b" );
            for ( i = 0, j = 0; i < divs.length; i++ ) {
              if ( pattern.test( divs[i].className ) ) {
                pageArray[j] = divs[i];
                j++;
              }
            }
            this.header = "<h1>" + pageArray[0].getElementsByTagName( "h1" )[0].innerHTML + "</h1>";
            for( i=0;i< pageArray.length;i++ ) {
              this.multicontent_arr[i] = pageArray[i].innerHTML;
            }
            this.glassboxContent = this.multicontent_arr[0];
            this.is_false = false;
          }
          else {
            if( multicontent_num == 1 ) {
              this.glassboxContent = this.multicontent_arr[ multicontent_num-1 ];
            }
            else {
              this.glassboxContent = this.header + this.multicontent_arr[ multicontent_num-1 ];
            }
          }
        }
        else {
          if(typeof this.glassboxContent == "undefined") {
            this.glassboxContent = this.glassbox.innerHTML;
		  }
        }
        if(this.glassbox != null) {
          this.glassbox.innerHTML = "";
	    }
      }

      this.glassboxWidth = parseInt( this.width );
      this.boxborder_lr1 = parseInt( this.bb_hor );
      this.content_width = this.glassboxWidth - ( 2 * this.boxborder_lr1 ) + "px" ;

      this.glassboxHeight = parseInt( this.height );
      this.boxborder_tb1 = parseInt( this.bb_ver );
      this.content_height = this.glassboxHeight - ( 2 * this.boxborder_tb1 ) + "px" ;

      var sd = getScreenDimensions ();  
      this.screenWidth = sd.screenWidth;
      this.screenHeight = sd.screenHeight;      
    },
    
    /** 
    * @memberOf GlassBox
    * @desc Full vertical size (height)
    * @param {string} left Position left (use CSS property values) 
    * @param {string} margin Margin (use CSS property values)
    * @example
    * myBox.vscreen( '50px', '5px' );
    */
    this.vscreen = function( left, margin ){
      this.glassboxHeight = this.screenHeight - ( parseInt( margin ) * 2 );
      this.boxborder_tb1 = parseInt( this.bb_ver );
      this.content_height = this.glassboxHeight - ( 2 * this.boxborder_tb1 ) + "px" ;
      this.glassbox.style.position = "absolute";
      this.glassbox.style.left = left;
      this.glassbox.style.top = parseInt( margin ) + "px";    
      this.createGlassbox();
    },
    
    /** 
    * @memberOf GlassBox
    * @desc inline position
    * @example
    * myBox.ipos();
    */
    this.ipos = function(){
      this.createGlassbox();
    },
    
    /** 
    * @memberOf GlassBox
    * @desc Absolute position
    * @param {string} left Position left (use CSS property values) 
    * @param {string} top Position top (use CSS property values)
    * @example
    * myBox.apos( '690px', '35px' );
    */
    this.apos = function( left, top ){
      this.glassbox.style.position = "absolute";
      this.glassbox.style.left = left;
      this.glassbox.style.top = top;
      this.createGlassbox();
    },
    
    /** 
    * @memberOf GlassBox
    * @desc Display object as a lightbox (with overlay)
    * @param {bool} exitbut Display exit button
    * @param {string} opac (optional) Opacity (use CSS property values)
    * @example
    * myBox.lbo( true, 0.50 ); 
    */
    this.lbo = function( exitbut, opac ){
 	  var arrayPageScroll = document.viewport.getScrollOffsets();   
      if( this.exists != true ) {
        if( opac ) {
          this.overlay = document.createElement( "div" );
          this.overlay.setAttribute( "id", this.id + "_overlay" );
          this.overlay.style.position = "absolute";
          this.overlay.style.backgroundColor = "#000000";
          this.overlay.style.left = "0px";
          this.overlay.style.top = "0px";
          this.overlay.style.width = document.viewport.getWidth() + "px";
          this.overlay.style.height = document.viewport.getHeight() + "px";
          this.overlay.style.opacity = opac;
          this.overlay.style.filter = "alpha( opacity=" + opac * 100 + " )";
          this.overlay.style.zIndex = 999;
          this.overlay.style.display = "block";
          var htmlbody = document.getElementsByTagName( "body" )[0];
          htmlbody.appendChild( this.overlay );
        }
        if( exitbut != false ) {
          var exitButton = document.createElement( "div" );
          exitButton.setAttribute( "id","exitButton" );
          exitButton.style.position = "absolute";
          exitButton.style.left = this.glassboxWidth - 39 + "px";
          exitButton.style.top = 23 + "px";
          exitButton.style.zIndex = 1001;
          exitButton.title = "close";
          this.glassbox.appendChild( exitButton );
    
          var exitLink = document.createElement( "a" );
          exitLink.href = "javascript:THIS.fadeBox( '" + this.id + "' );";
          exitButton.appendChild( exitLink );
    
          var exitImage = document.createElement( "img" );
          exitImage.setAttribute( "id", "exitImage" );
          exitImage.style.border = 0;
          exitImage.src = this.skin_path + "exitButton.png";
          exitLink.appendChild( exitImage );
    
          try {
            new Effect.Appear( "exitButton" );
          }
          catch(e) {
            document.getElementById( "exitButton" ).style.display = "block";
          }
        }

        this.glassbox.style.position = "absolute";
        this.glassbox.style.left = Math.round( ( this.screenWidth - this.glassboxWidth ) / 2 ) + "px";
        this.glassbox.style.top = Math.round( ( this.screenHeight - this.glassboxHeight ) / 2 ) + "px";
        this.glassbox.style.zIndex = 1000;
        this.glassbox.style.minWidth = this.glassboxWidth + "px";
    
        this.createGlassbox();
        this.exists = true;
      }
      else {
        document.getElementById( this.id + "_overlay" ).style.display = "block";
      }
      this.appear();
    },
    
    /** 
    * @memberOf GlassBox
    * @desc Display object as a select box
    * @param {bool} exitbut Display exit button
    * @param {string} opac (optional) Opacity (use CSS property values)
    * @param {string} left Position left (use CSS property values) 
    * @param {string} top Position top (use CSS property values)
	* @example
    * myBox.sbo( true, 0.50, '690px', '35px' ); 
    */
    this.sbo = function( exitbut, opac, left, top ){
      if( this.exists != true ) {
		if( opac ) {
          this.overlay = document.createElement( "div" );
          this.overlay.setAttribute( "id", this.id + "_overlay" );
          this.overlay.style.position = "absolute";
          this.overlay.style.backgroundColor = "#000000";
          this.overlay.style.left = "0px";
          this.overlay.style.top = "0px";
          this.overlay.style.width = document.viewport.getWidth() + "px";
          this.overlay.style.height = document.viewport.getHeight() + "px";
          this.overlay.style.opacity = opac;
          this.overlay.style.filter = "alpha( opacity=" + opac * 100 + " )";
          this.overlay.style.zIndex = 999;
          this.overlay.style.display = "block";
          var htmlbody = document.getElementsByTagName( "body" )[0];
          htmlbody.appendChild( this.overlay );
        }
		if( exitbut != false ) {
          var exitButton = document.createElement( "div" );
          exitButton.setAttribute( "id","exitButton" );
          exitButton.style.position = "absolute";
          exitButton.style.left = this.glassboxWidth - 39 + "px";
          exitButton.style.top = 4 + "px";
          exitButton.style.zIndex = 1001;
		  exitButton.title = "close";
          this.glassbox.appendChild( exitButton );

          var exitLink = document.createElement( "a" );
          exitLink.href = "javascript:THIS.hideBox( '" + this.id + "' );";
          exitButton.appendChild( exitLink );
		  
		  if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
			var exitImage = document.createElement( "span" );
			exitImage.setAttribute( "id", "exitImage" );
			exitImage.style.border  = 0;
			exitImage.style.width   = "30px";
			exitImage.style.height  = "30px";
			exitImage.style.display = "inline-block";
			exitImage.style.cursor  = "hand";
		    exitImage.style.filter  = this.iepngfix(this.skin_path + "exitButton.png");
		  
		  } else {
			var exitImage = document.createElement( "img" );
			exitImage.setAttribute( "id", "exitImage" );
			exitImage.style.border = 0;
			exitImage.src = this.skin_path + "exitButton.png";
			exitImage.style.width = "30px";
			exitImage.style.height = "30px";
		  }
		  
		  exitLink.appendChild( exitImage );
		  
          try {
          	new Effect.Appear( "exitButton" );
          }
          catch(e) {
          	document.getElementById( "exitButton" ).style.display = "block";
          }
		
		} else {
          var exitButton = document.getElementById( "exitButton" );
          if(exitButton != undefined) Element.remove($('exitButton'));
		}   

		this.glassbox.style.position = "absolute";

		this.glassbox.style.zIndex = 1000;
		this.glassbox.style.minWidth = this.glassboxWidth + "px";

		this.createGlassbox();
		this.exists = true;
     
      } else {
      	this.resizeGlassbox();
      	
      	if( opac ) document.getElementById( this.id + "_overlay" ).style.display = "block";
		if( exitbut != false ) {
          var exitButton = document.getElementById( "exitButton" );
          if(exitButton == undefined) {
	          var exitButton = document.createElement( "div" );
	          exitButton.setAttribute( "id","exitButton" );
	          exitButton.style.position = "absolute";
	          exitButton.style.left = this.glassboxWidth - 39 + "px";
	          exitButton.style.top = 4 + "px";
	          exitButton.style.zIndex = 1001;
			  exitButton.title = "close";
	          this.glassbox.appendChild( exitButton );
	
	          var exitLink = document.createElement( "a" );
	          exitLink.href = "javascript:THIS.hideBox( '" + this.id + "' );";
	          exitButton.appendChild( exitLink );
			  
			  if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
				var exitImage = document.createElement( "span" );
				exitImage.setAttribute( "id", "exitImage" );
				exitImage.style.border  = 0;
				exitImage.style.width   = "30px";
				exitImage.style.height  = "30px";
				exitImage.style.display = "inline-block";
				exitImage.style.cursor  = "hand";
			    exitImage.style.filter  = this.iepngfix(this.skin_path + "exitButton.png");
			  
			  } else {
				var exitImage = document.createElement( "img" );
				exitImage.setAttribute( "id", "exitImage" );
				exitImage.style.border = 0;
				exitImage.src = this.skin_path + "exitButton.png";
				exitImage.style.width = "30px";
				exitImage.style.height = "30px";
			  }
			  
			  exitLink.appendChild( exitImage );
			  
	          try {
	          	new Effect.Appear( "exitButton" );
	          }
	          catch(e) {
	          	document.getElementById( "exitButton" ).style.display = "block";
	          }	   
	             
	      } else {
	          exitButton.style.left = this.glassboxWidth - 39 + "px";
			  
	          try {
	          	new Effect.Appear( "exitButton" );
	          }
	          catch(e) {
	          	document.getElementById( "exitButton" ).style.display = "block";
	          }
          }
          
		} else {
          var exitButton = document.getElementById( "exitButton" );
          if(exitButton != undefined) Element.remove($('exitButton'));
		}       	
      }
      
	  var arrayPageScroll = document.viewport.getScrollOffsets();   
	  
	  if(left != undefined) this.glassbox.style.left = left;
	  else this.glassbox.style.left = Math.round( ( this.screenWidth - this.glassboxWidth ) / 2 ) + "px";
	  
	  if(top != undefined) this.glassbox.style.top = top;
	  else this.glassbox.style.top = Math.round( arrayPageScroll[1] + ((document.viewport.getHeight() - this.glassboxHeight) / 2) ) + "px"; 

	  new Element.show(this.id);
    },
    /** 
    * @private 
    */
    this.getPageSize = function() {
	    var xScroll, yScroll, windowWidth, windowHeight;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			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;
		}

		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth) windowWidth = document.documentElement.clientWidth; 
			else 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 = xScroll;		
		else pageWidth = windowWidth;

		return [pageWidth,pageHeight,windowWidth,windowHeight];
	}
	
    this.createGlassbox = function(){
  
      var toprow = document.createElement( "div" );
      toprow.setAttribute( "id","toprow" );
      toprow.style.width = this.glassboxWidth;
      toprow.style.minWidth = this.glassboxWidth + "px";
      this.glassbox.appendChild( toprow );

      var topleft = document.createElement( "div" );
      topleft.setAttribute( "id","topleft" );
      topleft.style.width = this.bb_hor;
      topleft.style.height = this.bb_ver;
      topleft.style.cssFloat = "left";
      topleft.style.styleFloat = "left";
      topleft.style.backgroundImage = "url( " + this.skinfolder + "/topleft.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        topleft.style.filter = this.iepngfix(this.skinfolder + "/topleft.png");
        topleft.style.backgroundImage = "none";
      }
      toprow.appendChild( topleft );
    
      var topmiddle = document.createElement( "div" );
      topmiddle.setAttribute( "id","topmiddle" );
      topmiddle.style.width = this.content_width;
      topmiddle.style.height = this.bb_ver;
      topmiddle.style.cssFloat = "left";
      topmiddle.style.styleFloat = "left";
      topmiddle.style.backgroundImage = "url( " + this.skinfolder + "/top.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        topmiddle.style.filter = this.iepngfix(this.skinfolder + "/top.png");
        topmiddle.style.backgroundImage = "none";
      }
      toprow.appendChild( topmiddle );
    
      var topright = document.createElement( "div" );
      topright.setAttribute( "id", "topright" );
      topright.style.width = this.bb_hor;
      topright.style.height = this.bb_ver;
      topright.style.cssFloat = "left";
      topright.style.styleFloat = "left";
      topright.style.backgroundImage = "url( " + this.skinfolder + "/topright.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        topright.style.filter = this.iepngfix(this.skinfolder + "/topright.png");
        topright.style.backgroundImage = "none";
      }
      toprow.appendChild( topright );
      
      var clear = document.createElement( "div" );
      clear.style.clear = "both";
      this.glassbox.appendChild( clear );
    
      var middlerow = document.createElement( "div" );
      middlerow.setAttribute( "id","middlerow" );
      middlerow.style.width = this.glassboxWidth;
      this.glassbox.appendChild( middlerow );

      var middleleft = document.createElement( "div" );
      middleleft.setAttribute( "id", "middleleft" );
      middleleft.style.width = this.bb_hor;
      middleleft.style.height = this.content_height;
      middleleft.style.cssFloat = "left";
      middleleft.style.styleFloat = "left";
      middleleft.style.backgroundImage = "url( " + this.skinfolder + "/left.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        middleleft.style.filter = this.iepngfix(this.skinfolder + "/left.png");
        middleleft.style.backgroundImage = "none";
      }
      middlerow.appendChild( middleleft );
    
      // Content
    
      var contentBox = document.createElement( "div" );
      contentBox.setAttribute( "id", "contentBox" );
      contentBox.style.width = this.content_width;
      contentBox.style.height = this.content_height;
      contentBox.style.cssFloat = "left";
      contentBox.style.styleFloat = "left";
      middlerow.appendChild( contentBox );
    
      var contentBoxBg = document.createElement( "div" );
      contentBoxBg.setAttribute( "id", "contentBoxBg" );
      contentBoxBg.style.width = "100%";
      contentBoxBg.style.height = "100%";
      contentBoxBg.style.overflow = this.overflow;
      contentBoxBg.style.backgroundColor = "#000000";
      contentBox.appendChild( contentBoxBg );
      this.contentBoxBg = contentBoxBg;    
    
      var content = document.createElement( "div" );
      content.setAttribute( "id", "content" );
      content.innerHTML = this.glassboxContent;
      contentBoxBg.appendChild( content );
      this.content = content;    
      
      // End Content
    
      var middleright = document.createElement( "div" );
      middleright.setAttribute( "id", "middleright" );
      middleright.style.width = this.bb_hor;
      middleright.style.height = this.content_height;
      middleright.style.cssFloat = "left";
      middleright.style.styleFloat = "left";
      middleright.setAttribute( "class", "boxmiddle" );
      middleright.style.backgroundImage = "url( " + this.skinfolder + "/right.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        middleright.style.filter = this.iepngfix(this.skinfolder + "/right.png");
        middleright.style.backgroundImage = "none";
      }
      middlerow.appendChild( middleright );
    
      var clear = document.createElement( "div" );
      clear.style.clear = "both";
      this.glassbox.appendChild( clear );
    
      var bottomrow = document.createElement( "div" );
      bottomrow.setAttribute( "id","bottomrow" );
      bottomrow.style.width = this.glassboxWidth;
      this.glassbox.appendChild( bottomrow );

      var bottomleft = document.createElement( "div" );
      bottomleft.setAttribute( "id", "bottomleft" );
      bottomleft.style.width = this.bb_hor;
      bottomleft.style.height = this.bb_ver;
      bottomleft.style.cssFloat = "left";
      bottomleft.style.styleFloat = "left";
      bottomleft.style.backgroundImage = "url( " + this.skinfolder + "/bottomleft.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        bottomleft.style.filter = this.iepngfix(this.skinfolder + "/bottomleft.png");
        bottomleft.style.backgroundImage = "none";
      }
      bottomrow.appendChild( bottomleft );
      
      var bottom = document.createElement( "div" );
      bottom.setAttribute( "id", "bottom" );
      bottom.style.width = this.content_width;
      bottom.style.height = this.bb_ver;
      bottom.style.cssFloat = "left";
      bottom.style.styleFloat = "left";
      bottom.style.backgroundImage = "url( " + this.skinfolder + "/bottom.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        bottom.style.filter = this.iepngfix(this.skinfolder + "/bottom.png");
        bottom.style.backgroundImage = "none";
      }
      bottomrow.appendChild( bottom );
    
      var bottomright = document.createElement( "div" );
      bottomright.setAttribute( "id", "bottomright" );
      bottomright.style.width = this.bb_hor;
      bottomright.style.height = this.bb_ver;
      bottomright.style.cssFloat = "left";
      bottomright.style.styleFloat = "left";
      bottomright.style.backgroundImage = "url( " + this.skinfolder + "/bottomright.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        bottomright.style.filter = this.iepngfix(this.skinfolder + "/bottomright.png");
        bottomright.style.backgroundImage = "none";
      }
      bottomrow.appendChild( bottomright );
    
      var clear = document.createElement( "div" );
      clear.style.clear = "both";
      this.glassbox.appendChild( clear );      
    },
    /** 
    * @private 
    */
    this.resizeGlassbox = function(){
  	  
      var toprow = document.getElementById( "toprow" );
      toprow.style.width = this.glassboxWidth;
      toprow.style.minWidth = this.glassboxWidth + "px";
        	  
      var topleft = document.getElementById( "topleft" );
      topleft.style.width = this.bb_hor;
      topleft.style.height = this.bb_ver;
      topleft.style.cssFloat = "left";
      topleft.style.styleFloat = "left";
      topleft.style.backgroundImage = "url( " + this.skinfolder + "/topleft.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        topleft.style.filter = this.iepngfix(this.skinfolder + "/topleft.png");
        topleft.style.backgroundImage = "none";
      }
    
      var topmiddle = document.getElementById( "topmiddle" );
      topmiddle.style.width = this.content_width;
      topmiddle.style.height = this.bb_ver;
      topmiddle.style.cssFloat = "left";
      topmiddle.style.styleFloat = "left";
      topmiddle.style.backgroundImage = "url( " + this.skinfolder + "/top.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        topmiddle.style.filter = this.iepngfix(this.skinfolder + "/top.png");
        topmiddle.style.backgroundImage = "none";
      }
    
      var topright = document.getElementById( "topright" );
      topright.setAttribute( "id", "topright" );
      topright.style.width = this.bb_hor;
      topright.style.height = this.bb_ver;
      topright.style.cssFloat = "left";
      topright.style.styleFloat = "left";
      topright.style.backgroundImage = "url( " + this.skinfolder + "/topright.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        topright.style.filter = this.iepngfix(this.skinfolder + "/topright.png");
        topright.style.backgroundImage = "none";
      }

      var middlerow = document.getElementById( "middlerow" );
      middlerow.style.width = this.glassboxWidth;

      var middleleft = document.getElementById( "middleleft" );
      middleleft.style.width = this.bb_hor;
      middleleft.style.height = this.content_height;
      middleleft.style.cssFloat = "left";
      middleleft.style.styleFloat = "left";
      middleleft.style.backgroundImage = "url( " + this.skinfolder + "/left.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        middleleft.style.filter = this.iepngfix(this.skinfolder + "/left.png");
        middleleft.style.backgroundImage = "none";
      }
    
      // Content
    
      var contentBox = document.getElementById( "contentBox" );
      contentBox.style.width = this.content_width;
      contentBox.style.height = this.content_height;
      contentBox.style.cssFloat = "left";
      contentBox.style.styleFloat = "left";

      // End Content
    
      var middleright = document.getElementById( "middleright" );
      middleright.style.width = this.bb_hor;
      middleright.style.height = this.content_height;
      middleright.style.cssFloat = "left";
      middleright.style.styleFloat = "left";
      middleright.setAttribute( "class", "boxmiddle" );
      middleright.style.backgroundImage = "url( " + this.skinfolder + "/right.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        middleright.style.filter = this.iepngfix(this.skinfolder + "/right.png");
        middleright.style.backgroundImage = "none";
      }

      var bottomrow = document.getElementById( "bottomrow" );
      bottomrow.style.width = this.glassboxWidth;

      var bottomleft = document.getElementById( "bottomleft" );
      bottomleft.style.width = this.bb_hor;
      bottomleft.style.height = this.bb_ver;
      bottomleft.style.cssFloat = "left";
      bottomleft.style.styleFloat = "left";
      bottomleft.style.backgroundImage = "url( " + this.skinfolder + "/bottomleft.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        bottomleft.style.filter = this.iepngfix(this.skinfolder + "/bottomleft.png");
        bottomleft.style.backgroundImage = "none";
      }
      
      var bottom = document.getElementById( "bottom" );
      bottom.style.width = this.content_width;
      bottom.style.height = this.bb_ver;
      bottom.style.cssFloat = "left";
      bottom.style.styleFloat = "left";
      bottom.style.backgroundImage = "url( " + this.skinfolder + "/bottom.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        bottom.style.filter = this.iepngfix(this.skinfolder + "/bottom.png");
        bottom.style.backgroundImage = "none";
      }
    
      var bottomright = document.getElementById( "bottomright" );
      bottomright.style.width = this.bb_hor;
      bottomright.style.height = this.bb_ver;
      bottomright.style.cssFloat = "left";
      bottomright.style.styleFloat = "left";
      bottomright.style.backgroundImage = "url( " + this.skinfolder + "/bottomright.png )";
      if ( /MSIE (5\.5|6\.)/.test( navigator.userAgent )){ 
        bottomright.style.filter = this.iepngfix(this.skinfolder + "/bottomright.png");
        bottomright.style.backgroundImage = "none";
      }
    },
    
    /** 
    * @memberOf GlassBox
    * @desc Effect.Appear
    * @param {number} ms (optional) Only for a period of time (in milliseconds)
    * @example
    * myBox.appear(3000);
    */
    this.appear = function( ms ){
      try {
        this.glassbox.style.display = "none";
        new Effect.Appear( this.id );
      }
      catch(e) {
        this.glassbox.style.display = "block";
      }
      /** 
      * @private 
      */
      this.glassbox.ondblclick = function () {
		  //alert('dblclick');
        if(THIS.dblclick == true) THIS.fadeBox( this.id );
      };
      if( ms ) {
        setTimeout( "THIS.fadeBox( '" + this.id + "' )", ms );
      }
    },
  
    /** 
    * @memberOf GlassBox
    * @desc Draggable Object
    * @example
    * myBox.draggable();
    */
    this.draggable = function(){
      try { // .. if Scriptaculous library is included
        new Draggable( this.id );
        this.glassbox.title = "You can drag me!";
      }
      catch(e) {}
    },
    /** 
    * @private 
    */
    this.backgroundImage = function( num ){
      try { // ..find and load background image
        var htmlbody = document.getElementsByTagName( "body" )[0];
        htmlbody.style.background ="url( " + this.img_bg_path + "bg" + num +".jpg )";
      }
      catch(e) {}
    },
  
    /** 
    * @memberOf GlassBox
    * @desc Sets the z-index of the object
    * @param {string} zindex Only for a period of time (in milliseconds)
    * @example
    * myBox.zindex('100');
    */
    this.zindex = function( zindex ){
      this.glassbox.style.zIndex = zindex;
    },
    /** 
    * @private 
    */
    this.noro = function( rightmargin ){ //no right overflow
      if( rightmargin == null ) rightmargin = 0;
      var leftMarginScreen = this.screenWidth - ( parseInt( this.glassbox.style.left) + parseInt( this.glassboxWidth ) );
      if( leftMarginScreen < 0 ) {
        this.glassbox.style.left = ( parseInt( this.glassbox.style.left ) + leftMarginScreen + rightmargin + 14 ) + "px";
      }
    },
    /** 
    * @private 
    */
    this.fadeBox = function( id ){
      try { // .. if Scriptaculous library is included
        new Effect.Fade( id );
        if(document.getElementById( id + "_overlay" )) {
          new Effect.Fade( id + "_overlay" );
        }
      }
      catch(e) {
        document.getElementById( id ).style.display = "none";
        if(document.getElementById( id + "_overlay" )) {
          document.getElementById( id + "_overlay" ).style.display = "none";
        }
      }
    },
    this.hideBox = function( id ){
      try { // .. if Scriptaculous library is included
        new Element.hide( id );
        if(document.getElementById( id + "_overlay" )) {
          new Effect.hide( id + "_overlay" );
        }
      }
      catch(e) {
        document.getElementById( id ).style.display = "none";
        if(document.getElementById( id + "_overlay" )) {
          document.getElementById( id + "_overlay" ).style.display = "none";
        }
      }
    },	
    /** 
    * @private 
    */
    this.iepngfix = function( bgimg ) {
      return 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + bgimg + '", sizingMethod="scale")';
    },
    /** 
    * @private 
    */
    window.onresize = function () {
      if(THIS.resize == true) {
        var sd = getScreenDimensions ();  
        THIS.glassbox.style.left = Math.round( ( sd.screenWidth - THIS.glassboxWidth ) / 2 ) + "px";
        THIS.glassbox.style.top = Math.round( ( sd.screenHeight - THIS.glassboxHeight ) / 2 ) + "px";  
        if(THIS.overlay != undefined){
          THIS.overlay.style.width = document.viewport.getWidth() + "px";
          THIS.overlay.style.height = document.viewport.getHeight() + "px";
        }
	  }
    }
  }
}

/** 
* @private 
*/
function GETrequest( url, target_id, callback_id ) {
  try {
    req = window.XMLHttpRequest ? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
  } 
  catch (e) { /* No AJAX Support */ }
  req.onreadystatechange = function () {
	if ((req.readyState == 4) && (req.status == 200)) {
	 if(target_id && document.getElementById( target_id )) document.getElementById( target_id ).innerHTML = req.responseText;
	 if(callback_id) GETrequest_callbackHandler(callback_id);
    }  
  }
  req.open( 'GET', url );
  req.send( null ); 
}

/** 
* @private 
*/
function getScreenDimensions (){
  if (window.innerHeight) {
    screenWidth = window.innerWidth;
    screenHeight = window.innerHeight;
  } 
  else if ( document.documentElement.clientHeight ) {
    screenWidth = document.documentElement.clientWidth;
    screenHeight = document.documentElement.clientHeight;
  }
  else if ( document.body.clientHeight ) {
    screenWidth = document.body.clientWidth;
    screenHeight = document.body.clientHeight;
  }
  return {
    "screenWidth": screenWidth, 
    "screenHeight": screenHeight 
  }
}

