Element.extend({
	getWidth: function(){
		return this.getCoordinates().width
	},
	getHeight: function(){
		return this.getCoordinates().height
	}
});

var W3CDOM = (document.createElement && document.getElementsByTagName);
window.addEvent("load", function(){
	initImages();
});

function initBoxFacilities() {
	if (!$('boxFacilities') || !$('more')) {
		return;
	}
	
	var div = $('boxFacilities');
	div.removeClass('moreFacilities');
	$('more').setStyle('visibility', 'hidden');
	return;
	
	if ($ES('table', div).length == 0 && $ES('li', div).length <= 2 * 6) {
		$('more').setStyle('visibility', 'hidden');
	}
}

function initGallery() {
	if (typeof images == 'undefined') {
		return;
	}
	
	var ulNode = $$('ul.numberBox');
	if (ulNode.length == 0) {
		return;
	}
	ulNode = ulNode[0];
	
	var arrLi = $ES('li',ulNode);
	var prev = $('preBox');
	// remove action from HTML page
	prev.onclick = null;
	
	var next = $('nextBox');	
	// remove action from HTML page
	next.onclick = null;
	
	var activeIndex = 0;
	
	if (images.length == 0) { // do nothing here
		return;
	}
	
	if (images.length == 1) {
		ulNode.getParent().setStyle('display', 'block');
		changImage(0);
		return;
	}
	
	arrLi.each(function(aElement,index){	
		aElement.removeClass('active');
		aElement.index = index
		aElement.addEvent('click',function(evt) {
			new Event(evt).stop();
						
			changImage(this.index);
		});
	});
	
	
	next.addEvent('click', function(evt) {
		new Event(evt).stop();
		
		changImage(activeIndex + 1);
	});
	
	
	prev.addEvent('click', function(evt) {
		new Event(evt).stop();
		
		changImage(activeIndex - 1);
	});
	
	
	function changImage(index) {
		if (index < 0 || index >= arrLi.length) {
			return;
		}
		arrLi[activeIndex].removeClass('active');
		
		$('photo').setProperty('src',images[index]);
		arrLi[index].addClass('active');
		
		activeIndex = index;
		
		if (activeIndex == 0) {
			prev.removeClass('preBox');
			prev.addClass('firstBox');
		} else {
			prev.addClass('preBox');
			prev.removeClass('firstBox');
		}
		
		if (activeIndex == arrLi.length - 1) {
			next.removeClass('nextBox');
			next.addClass('lastBox');
		} else {
			next.addClass('nextBox');
			next.removeClass('lastBox');
		}
	}
	
	// show first image
	changImage(0);
}

function initImages() {	
	//
	document.imageOut = new Object();
	document.imageOver = new Object();
	// PNG Fix for IE<7
	var png_fix = "png_fix.gif";
	var pngRegExp = new RegExp("\\.png$", "i")
	var f = "DXImageTransform.Microsoft.AlphaImageLoader";
	//
	var imageArray = $$("img", "input");
	imageArray.each(function(item){
		var image = item.src.substr(item.src.lastIndexOf("/")+1);
		var id = item.id || image.replace("_n.", "").replace("_N.", "");
		var hover = (image.toLowerCase().lastIndexOf("_n.") !=-1);
		//
		if (hover && document.imageOut && document.imageOver) {
			document.imageOut[id] = new Image();
			document.imageOut[id].src = item.src;
			document.imageOver[id] = new Image();
			document.imageOver[id].src = item.src.substr(0, item.src.lastIndexOf("/")+1)+image.replace("_n.", "_o.").replace("_N.", "_O.");
		}
		// PNG Fix for IE<7
		if (window.ie && !window.ie7 && image.test(pngRegExp)) {
			item.style.width = item.offsetWidth+"px";
			item.style.height = item.offsetHeight+"px";
			item.style.filter = "progid:"+f+"(src='"+item.src+"', sizingMethod='scale');";
			item.src = png_fix;
		}
		//
		if (hover && document.imageOut && document.imageOver) {
			item.onmouseover = function(){
				if (document.imageOver && document.imageOver[this.id]) setImage(this, document.imageOver[this.id].src);
			}
			item.onmouseout = function(){
				if (document.imageOut && document.imageOut[this.id]) setImage(this, document.imageOut[this.id].src);
			}
			item.id = id;
			//
			function setImage(imageObject, src) {
				if (window.ie && !window.ie7) {
					if (imageObject.filters[f] && imageObject.filters[f].src.test(pngRegExp)) {
						imageObject.filters[f].src = src;
					} else {
						imageObject.src = src;
					}
				} else {
					imageObject.src = src;
				}
			}
		}
	});
}
/////////

function initMenu(){
	
	var body = $$("body")[0];
	if (!initMenu.frm) {
		initMenu.frm = new Element("iframe");
		initMenu.frm.setStyles({
			filter: 'alpha(opacity=0)',
			position: 'absolute',			
			"z-index": 1000,
			top: -500,
			left: 0,
			height: 0
		});
		
		initMenu.frm.injectInside($$('body')[0]);
		initMenu.frm.fx = new Fx.Style(initMenu.frm, "height");
	}
	
	document.menuOver = false;
	document.openedMenu = null;
	document.openedBtn = null;
	document.menuInterval = null;
	
	//
	$$("a.menuBtn").each(function(btn, i){
		var menuContent = $(btn.getProperty("id")+"Menu");
		btn.subMenu = menuContent.clone().injectInside($$("body")[0]);
		menuContent.remove();
		btn.subMenu.orgH = btn.subMenu.getCoordinates().height;
		btn.subMenu.fx = new Fx.Style(btn.subMenu, "height").set(0);
		btn.subMenu.subUL = btn.subMenu.getElements("ul");
		//
		btn.addEvent("mouseover", function(){
			if (btn.getFirst()) btn.getFirst().swap = false;
			btn.subMenu.setStyles({
				left: btn.getPosition().x+10
			});
			
			if (window.ie) {
				initMenu.frm.setStyles({
					left: btn.getPosition().x,
					top: btn.subMenu.getPosition().y,
					width: btn.subMenu.getWidth()
				});
				
				btn.subMenu.injectInside($$('body')[0]);
				initMenu.frm.fx.start(btn.subMenu.orgH);
			}
			
			//
			hideMenu();
			//
			btn.subMenu.fx.stop();
			btn.subMenu.fx.options.duration = 500;
			btn.subMenu.fx.start(btn.subMenu.orgH);
			//
			clearInterval(document.menuInterval);
			document.menuOver = true;
			document.openedMenu = btn;
		});
		btn.addEvent("mouseout", function(){
			document.menuOver = false;
			clearInterval(document.menuInterval);
			document.menuInterval = setInterval(hideMenu, 100);
		});
		//
		btn.subMenu.subUL.each(function(sMn){
			var prevLink = sMn.getPrevious();
			prevLink.addEvent("click", function(e){
				new Event(e).stop();
				sMn.fx.stop();
				sMn.fx.start(!sMn.opened ? sMn.orgH : 0);
				sMn.opened = !sMn.opened;
				//
				btn.subMenu.fx.stop();
				btn.subMenu.fx.start(btn.subMenu.getCoordinates().height+(sMn.opened ? sMn.orgH : -sMn.orgH));
				//
			});
			sMn.opened = false;
			sMn.orgH = sMn.getCoordinates().height;
			sMn.setStyle("height", 0);
			sMn.fx = new Fx.Style(sMn, "height");
			btn.subMenu.orgH -= sMn.orgH;
		});
		//
		btn.subMenu.addEvent("mouseover", function(){
			clearInterval(document.menuInterval);
			document.menuOver = true;
			
		});
		btn.subMenu.addEvent("mouseout", function(){
			document.menuOver = false;
			clearInterval(document.menuInterval);
			document.menuInterval = setInterval(hideMenu, 100);
		});
		btn.subMenu.getElements("a").addEvents({
			"mouseover": function(e){
				clearInterval(document.menuInterval);
				document.menuOver = true;
			},
			"mouseout": function(e){
				document.menuOver = false;
				clearInterval(document.menuInterval);
				document.menuInterval = setInterval(hideMenu, 100);
			}
		});
		//
	});
	$$("#nav a").each(function(item){
		if (!item.hasClass("menuBtn")) {
			item.addEvent("mouseover", function(){
				hideMenu();
			});
		}
	});
	//
	//
	function hideMenu(){
		
		if (document.menuOver == false) {
			clearInterval(document.menuInterval);
			
			if (window.ie) {
				initMenu.frm.fx.start(0);
			}
			
			if (document.openedMenu) {
				var img = document.openedMenu.getFirst()
				if (img) {
					img.swap = true;
					img.fireEvent("mouseout");
				}
				//
				var subOpenedMenu = document.openedMenu.subMenu;
				subOpenedMenu.fx.stop();
				subOpenedMenu.fx.options.duration = 200;
				subOpenedMenu.fx.start(0);
				subOpenedMenu.subUL.each(function(subUL){
					subUL.fx.stop();
					subUL.fx.set(0);
					subUL.opened = false;
				});
				document.openedMenu = null;
			}
		}
	}
}
//////
function initSlideGallery() {
	var slideContent = $("slideGallery");
	if (!slideContent) return;
	slideContent.fxScrollIndex = 0;
	slideContent.fxScroll = new Fx.Scroll(slideContent, {
		wait: false,
		duration: 1000,
		transition: Fx.Transitions.Quad.easeInOut
	});
	slideContent.scrollTo(0, 0);
	slideContent.li = slideContent.getFirst().getChildren();
	//
	//
	var leftBtn = slideContent.getPrevious().getFirst();
	if (leftBtn) {
		leftBtn.setOpacity(0.5);
		leftBtn.addEvent("click", function(e){
			new Event(e).stop();
			if (slideContent.fxScrollIndex > 0) {
				slideContent.fxScrollIndex--;
				slideContent.fxScroll.toElement(slideContent.li[slideContent.fxScrollIndex]);
				rightBtn.setOpacity(1);
				if (slideContent.fxScrollIndex == 0) {
					leftBtn.setOpacity(0.5);
				}
			}
		});
	}
	//
	var rightBtn = slideContent.getNext().getFirst();
	if (rightBtn) {
		rightBtn.addEvent("click", function(e){
			new Event(e).stop();
			if (slideContent.fxScrollIndex < slideContent.li.length-5) {
				slideContent.fxScrollIndex++;
				slideContent.fxScroll.toElement(slideContent.li[slideContent.fxScrollIndex]);
				leftBtn.setOpacity(1);
				if (slideContent.fxScrollIndex == slideContent.li.length-5) {
					rightBtn.setOpacity(0.5);
				}
			}
		});
	}
	//
	if (slideContent.li.length <=5 ) {
		leftBtn.setOpacity(0);
		rightBtn.setOpacity(0);
	}
}
//////////
function opaceIt(thisObj, opaceTo) {
	if (!thisObj) return;
	if (opaceTo != 0) {
		thisObj.setStyles({
			display:'block'
		}).setOpacity(0);
	}
	var myEffects = new Fx.Style(thisObj, "opacity", {
		duration:400, 
		transition:Fx.Transitions.quadInOut
	});
	myEffects.start(opaceTo);
}

/////////////run text /////////////////////
var initSlogan = function(){
	try {
		var frame = $("slogan");
		if (!frame) return;
		//
		
		var news = new Element("span");
		
		if (frame.innerHTML.trim() == '') {
			news.innerHTML = frame.getNext().innerHTML;
			frame.getNext().remove();
		} else {
			if ($E('p', frame)) {
				news.innerHTML = $E('p', frame).innerHTML;
				$E('p', frame).remove();	
			}
		
			news.innerHTML += frame.innerHTML;
			frame.innerHTML = '';		
		}
		
		news.injectInside(frame);
		news.setStyle('width', news.getCoordinates().width);
		news.setStyles({
			position: "absolute"
		});
		
		initSlogan.sliderFx = new Fx.Style(news, "bottom", {
			transition: Fx.Transitions.linear,
			duration: Math.sqrt($E('span', frame).innerHTML.length * 3000) * 20,
			onComplete: function(){
				//slideIt();
				initSlogan.sliderFx.start(frame.getParent().getCoordinates().height, -$E('span', frame).getCoordinates().height);
			}
		});
		
		initSlogan.sliderFx.start(frame.getParent().getCoordinates().height, -$E('span', frame).getCoordinates().height);
		/*
		return;
		
		//
		function slideIt(){

			initSlogan.sliderFx.stop();
			initSlogan.sliderFx.options.duration = Math.sqrt($E('span', frame).innerHTML.length * 3000) * 20;
			//initSlogan.sliderFx.start(frame.getParent().getCoordinates().width, -$E('span', frame).getCoordinates().width);
			initSlogan.sliderFx.start(frame.getParent().getCoordinates().height, -$E('span', frame).getCoordinates().height);
			
		}
		//
		slideIt();
		*/
	} catch (e) {
	}
}
//////////////
////////////////
function fShowConent(idCont, idActive)
{
	if (idCont.className == "")
	{
		idActive.setText("More");
		idCont.addClass("moreFacilities");
	}
	else if (idCont.className == "moreFacilities")
	{
		idActive.setText("Hide");
		idCont.removeClass("moreFacilities");
		
	}
}

function getVNTime() {
	var phphours = 7;
	//if (typeof GMTTime != 'undefined') {
	//	alert(GMTTime);
	//}
	var time_dig = new Date();
	var seconds_dig = time_dig.getUTCSeconds();
	var minutes_dig = time_dig.getUTCMinutes();
	var hours_dig = time_dig.getUTCHours();
	
	var hours_dig_new = hours_dig + phphours + parseInt(minutes_dig / 60);
	
	if (hours_dig_new > 23) {
		hours_dig_new = hours_dig_new - 24;
		time_dig.setTime(time_dig.getTime() + 24 * 60 * 60 * 1000);
	} else if (hours_dig_new < 0) {
		hours_dig_new = hours_dig_new + 24;
		time_dig.setTime(time_dig.getTime() - 24 * 60 * 60 * 1000);
	}
	
	var weekday = time_dig.getUTCDay();
	var day = time_dig.getUTCDate();
	var month = time_dig.getUTCMonth();
	var year = time_dig.getUTCFullYear();
	
	return weekday + ',' + day + ',' + month + ',' + year + ',' + hours_dig_new + "," + minutes_dig + "," + seconds_dig;
}

function initWinsorFlashClock(){
	
	var times=getVNTime();
	var dates=times.split(",");
	var clock = $('clock');
	
	var arrMonth = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
	var dateTag = clock.getNext().getNext();
	dateTag.innerHTML = "Date: " + arrMonth[dates[2]] + " " + dates[1] + ", " + dates[3];
	
	/*
	var clock= new SWFObject("flash/WinsorClock.swf", "wClock", "40", "35", "8", "#000000");
	clock.skipDetect = true;
	clock.addParam('type','application/x-shockwave-flash');
	clock.addParam('allowscriptaccess','sameDomain');
	clock.addParam('wmode','transparent');
	clock.addVariable('hour',dates[4]);
	clock.addVariable('minute',dates[5]);
	clock.addVariable('second',dates[6]);
	//clock.addVariable('detectflash',false);

	clock.write("clock");
	*/
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		clock.innerHTML = AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '40',
			'height', '35',
			'src', 'flash/WinsorClock',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'transparent',
			'devicefont', 'false',
			'id', 'flashclock',
			'bgcolor', '#000000',
			'name', 'flashclock',
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'movie', 'flash/WinsorClock',
			'salign', '',
			'FlashVars', 'hour=' + dates[4] + '&minute=' + dates[5] + '&second=' + dates[6]
			); //end AC code
	}	
	
	/*
	var root=window.location;
	var protocol=root.protocol;
	var host=root.host;
	var path=root.pathname;
	
	var url=protocol+"//"+host+path+"index.php?controller=static&nav1=time";
	//alert(url);
	var ajaxClock=new Ajax(url,{method:'get',
		onComplete:function(){
			
			var date=this.response.text;
			var dates=date.split(":");
			
			clock.addVariable('hour',dates[0]);
			clock.addVariable('minute',dates[1]);
			clock.addVariable('second',dates[2]);
			
			clock.write("clock");
		}
	});
	
	ajaxClock.request();*/
}	