 
 var PageBox = {

    loadingIcon: 'graphics/loading.gif',
    closeIcon: 'graphics/close.gif',
    fullScreenClose: false,

	  initialize: function() {
	  	  
      if (!document.getElementsByTagName){ return; }
		  var anchors = document.getElementsByTagName('a');

      for (var i=0; i<anchors.length; i++){
	  	  var anchor = anchors[i];
			  var relAttribute = String(anchor.getAttribute('rel'));	
			  if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('pagebox'))){
				  anchor.onclick = function () {PageBox.start(this); return false;}
			  }
		  }
	  
	    window.onscroll = this.position;

	  
		  //Build Preview Box
		  
		  var objBody = document.getElementsByTagName("body").item(0);
		  var objOverlay = document.createElement("div");
		  objOverlay.setAttribute('id','overlay');
		  objOverlay.style.display = 'none';
		  objOverlay.parent=this;
		  
		  if (this.fullScreenClose) { 
		    objOverlay.onclick=function() {this.parent.close(); return false; }
		  }
		  
		  objBody.appendChild(objOverlay);
		  
		  var objLightBox = document.createElement("div");
		  objLightBox.setAttribute('id','lightbox');
		  objOverlay.appendChild(objLightBox);
		  
		  if (!this.fullScreenClose) {  
		    var objClose = document.createElement("img");
		    objClose.src = this.closeIcon;
		    objClose.className='CloseIcon';
		    objClose.parent = this;
		    objClose.onclick = function () {this.parent.close(); return false;}
		    objLightBox.appendChild(objClose);
		  }
		  
		  var objLoadingImage = document.createElement("img");
		  objLoadingImage.src = this.loadingIcon;
		  objLoadingImage.setAttribute('id','imgloading');
		  objLightBox.appendChild(objLoadingImage);
		  
		  var objPageDataContainer = document.createElement("div");
		  objPageDataContainer.setAttribute('id','pageDataContainer');
		  objLightBox.appendChild(objPageDataContainer);
		  
		  
		  //  <div id="overlay">
      //    <div id="lightbox">
      //      <img src="loadingicon.gif" id="imgloading>
      //      <div id="pageDataContainer"></div>
      //    </div>
      //  </div>
      
      Http.initialize();
		  
		},
		
		start: function(pageLink) {			  
		  if (!document.getElementsByTagName){ return; }
    
		  if((pageLink.getAttribute('rel') == 'pagebox')){
		    var arrayPageSize = Page.getPageSize();
		    
		    var overlay = document.getElementById('overlay');
		    overlay.style.height=arrayPageSize[1]+'px';
		    overlay.style.width=arrayPageSize[0]+'px';
		    overlay.style.display='block';
		    
		    Elements.hide('pageDataContainer');
		    Elements.show('imgloading');

        Http.getPage(pageLink.getAttribute('href'), this.handleResponse);
 		    			  
			  this.position();
		  }
	  },
	  
	  handleResponse: function(htmltext) {
	    Elements.show('pageDataContainer');
			Elements.hide('imgloading');
			var obj = document.getElementById('pageDataContainer')
      obj.innerHTML = htmltext
	  },
	  
	  close: function() {
	    Elements.hide('overlay');
	  },
	  
	  position: function() {
	    var arrayScroll = Page.getPageScroll();
	    var arrayPageSize = Page.getPageSize();
	    
	    var lightbox = document.getElementById('lightbox');
	    lightbox.style.left=((arrayPageSize[2]/2)+arrayScroll[0])-(lightbox.offsetWidth/2) +'px';
		  lightbox.style.top=((arrayPageSize[3]/2)+arrayScroll[1])-(lightbox.offsetHeight/2) +'px';
		  
	  }

  }
 
