function initOverlay(product) {
	var objBody = document.getElementById('container');//document.getElementsByTagName("body")[0];
	
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.onclick = function () {hideGallery(); return false;}
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '100%';
	

	ifr = document.createElement('iframe');
	ifr.id = "galleryIfr";
	ifr.frameBorder = "0";
	ifr.style.width='100%';
	ifr.setAttribute('allowtransparency',true);


	var objZoom = document.createElement("div");
	objZoom.setAttribute('id','photoLayer');
	objZoom.style.display = 'none';	
	objZoom.innerHTML = '<span class="photoLayerClose" onclick="hideGallery();">Zamknij okno</span><h2>'+product+'</h2><div id="photoLayerFlash"></div></div>';

	document.getElementsByTagName("body")[0].insertBefore(objOverlay, document.getElementsByTagName("body")[0].firstChild); 
	document.getElementsByTagName("body")[0].insertBefore(objZoom, document.getElementsByTagName("body")[0].firstChild);
	objBody.insertBefore(ifr, objBody.firstChild);	
}

function getPageSize(){

	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;
}

function callExternalInterface(nr) {
      try{
    	  if (navigator.appName.indexOf("Microsoft") != -1) {
               window["promoflash"].callFlash(nr);
           }
           else {
               document["promoflash"].callFlash(nr);
           }
       }catch(err){}
}

function showGallery(picnr) {
	
	document.getElementById("photoLayer").style.top="260px";
	callExternalInterface(picnr);
	var objOverlay = document.getElementById('overlay');		
	var objZoom = document.getElementById('photoLayer');				
	var arrayPageSize = getPageSize();
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	
	
	objOverlay.style.display = 'block';
	height = (navigator.appName.indexOf("Netscape") != -1) ? pageYOffset + (innerHeight/2) - 280 : document.body.scrollTop + (document.body.clientHeight/2) - 280;
	objZoom.style.top = height;
	objZoom.style.left = (arrayPageSize[0] - 720)/2;
	document.getElementById('galleryIfr').style.top=0;
	document.getElementById('galleryIfr').style.paddingTop = height;	
	document.getElementById('galleryIfr').style.left = '0';//(arrayPageSize[0] - 720)/2;	
	if (window.event)
		document.getElementById('galleryIfr').style.display = 'block';	
	callExternalInterface(picnr);
	
	
}

function hideGallery() {
	var objOverlay = document.getElementById('overlay');	
	objOverlay.style.height='0px';
	objOverlay.style.display='none';
	document.getElementById('photoLayer').style.top="-10000px";
	if (window.event)	
		document.getElementById('galleryIfr').style.display = 'none';	
}