function DivPopup() 
{
  
  var obj = new Object();

  
  obj.initialize = function () {
    
		if (!document.body.getElementsByTagName){ return; }
		var anchors = document.body.getElementsByTagName('a');
    var frame_href = new Array();
		// loop through all anchor tags
		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('popup'))){	
                
        anchor.onclick = function () {            

          pageSize  = obj.getPageSize();
          document.getElementById('overlay').style.height   = pageSize[1] + 'px';
          document.getElementById('overlay').style.display  = '';
          pageScroll = obj.getPageScroll();

          var h = parseInt(pageScroll[1])+parseInt(pageSize[3])/15;
          if ( h + 600 > parseInt(pageSize[1]) )
            h = parseInt(pageSize[1]) - 600 - 5;

          //document.getElementById('popup_content_main').style.top = (parseInt(pageScroll[1])+parseInt(pageSize[3])/15)+'px';
          document.getElementById('popup_content_main').style.top     = h+'px';
          document.getElementById('popup_content_main').style.display = '';
          document.getElementById('popup_content').style.display      = '';
          document.getElementById('popup_content').innerHTML          = '<div id="btn_close"><a href="javascript:;" onclick="popup.remove();return false;" title="zamknij"><img src="pics/zamknij.gif" alt="" title="zamknij okno" border="0" /></a></div>';
           
          var objIFrame = document.createElement("iframe");
      		
          objIFrame.setAttribute('id','popup_frame');
      		
          objIFrame.setAttribute('src', this.getAttribute('href'));
      		
          objIFrame.setAttribute('width',  560);
          objIFrame.setAttribute('height', 600);      		
      		objIFrame.setAttribute('frameborder','0');
          
          objOuterImageContainer  = document.getElementById('popup_content');
          objOuterImageContainer.appendChild(objIFrame);      

          return false;
        }
			}
			
		}
		
		var objBody = document.getElementsByTagName("body").item(0);
		
		
		if (!document.getElementById('overlay')) {
		
  		var objOverlay = document.createElement("div");
  		objOverlay.setAttribute('id','overlay');
  		objOverlay.style.display  = 'none';
  		objOverlay.style.filter   = 'alpha(opacity=40)';
  		objOverlay.style.opacity  = '0.4';
  		
  		objBody.appendChild(objOverlay);
  	
  		var objLightbox = document.createElement("div");
  		objLightbox.setAttribute('id','popup_content_main');
  		objLightbox.setAttribute('class','popup_content_main');
  		objLightbox.style.display = 'none';
      objBody.appendChild(objLightbox);
  	
  		var objOuterImageContainer = document.createElement("div");
  		objOuterImageContainer.setAttribute('id','popup_content');
  		objOuterImageContainer.setAttribute('class','popup_content');
  		objLightbox.appendChild(objOuterImageContainer);
    }      
    
    
  };
  
  // getPageSize()
  obj.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;
  	}
  
  
  	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
  	return arrayPageSize;
  };

  obj.getPageScroll = function () {

  	var yScroll;
  
  	if (self.pageYOffset) {
  		yScroll = self.pageYOffset;
  	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
  		yScroll = document.documentElement.scrollTop;
  	} else if (document.body) {// all other Explorers
  		yScroll = document.body.scrollTop;
  	}
  
  	arrayPageScroll = new Array('',yScroll) 
  	return arrayPageScroll;
  };
  
  obj.remove  = function() {
    
    document.getElementById('popup_content').style.display='none';
    document.getElementById('popup_content_main').style.display='none';
    document.getElementById('overlay').style.display='none';
    document.getElementById('popup_content').innerHTML = '';
  
  };
  
  
  obj.getOpacity = function(element){  
    var opacity;
      
    if (opacity = element.style.opacity) {  
      return parseFloat(opacity);  
    }
    
    if (opacity = (element.style.filter || '').match(/alpha\(opacity=(.*)\)/))  
      if(opacity[1]) return parseFloat(opacity[1]) / 100;  
    return 1.0;  
  };


  obj.setOpacity = function(element, value){  
  
    if (value == 1){
      element.style.opacity = (/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 0.999999 : null;
      
      if(/MSIE/.test(navigator.userAgent))  
        element.style.filter  = element.style.filter.replace(/alpha\([^\)]*\)/gi,'');  
      
    } else {  
      if(value < 0.00001) value = 0;  
      element.style.opacity = value;
      if(/MSIE/.test(navigator.userAgent))  
       element.style.filter = element.style.filter.replace(/alpha\([^\)]*\)/gi,'') + 'alpha(opacity='+value*100+')';  
    }   
  };
  
  obj.appear  = function(element, value, duration) {
    
    valueTmp = 0
    
    for (i = 0; i < duration; i++) {
      valueTmp += value/duration;
 
      obj.setOpacity(element, valueTmp);
      
    }
   
  };
  
  
  return obj;
}

function initPopup(inst) 
{
   
  popup = new DivPopup(inst);
  
  return popup;

}
