
var HotelSystems = new Object;

HotelSystems._verticalOffset = 0;

HotelSystems.url = '';
HotelSystems._domain = 'wittenberg.hotelsystems.pl';

HotelSystems._iframeSrc = 'https://'+HotelSystems._domain+'/index/';
HotelSystems._iframeVideo = 'http://'+HotelSystems._domain+'/video/';

HotelSystems._loadCounter = 0;
HotelSystems._loadInterval = false;

HotelSystems._params = new Object;
HotelSystems._lang = 1;

	HotelSystems._hideFlash = false;
	HotelSystems._wmodeFlash = false;

HotelSystems._ie = false;
HotelSystems._ie6 = false;
HotelSystems._mode = document.compatMode;

HotelSystems._forceShow = false;



	HotelSystems._iframeSrc = 'https://'+HotelSystems._domain+'/index/';



function loadCounter() {
	HotelSystems._loadCounter++;
	//window.status = HotelSystems._loadCounter;	
	if(HotelSystems._loadCounter > 15) {
		document.getElementById('hs_iframe').style.backgroundImage = '';
		document.getElementById('hs_iframe').style.backgroundColor = '#ffffff';
		clearInterval(HotelSystems._loadInterval);
	}
}

HotelSystems.showHotel = function(domain) {
	HotelSystems.setDomain(domain);
	HotelSystems.show(HotelSystems.renderParams());
}

HotelSystems.showHotelOffer = function(domain,id) {
	HotelSystems.setDomain(domain);
	HotelSystems.showOffers(id);
}

HotelSystems.setDomain = function(domain) {
	HotelSystems._iframeSrc = 'https://'+domain+'.hotelsystems.pl/index/';
}

HotelSystems.setLang = function(lang) {
	HotelSystems._lang = HotelSystems.convertLang(lang);
}

HotelSystems.convertLang = function(lang) {
	var langArr = new Array;
	langArr['pl'] = 1;
	langArr['en'] = 2;
	langArr['de'] = 5;
	langArr['lt'] = 4;
	langArr['ru'] = 6;
	return langArr[lang];
}

HotelSystems.createCookie = function(name,value,days) {
	var head = document.getElementsByTagName("head")[0];
	var script = document.createElement("script");
	script.src = "A.com/setCookie?cache=1231213123";
	head.appendChild(script);
}

HotelSystems.show = function(p) {	
	HotelSystems._params = p;		
	HotelSystems.v(false);
}

HotelSystems.showRoom = function(p) {
	HotelSystems.show({'id_rooms_types':p});
}

HotelSystems.showOffers = function(offers_id) {
	if(!offers_id) { var offers_id = 'first'; }
	HotelSystems.show({'id_offers':offers_id});	
	//HotelSystems.v();
}


HotelSystems.showVideo = function(initVideo) {
	HotelSystems.hideFlash();

	if(!document.getElementById('hs_div')) {
		HotelSystems.init2();
	}
	
	if(!initVideo) { var initVideo = 0; }
	
	document.getElementById('hs_iframe').src = HotelSystems._iframeVideo+'initVideo/'+initVideo;
	document.body.style.overflow = 'hidden';
	document.getElementById("hs_reservation_container").style.display = 'block';
	document.getElementById("hs_overlay").style.display = 'block';
	if(!HotelSystems._forceShow) {
		document.getElementById("hs_overlay").onclick = function() { HotelSystems.hide(); }	
	}
	HotelSystems.position();
	HotelSystems.v(true);
	
}


HotelSystems.showGMap = function() {
	//HotelSystems.hideFlash();

	if(!document.getElementById('hs_div')) {
		HotelSystems.init2();
	}
	
	var src = 'http://'+HotelSystems._domain+'/gmap';
	
	document.getElementById('hs_iframe').src = src;
	document.body.style.overflow = 'hidden';
	document.getElementById("hs_reservation_container").style.display = 'block';
	document.getElementById("hs_overlay").style.display = 'block';
	if(!HotelSystems._forceShow) {
		document.getElementById("hs_overlay").onclick = function() { HotelSystems.hide(); }	
	}
	HotelSystems.position();
	HotelSystems.v(true);
}

HotelSystems.showPromo = function() {
	HotelSystems.show({'promo':true});
}

HotelSystems.renderParams = function() {
	var p = HotelSystems._params;
	var str = '';
	
	if(p) {
		if (p.id_offers && p.id_offers_variants && p.date_from) {
			str += 'load/loadOffer/id/'+p.id_offers+'/?reservations__id_offers='+p.id_offers;
		}
		else {
			if (p.id_offers) {
				str += 'load/loadOffer/id/' + p.id_offers + '/?';
			}
			else {
				str += '?';
			}
		}
		if(p.date_from) { str += '&reservations__date_from='+p.date_from; }
		if(p.date_to) { str += '&reservations__date_to='+p.date_to; }
		if(p.id_rooms_types) { str += '&reservations__id_rooms_types='+p.id_rooms_types; }
		if(p.id_offers_variants) { str += '&reservations__id_offers_variants='+p.id_offers_variants; }
		if(p.promo) { str = 'load/discounts/?'; }
		if(p.days) { str += '&reservations__days='+p.days; }
		
	} else {
		str += '?';
	}
	if(HotelSystems._lang) { str += '&setLang='+HotelSystems._lang; }
	if(HotelSystems._idPartners) { str += '&setPartners='+HotelSystems._idPartners; }
	
	return str;
}

HotelSystems.hideFlash = function() {		
	var flash = document.getElementsByTagName('embed');	
	for(var i = 0; i < flash.length; i++) {
		if (HotelSystems._hideFlash) {
			flash[i].style.visibility = 'hidden';
		} else {
			flash[i].setAttribute('wmode', 'transparent');
		}
	}
	
	var flash = document.getElementsByTagName('object');
	
	for(var i = 0; i < flash.length; i++) {
		if (HotelSystems._hideFlash) {
			flash[i].style.visibility = 'hidden';
		} else {
			var params = flash[i].getElementsByTagName('param');
			for (var p = 0; p < params.length; p++) {
				if (params[p].name == 'wmode') {
					params[p].value = 'transparent';
				}
			}
			var param = document.createElement('param');
			param.setAttribute('name', 'wmode');
			param.setAttribute('value', 'transparent');
			flash[i].appendChild(param);
		}
	}
	
	if(HotelSystems._wmodeFlash) {
		document.body.style.overflow = 'auto';
	}
}

HotelSystems.showFlash = function() {
	var flash = document.getElementsByTagName('embed');	
	for(var i = 0; i < flash.length; i++) {
		if (HotelSystems._hideFlash) {
			flash[i].style.visibility = 'visible';
		}
	}
	
	var flash = document.getElementsByTagName('object');
	
	for(var i = 0; i < flash.length; i++) {
		if (HotelSystems._hideFlash) {
			flash[i].style.visibility = 'visible';
		}
	}
}

HotelSystems.v = function(dontload) {

	if (HotelSystems._wmodeFlash||HotelSystems._hideFlash) {
		HotelSystems.hideFlash();
	}
	
	if(!document.getElementById('hs_div')) {
		HotelSystems.init2();
	}
	
	var paramsStr = HotelSystems.renderParams();
	var url = HotelSystems._iframeSrc+paramsStr;
	if (!dontload) {
		document.getElementById('hs_iframe').src = url;
	}
	
	if (!HotelSystems._ie) {
		//document.body.style.overflow = 'hidden';
	}
	
	document.getElementById("hs_reservation_container").style.display = 'block';
	document.getElementById("hs_overlay").style.display = 'block';
	document.getElementById("hs_div").style.display = 'block';
	if(!HotelSystems._forceShow) {
		document.getElementById("hs_overlay").onclick = function() { HotelSystems.hide(); }	
	}
	HotelSystems.position();
}

HotelSystems.hide = function() {	
	document.getElementById("hs_reservation_container").style.display = 'none';
	document.getElementById("hs_overlay").style.display = 'none';
	document.getElementById("hs_div").style.display = 'none';	
	//HotelSystems.position();	
	
	if (!HotelSystems._ie) {
		//document.body.style.overflow = 'visible';
	}
		
	if(HotelSystems._hideFlash) {
		HotelSystems.showFlash();
	}
}

HotelSystems.getWindowSize = function() {
	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth;
	  winH = window.innerHeight;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winW = document.body.offsetWidth;
	  winH = document.body.offsetHeight;
	 }
	}
	return Array(winW,winH);
}

HotelSystems.getViewportSize = function() {
	 var viewportwidth;
	 var viewportheight;
	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
	      viewportwidth = window.innerWidth,
	      viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientWidth !=
	     'undefined' && document.documentElement.clientWidth != 0)
	 {
	       viewportwidth = document.documentElement.clientWidth,
	       viewportheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
	       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	       viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	
	var a = Array(viewportwidth,viewportheight);
	return a;
}

HotelSystems.init = function() { }

HotelSystems.init2 = function(domain) {	
	HotelSystems.injectHtml();		
	
	HotelSystems.parseURL();
	if((HotelSystems.url == 'book')||(HotelSystems._forceShow)) {
		HotelSystems.v(false);
	}
	if(HotelSystems.url == 'video') {
		HotelSystems.v(true);
	}
}

HotelSystems.parseURL = function() {
	var urltag = document.location.href.split('#');
	HotelSystems.url = urltag[1];
}

HotelSystems.getHeight = function() {
	if (document.body.scrollHeight)
	return document.body.scrollHeight;
	return document.documentElement.offsetHeight;
}

HotelSystems.position = function() {
	
	var winSize = HotelSystems.getViewportSize();
	
	var msgbox = document.getElementById("hs_reservation_container");	
	var x = (winSize[0] / 2) - (msgbox.offsetWidth / 2);
	var y = (winSize[1] / 2) - (msgbox.offsetHeight / 2);
	
	if(y < 0) {
		var y = 10;
		if (!HotelSystems._ie6) {
			document.body.style.overflow = 'visible';
		}
		
		if (HotelSystems._ie) {
			document.body.style.overflow = 'auto';
		}
	}
	
	var scrollTop = (document.documentElement && document.documentElement.scrollTop) ?
				document.documentElement.scrollTop : document.body.scrollTop;
			
	if(HotelSystems._verticalOffset != 0) {
		var y = HotelSystems._verticalOffset;
	}
	
	var absy = y;
	y = y+scrollTop;
	
	if(winSize[0] < msgbox.offsetWidth) {
		HotelSystems._toSmallWindow = true;
	}
	
	if(winSize[1] < msgbox.offsetHeight) {
		HotelSystems._toSmallWindow = true;
	}
	
	if(HotelSystems._toSmallWindow) {
		var x = 0;
		var y = scrollTop;
		//document.body.scrollTop = 0;
	}
	
	msgbox.style.top = y+'px';
	msgbox.style.left = x+'px';
	var overlay = document.getElementById('hs_overlay');
	
	var pHeight = HotelSystems.getHeight();
		
	if (HotelSystems._toSmallWindow) {		
		if (winSize[0] < msgbox.offsetWidth) {
			overlay.style.width = msgbox.offsetWidth + 'px';
		} else {
			overlay.style.width = winSize[0] + 'px';
		}
		
		if (winSize[1] < msgbox.offsetHeight) {
			overlay.style.height = msgbox.offsetHeight + 'px';			
		} else {
			overlay.style.height = winSize[1] + 'px';
		}		
		
		overlay.style.top = '0px';		
	} else {
		overlay.style.width = winSize[0] + 'px';
		overlay.style.height = winSize[1] + 'px';
		overlay.style.top = scrollTop + 'px';
	}
		
	if ((HotelSystems._ie6)||((HotelSystems._mode == 'BackCompat')&&(HotelSystems._ie))) {
		overlay.style.height = (pHeight + msgbox.offsetHeight) + 'px';
		overlay.style.top = '0px';
		HotelSystems.setPosition('absolute');
	} else {
		if (HotelSystems._toSmallWindow) {
			overlay.style.height = (pHeight + msgbox.offsetHeight) + 'px';
			overlay.style.top = '0px';
			HotelSystems.setPosition('absolute');
		} else {
			HotelSystems.setPosition('fixed');
			overlay.style.top = '0px';
			msgbox.style.top = absy + 'px';
		}
	}
	
	var footer = document.getElementById('hs_footer');
	footer.style.left = (msgbox.offsetWidth-footer.offsetWidth)/2 + 'px';
	
}

HotelSystems.setPosition = function(pos) {
	if(!pos) { var pos = 'absolute'; }
	document.getElementById('hs_reservation_container').style.position = pos;
	document.getElementById('hs_overlay').style.position = pos;
	document.getElementById('hs_div').style.position = pos;
	}

 
HotelSystems.injectHtml = function() {

	var opacity = 45;

	var body = document.body;
	var hsDiv = document.createElement('div');
	hsDiv.setAttribute('id','hs_div');	
	hsDiv.style.left = '0px';
	hsDiv.style.top = '0px';
	hsDiv.style.zIndex = '1000';
	
	var iframe = document.createElement('iframe');
	iframe.setAttribute('id','hs_iframe');
	iframe.setAttribute('src',HotelSystems._iframeSrc);
	iframe.setAttribute('scrolling','auto');
	iframe.setAttribute('frameBorder',0);
	iframe.style.margin = '15px';
	
	iframe.style.width = '862px';
	iframe.style.height = '562px';
	
	iframe.style.border = 'none';
	iframe.style.zIndex = '152';
	iframe.style.backgroundColor = '#f1f1f1';
	iframe.style.backgroundRepeat = 'no-repeat';
	iframe.style.backgroundPosition = '50% 50%';
	
	if (HotelSystems._lang == 1) {
		iframe.style.backgroundImage = "url('https://" + HotelSystems._domain + "/skins/hotelsystems/img/loader_iframe_pl.gif')";
	} else {
		iframe.style.backgroundImage = "url('https://" + HotelSystems._domain + "/skins/hotelsystems/img/loader_iframe_en.gif')";
	}
	
	HotelSystems._iframe = iframe;
	
	var hsContainer = document.createElement('div');
	hsContainer.setAttribute('id','hs_reservation_container');	
	hsContainer.style.width = '892px';
	hsContainer.style.height = '602px';
	hsContainer.style.border = 'none';
	hsContainer.style.overflow = 'hidden';
	hsContainer.style.display = 'none';
	hsContainer.style.zIndex = '151';
	
	var closeBtn = document.createElement('div');
	var closeImg = 'https://'+HotelSystems._domain+'/skins/hotelsystems/img/close_btn.gif';
	closeBtn.style.background = 'url('+closeImg+')';
	closeBtn.style.cursor = 'pointer';
	closeBtn.style.height = '19px';
	closeBtn.style.overflow = 'hidden';
	closeBtn.style.position = 'absolute';
	closeBtn.style.right = '21px';
	closeBtn.style.top = '21px';
	closeBtn.style.width = '20px';
	closeBtn.style.zIndex = '153';
	closeBtn.onclick = function() {
		HotelSystems.hide();
	}
		
	if(HotelSystems._forceShow) { opacity = 100; }
	
	var hsOverlay = document.createElement('div');
	hsOverlay.setAttribute('id','hs_overlay');	
	hsOverlay.style.top = '0px';
	hsOverlay.style.left = '0px';
	hsOverlay.style.backgroundColor = '#000000';
	hsOverlay.style.border = 'none';
	hsOverlay.style.overflow = 'hidden';
	hsOverlay.style.zIndex = '150';
	hsOverlay.style.display = 'none';
	hsOverlay.style.opacity = '.'+opacity;
	hsOverlay.style.filter = 'alpha(opacity='+opacity+')';
			
	var hsFooter = document.createElement('div');
	hsFooter.setAttribute('id','hs_footer');
	hsFooter.style.position = 'absolute';
	hsFooter.style.left = '361px';
	hsFooter.style.bottom = '3px';
	hsFooter.style.textAlign = 'center';
	hsFooter.style.width = '170px';
	hsFooter.style.height = '22px';
	hsFooter.style.lineHeight = '22px';
	hsFooter.style.overflow = 'hidden';	
	
	var hsBg = document.createElement('div');
	hsBg.style.backgroundColor = '#000000';
	hsBg.style.width = '170px';
	hsBg.style.height = '22px';
	hsBg.style.lineHeight = '22px';
	hsBg.style.opacity = '.75';
	hsBg.style.filter = 'alpha(opacity=75)';
	hsBg.style.position = 'absolute';
	hsBg.style.background = "url('https://admin.hotelsystems.pl/public/images/hs_tag_bg.gif')";
	hsBg.style.backgroundRepeat = 'no-repeat';
	hsBg.style.overflow = 'hidden';
	hsBg.style.left = '0px';
	
	hsFooter.appendChild(hsBg);
	
	var hsLinkCont = document.createElement('div');
	hsLinkCont.style.position = 'absolute';
	hsLinkCont.style.width = '170px';
	hsLinkCont.style.height = '18px';
	hsLinkCont.style.left = '0px';
	hsLinkCont.style.zIndex = 50;
	hsLinkCont.style.top = '0px';
	hsLinkCont.style.lineHeight = '22px';
	hsLinkCont.style.textAlign = 'center';
	
	var hslink = document.createElement('a');
	hslink.href = 'http://www.hotelsystems.pl';
	hslink.target = '_blank';
	hslink.style.textDecoration = 'none';
	
	hslink.style.fontSize = '11px';
	hslink.style.fontFamily = 'Tahoma';
	hslink.style.color = '#c3c3c3';
	hslink.style.fontWeight = 'normal';
	hslink.style.lineHeight = '22px';	
	hslink.style.textAlign = 'center';
	
	hslink.innerHTML = 'powered by HotelSystems.pl';

	hsLinkCont.appendChild(hslink);
	hsFooter.appendChild(hsLinkCont);
	
	hsContainer.appendChild(hsFooter);	
		
	if(!HotelSystems._forceShow) { hsContainer.appendChild(closeBtn); }
	hsContainer.appendChild(iframe);
	hsDiv.appendChild(hsContainer);
	hsDiv.appendChild(hsOverlay);

	body.appendChild(hsDiv);
	
	HotelSystems._loadInterval = setInterval("loadCounter()",1000);
	
	//body.insertBefore(hsDiv,body.firstChild);	
	
}
