var Hotres = new Object;

Hotres.url = '';
Hotres._lang = 'pl'; //default lang

Hotres.show = function(auth,lang,ref,arrival_date,departure_date) {
	Hotres.create();
	link = 'http://www.panel.hotres.pl/booking/index/lang/'+lang+'/auth/'+auth;
	if (ref && ref!=undefined) link=link+'/ref/'+ref;
	if (arrival_date && arrival_date!=undefined) link=link+'/arrival_date/'+arrival_date;
	if (departure_date && departure_date!=undefined) link=link+'/departure_date/'+departure_date;
	
	document.getElementById("hotresContent").innerHTML='<iframe frameborder="0" width="100%" style="margin:0px;padding:0px;" height="100%" src="'+link+'"></iframe>';
}

Hotres.setLang = function(lang) {
	Hotres._lang = lang;
}

Hotres.showPackage = function(id,auth,lang,ref) {
  Hotres.create();	
  link = 'http://www.panel.hotres.pl/bookingpackage/show/lang/'+lang+'/auth/'+auth+'/packageid/'+id;
  if (ref && ref!=undefined) link=link+'/ref/'+ref;
  document.getElementById("hotresContent").innerHTML='<iframe frameborder="0" width="100%" style="margin:0px;padding:0px;" height="100%" src="'+link+'"></iframe>';
}

Hotres.showPackages = function(auth,lang) {
	  Hotres.create();	
	  document.getElementById("hotresContent").innerHTML='<iframe frameborder="0" width="100%" style="margin:0px;padding:0px;" height="100%" src="http://www.panel.hotres.pl/bookingpackage/index/lang/'+lang+'/auth/'+auth+'"></iframe>';
	}


Hotres.showVouchers = function(auth,lang) {
	  Hotres.create();	
	  document.getElementById("hotresContent").innerHTML='<iframe frameborder="0" width="100%" style="margin:0px;padding:0px;" height="100%" src="http://www.panel.hotres.pl/bookingvoucher/index/lang/'+lang+'/auth/'+auth+'"></iframe>';
	}

	
Hotres.showVoucher = function(id,auth,lang,ref) {
	  Hotres.create();	
	  link = 'http://www.panel.hotres.pl/bookingvoucher/select/lang/'+lang+'/auth/'+auth+'/vouchersid/'+id;
	  if (ref && ref!=undefined) link=link+'/ref/'+ref;
	  document.getElementById("hotresContent").innerHTML='<iframe frameborder="0" width="100%" style="margin:0px;padding:0px;" height="100%" src="'+link+'"></iframe>';
	}	

Hotres.destroy = function() {	
	var BodyObject = document.getElementsByTagName("body").item(0); 
	BodyObject.removeChild(document.getElementById("hotresOverlay"));
	BodyObject.removeChild(document.getElementById("hotresContent"));
	BodyObject.removeChild(document.getElementById("hotresClose"));
	BodyObject.removeChild(document.getElementById("hotresPowered"));
}

Hotres.create = function() {


var w=995;var h=550;
var arrayPageSize = Hotres.getPageSize(); 
var arrayPageScroll = Hotres.getPageScroll(); 


var BodyObject = document.getElementsByTagName("body").item(0); 
var OverlayObject = document.createElement("div"); 
OverlayObject.setAttribute('id','hotresOverlay'); 
OverlayObject.onclick = function() { Hotres.destroy(); }
OverlayObject.style.width = arrayPageSize[0] + "px"; 
OverlayObject.style.height = arrayPageScroll[1]+arrayPageSize[1] + "px"; 
OverlayObject.style.left = '0px'; 
OverlayObject.style.top = '0px'; 
OverlayObject.style.position = "absolute"; 
OverlayObject.style.backgroundColor = "#000000"; 
OverlayObject.style.zindex = getNextHighestZindex(); 
OverlayObject.style.filter = "alpha(opacity=65)"; 
OverlayObject.style.mozOpacity = ".65"; 
OverlayObject.style.opacity = ".65"; 
OverlayObject.style.display = "block"; 


var ContentObject = document.createElement("div"); 
ContentObject.setAttribute('id', 'hotresContent'); 
ContentObject.style.width = w+"px"; 
ContentObject.style.height = h+"px"; 
ContentObject.style.padding = "0px"; 
ContentObject.style.margin = "0px"; 

ContentObject.style.left = (arrayPageSize[0]-w)/2+'px';
ContentObject.style.top = arrayPageScroll[1]+(arrayPageSize[1]-h)/2+'px';

ContentObject.style.position = "absolute"; 
ContentObject.style.zindex = getNextHighestZindex(); 
ContentObject.style.background = "url(http://www.hotres.pl/api/api-back-bw.png) no-repeat"; 
ContentObject.style.display = "block"; 


var CloseObject = document.createElement("div"); 
CloseObject.onclick = function() { Hotres.destroy(); }
CloseObject.setAttribute('id', 'hotresClose'); 
CloseObject.style.width = "41px"; 
CloseObject.style.height = "30px"; 
CloseObject.style.cursor = "pointer"; 
CloseObject.style.left = ((arrayPageSize[0]-w)/2)+w-51+'px';
CloseObject.style.top = arrayPageScroll[1]+(arrayPageSize[1]-h)/2-30+'px';
CloseObject.style.position = "absolute"; 
CloseObject.style.zindex = getNextHighestZindex(); 
CloseObject.style.background = "url(http://www.hotres.pl/api/api-close.png) no-repeat"; 

CloseObject.onmouseover = function() {this.style.backgroundPosition = "right";}
CloseObject.onmouseout = function() {this.style.backgroundPosition = "left";}


var PoweredObject = document.createElement("div"); 
PoweredObject.onclick = function() { window.open('http://www.hotres.pl'); }
PoweredObject.setAttribute('id', 'hotresPowered'); 
PoweredObject.style.width = "153px"; 
PoweredObject.style.height = "29px"; 
PoweredObject.style.cursor = "pointer"; 
PoweredObject.style.left = ((arrayPageSize[0]-w)/2)+410+'px';
PoweredObject.style.top = arrayPageScroll[1]+(arrayPageSize[1]-h)/2+551+'px';
PoweredObject.style.position = "absolute"; 
PoweredObject.style.zindex = getNextHighestZindex(); 
PoweredObject.style.background = "url(http://www.hotres.pl/api/api-powered.png) no-repeat"; 

BodyObject.appendChild(OverlayObject); 
BodyObject.appendChild(ContentObject); 
BodyObject.appendChild(CloseObject); 
BodyObject.appendChild(PoweredObject); 

if (document.all) { document.body.onresize = resizeLayers; } else 
{ if (window.addEventListener) { window.addEventListener("resize", resizeLayers, false); } 
else { window.attachEvent("resize", resizeLayers); } } 

}




function getNextHighestZindex()
	{  
	   var highestIndex = 0;  
	   var currentIndex = 0;  
	   var elArray = document.getElementsByTagName('*');  
	   for(var i=0; i < elArray.length; i++){  
	      if (elArray[i].currentStyle){  
	         currentIndex = parseFloat(elArray[i].currentStyle['zIndex']);  
	      }else if(window.getComputedStyle){  
	         currentIndex = parseFloat(document.defaultView.getComputedStyle(elArray[i],null).getPropertyValue('z-index'));  
	      }  
	      if(!isNaN(currentIndex) && currentIndex > highestIndex){ highestIndex = currentIndex; }  
	   }  
	   return(highestIndex+1);  
	}  


function resizeLayers()
{
var w=995;var h=550;

var arrayPageSize = Hotres.getPageSize(); 
var arrayPageScroll = Hotres.getPageScroll(); 


var OverlayObject = document.getElementById("hotresOverlay");
OverlayObject.style.width = arrayPageSize[0] + "px"; 
OverlayObject.style.height = arrayPageScroll[1]+arrayPageSize[1] + "px"; 

var ContentObject = document.getElementById("hotresContent");
ContentObject.style.left = (arrayPageSize[0]-w)/2+'px';
ContentObject.style.top = arrayPageScroll[1]+(arrayPageSize[1]-h)/2+'px';

var CloseObject = document.getElementById("hotresClose");
CloseObject.style.left = ((arrayPageSize[0]-w)/2)+w-51+'px';
CloseObject.style.top = arrayPageScroll[1]+(arrayPageSize[1]-h)/2-30+'px';

var PoweredObject = document.getElementById("hotresPowered");
PoweredObject.style.left = ((arrayPageSize[0]-w)/2)+410+'px';
PoweredObject.style.top = arrayPageScroll[1]+(arrayPageSize[1]-h)/2+551+'px';
}

Hotres.getPageSize = function ()
{
var x,y; 
if (self.innerHeight) { x = self.innerWidth; y = self.innerHeight; } 
else if (document.documentElement && document.documentElement.clientHeight) 
{ x = document.documentElement.clientWidth; y = document.documentElement.clientHeight; } 
else if (document.body) { x = document.body.clientWidth; y = document.body.clientHeight; } 
arrayPageSize = new Array(x,y);
return arrayPageSize; 
} 


Hotres.getPageScroll = function ()
	{ 
	var x,y; 
	if (self.pageYOffset)
		{ 
		x = self.pageXOffset; 
		y = self.pageYOffset; 
		} 
	else if (document.documentElement && document.documentElement.scrollTop)
		{ 
		x = document.documentElement.scrollLeft; 
		y = document.documentElement.scrollTop; 
		} 
	else if (document.body) 
		{ 
		x = document.body.scrollLeft; 
		y = document.body.scrollTop; 
		}

	x = parseFloat(x); 
	y = parseFloat(y); 
	arrayPageSize = new Array(x,y);
	return arrayPageSize; 
	} 
