//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	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;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
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 showBox()
  { 
    var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
	var objBody = document.getElementsByTagName("body").item(0);
    
    var layer = document.createElement('div');
    layer.style.zIndex = '90';
    layer.id = 'layer';
    layer.style.position = 'absolute';
    layer.style.top = '0px';
    layer.style.left = '0px';
    /*if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    layer.style.width = window.innerWidth + 'px';
    layer.style.height = window.innerHeight + 'px';
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    layer.style.width = document.documentElement.clientWidth + 'px';
    layer.style.height = document.documentElement.clientHeight + 'px';
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    layer.style.width = document.body.clientWidth + 'px';
    layer.style.height = document.body.clientHeight + 'px';
  }*/
 	layer.style.height = (document.body.clientHeight)*1.1 + 'px';
    layer.style.width = width + 'px';
   	//layer.style.height = '100%';
   	//layer.style.width = '100%';
    layer.style.backgroundColor = 'black';
    layer.style.opacity = '.8';
    layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=80)");
    layer.onclick=function () { 
    	document.body.removeChild(document.getElementById('layer'));
      	document.body.removeChild(document.getElementById('box'));
    }
    objBody.insertBefore(layer, objBody.firstChild);

var parrentDiv = document.createElement ('div');
parrentDiv.style.zIndex = '100';
parrentDiv.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
parrentDiv.setAttribute('id','box');
parrentDiv.style.top = '105px';
//parrentDiv.style.left = (width / 2) - (660 / 2) + 12 + 'px'; 
parrentDiv.style.left = (width / 2) - (1000 / 2) + 'px'; 
parrentDiv.style.height = 'auto';
parrentDiv.style.width = 'auto';
parrentDiv.style.border = '1px solid white';
parrentDiv.style.position = 'absolute';
objBody.insertBefore(parrentDiv, layer.nextSibling);


    var div = document.createElement('div');
    div.style.height = 'auto';
    div.style.width = 'auto';
    div.style.backgroundColor = 'white';
    div.style.border = '10px solid silver';
    parrentDiv.appendChild(div);

var imageDiv = document.createElement('div');
imageDiv.setAttribute('id','image');
div.appendChild(imageDiv);

/****** link-ul catre pagina de stoc, cu poza pe ea*******/
var myLink = document.createElement('a');
 //myLink.setAttribute('href','rabla.jsp');
 myLink.setAttribute('href','opel.jsp?id=opel-astra-new-generation');
 imageDiv.appendChild(myLink);
 
 	var objImage = document.createElement('img');
	objImage.setAttribute('id','lightboxImage');
	/*
	objImage.setAttribute('src','library/images/home/rabla_2010.jpg');
	objImage.setAttribute('title','Rabla 2010');
	objImage.style.height = '506px';
	objImage.style.width = '640px';
	*/
	
	//banner biliard cu mesaje popup
	objImage.setAttribute('src','library/images/home/banner_opel_astra_I.jpg');
	objImage.setAttribute('title','Noul Opel Astra');
	objImage.style.height = '381px';
	objImage.style.width = '971px';
	
	objImage.style.border = 'none';
	myLink.appendChild(objImage);
   /****** starsit link catre pagina de stoc, cu poza pe ea*******/

var objLink = document.createElement("a");
	objLink.setAttribute('href','#');
	objLink.setAttribute('title','Inchide');
	objLink.onclick = function () { 
		document.body.removeChild(document.getElementById('layer'));
      	document.body.removeChild(document.getElementById('box'));
    }
	objLink.innerHTML = "Inchide X";
	objLink.style.position = 'absolute';
	objLink.style.zIndex = '101';
	objLink.style.right='20px';
	objLink.style.top='15px';
	objLink.style.color='black';
	objLink.style.fontWeight="bolder";
	div.appendChild(objLink);

// preload and create close button image
	/*var imgPreloadCloseButton = new Image();

	// if close button image found, 
	imgPreloadCloseButton.onload=function(){

		var objCloseButton = document.createElement("img");
		objCloseButton.src = 'library/images/home/close.jpg';
		objCloseButton.setAttribute('id','closeButton');
		objCloseButton.style.position = 'absolute';
		objCloseButton.style.zIndex = '101';
		objCloseButton.style.border = 'none';
		objLink.appendChild(objCloseButton);

		return false;
	}

	imgPreloadCloseButton.src = 'library/images/home/close.jpg';*/
	
	/*var objKeyboardMsg = document.createElement("div");
	objKeyboardMsg.setAttribute('id','keyboardMsg');
	//objKeyboardMsg.innerHTML = 'apasati pe <kbd>x</kbd> pentru inchidere';
	objKeyboardMsg.innerHTML = 'apasati tasta <b>ESC</b> pentru inchidere';
	objKeyboardMsg.style.zIndex = '101';
	div.appendChild(objKeyboardMsg);*/


listenKey();

  }
  
 function wresize(){
	 document.body.removeChild(document.getElementById('layer'));
	 document.body.removeChild(document.getElementById('box'));
	 showBox();
}
function getKey(e){
      var kC  = (window.event) ?    // MSIE or Firefox?
                 event.keyCode : e.keyCode;
      var Esc = (window.event) ?   
                27 : e.DOM_VK_ESCAPE // MSIE : Firefox
      if(kC==Esc){ 
		document.body.removeChild(document.getElementById('layer'));
      	document.body.removeChild(document.getElementById('box'));
      }
}
function listenKey () {	document.onkeypress = getKey; }

function insertafter(newchild, refchild) { 
 refchild.parentNode.insertBefore(newchild,refchild.nextSibling); 
}