// JavaScript Document
var imgPop1 = new Image();
var imgPop2 = new Image();
var popProPicLoaded = 0;
var popText;
var bPopOk = false;
var popPicNow;

function popProBeginLoad() {
	imgPop1.onload = popProLoadCount;
	imgPop2.onload = popProLoadCount;
	imgPop1.src = "images/Ayatana_Superior_Rooms2.jpg";
	imgPop2.src = "images/Ayatana_Deluxe_Rooms1.jpg";
}

function popProLoadCount() {
	popProPicLoaded++;
	if (popProPicLoaded >= 2) {
		popText = "<div style=\"height:30px; color:#ffffff; background-color:#551314;\"><div style=\"padding:5px 0px 0px 5px;\">โปรโมชั่นคนไทย</div></div>"
			+ "<div style=\"height:" + (150 + imgPop1.height) + "px; border:solid 1px #551314; background-color:#e1d1b0; color:#532410;\"><div id=\"popPicBg\"><img src=\"" + imgPop1.src + "\" id=\"popPic\" /></div><div style=\"padding:10px; font-size:14px;\"><ul class=\"pop\"><li><a href=\"javascript:popCngPic(1)\">ห้องซุปพีเรียร์ ๑,๖๐๐ บาท</a></li><li><a href=\"javascript:popCngPic(2)\">ห้องดีลักซ์ ๒,๖๐๐  บาท</a></li></ul>วันนี้ – ๓๑ ต.ค. ๒๕๕๔<br />(ราคานี้รวมอาหารเช้า, ภาษี และค่าบริการแล้ว)<br />สอบถามรายละเอียดเพิ่มเติม โทร: 053 811388</div></div>";
		bPopOk = true;
	}
}

function popCngPic(n) {
	url = "";
	url2 = "";
	if (n == 2) {
		url = imgPop2.src;
		url2 = imgPop1.src;
	}
	else {
		url = imgPop1.src;
		url2 = imgPop2.src;
	}
	popPicNow = url;
	popPic = document.getElementById("popPic");
	popPicBg = document.getElementById("popPicBg");
	popPic.alpha = 100;
	popPicBg.style.backgroundImage = "url(" + url + ")";
	popCngPic2();
}

function popCngPic2() {
	popPic.alpha -= 5;
	setAlpha(popPic,popPic.alpha);
	if (popPic.alpha <= 5) {
		popPic.src = popPicNow;
		setAlpha(popPic,100);
		return;
	}
	setTimeout(popCngPic2,30);
}

function openPopPromo() {
	if (!bPopOk) return;
	initial();
	callDialog(popText,2 + imgPop1.width,180 + imgPop1.height,0);
	_popBG.onclick = closeDialog;
}

var halfX;
var halfY;
var fullX;
var fullY;

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function initial() {
	IE = document.all ? true : false;
	fox = new RegExp("Firefox","i");
	chrome = new RegExp("Chrome","i");
	safari = new RegExp("Safari","i");
	opera = new RegExp("Opera","i");
	if (IE) {
		fullX = document.body.clientWidth;
		fullY = getWindowHeight();
	}
	else if (fox.test(navigator.userAgent) || chrome.test(navigator.userAgent) || safari.test(navigator.userAgent) || opera.test(navigator.userAgent)) {
		fullX = document.body.clientWidth;
		fullY = getWindowHeight();
	}
	else {
		fullX = pageXOffset;
		fullY = pageYOffset;
	}
	halfX = Math.floor(fullX / 2);
	halfY = fullY / 2;
}

function setAlpha(obj,per) {
	inone = per / 100;
	if (inone >= 1) inone = 0.99;
	obj.style.opacity = inone;
	obj.style.MozOpacity = inone;
	obj.style.KhtmlOpacity = per / 100;
	obj.style.filter = "alpha(opacity=" + per + ")";
}

var _popBG = null;
var _popFG = null;

function callDialog(txt,w,h,padding) {
	initial();
	if (padding == undefined) padding = 20;
	if (_popBG == null) {
		_popBG = document.createElement("div");
		_popBG.style.position = "fixed";
		_popBG.style.zIndex = 98;
		_popBG.style.backgroundColor = "#fff";
		setAlpha(_popBG,80);
		document.body.appendChild(_popBG);
	}
	if (_popFG == null) {
		_popFG = document.createElement("div");
		_popFG.style.position = "fixed";
		_popFG.style.zIndex = 99;
		_popFG.style.backgroundColor = "#FFF";
		document.body.appendChild(_popFG);
	}
	_popBG.style.width = fullX + "px";
	_popBG.style.height = fullY + "px";
	_popBG.style.left = "0px";
	_popBG.style.top = "0px";
	_popFG.style.width = w;
	_popFG.style.height = h;
	_popFG.style.left = Math.round((fullX - w) / 2) + "px";
	_popFG.style.top = Math.round((fullY - h) / 2) + "px";
	_popFG.innerHTML = "<div style=\"padding:" + padding + "px\">" + txt + "</div>";
	_popBG.style.display = "";
	_popFG.style.display = "";
	return _popFG;
}

function closeDialog() {
	_popFG.style.display = "none";
	_popBG.style.display = "none";
}

