window.addEvent("load", function(){
	initImages();
	initSlideShow();
	initMenu();
	initTips();
	/////////////////////////////////////
	var accordion = new Accordion('h3.atStart', 'div.atStart', {
	opacity: false,
	onActive: function(toggler, element){
		toggler.setStyle('color', '#7C4F00');
		toggler.setStyle('background', '#EEE');
		toggler.setStyle('cursor', 'default');
	},
 
	onBackground: function(toggler, element){
		toggler.setStyle('color', '#FFF');
		toggler.setStyle('background', '#C8573A');
		toggler.setStyle('cursor', 'pointer');
	}
	}, $('accordion'));
	//accordion.addSection(newTog, newEl, 0);
	// init photo gallery
	initPhotoGallery();
	
	//Career Step
	initCareerStep();
	//Career Add
	initCareerAdd();
	dayCalculation();
	
});
window.addEvent("domready", function(){
	initAccordionCommon('.faq dt', '.faq dd', 'current');
	initFlashIntro();
	initSpecialOffer();
	
});


function showMore(el){
	el = $(el);
	var divCont = el.getParent().getParent();
	divCont.getElement('.less-content').addClass('hidden');
	divCont.getElement('.more-content').removeClass('hidden');
};

function showLess(el){
	el = $(el);
	var divCont = el.getParent().getParent();
	divCont.getElement('.more-content').addClass('hidden');
	divCont.getElement('.less-content').removeClass('hidden');
};


function bookAction(){
	var frmAction = $('frmReservations');
	var propertyID = $('PropertyID');
	if(frmAction && propertyID){
		frmAction.action = 'https://be.genares.net/' + propertyID.value + '/2?NextPage=room_search';
	}
}

function initSpecialOffer(){
	var tblspecial = $$('.tblspecial a');
	if(tblspecial.length){
		tblspecial.each(function(item){
			setInterval(function(){
				if(item.getStyle('color') == 'red'){
					item.setStyle('color', '');
				}
				else{
					item.setStyle('color', 'red');			
				}
			}, 500);
		});
	}
}
	
function initFlashIntro(){
	if($('flashIntro')){
		showPopupLayer('flashIntro');
	}
}
function initAccordionCommon(selectorToggler, selectorElement, clsActive){    
    var togglers = $$(selectorToggler);
    var elements = $$(selectorElement);
	elements.removeClass('hidden');
    if(togglers.length == elements.length){
        new Accordion(togglers, elements, {
            'show': -1,
            'alwaysHide': true,
            'onActive': function(toggler, element){
                toggler.addClass(clsActive);
            },
            'onBackground': function(toggler, element){
                toggler.removeClass(clsActive);                
            }
        });
    }    		
}

//@Des: add more entry input value
function initCareerAdd(){
	var container = $('frmAplication');
	if(!container){ return ;}
	var btnAddHistory = $('btnAddHistory');
	var btnAddReferee = $('btnAddReferee');
	var btnAddAttached = $('btnAddAttached');
	var historyID  = 0;
	var refereeID = 0;
	var attachedID = 0;
	//add Event Click 
	if(btnAddHistory){
		btnAddHistory.removeEvents().addEvent('click', function(e){
			var e = new Event(e).stop();
			var tempHistory = this.getParent().getPrevious().getElement('ul').clone();			
			if(historyID < 3){
				historyID++;
				tempHistory.setProperty('id', 'history' + historyID).injectInside(this.getParent().getPrevious(), 'bottom');			
				//increase value
				if($('history' + historyID)){
					$('history' + historyID).getElement('li').setHTML(historyID + 1);				
					
					$('history' + historyID).getElement('li.col02').getFirst().id = 'companyName0' + (historyID + 1);
					$('history' + historyID).getElement('li.col02').getFirst().name = 'companyName0' + (historyID + 1);
					
					$('history' + historyID).getElement('li.col03').getFirst().id = 'position0' + (historyID + 1);
					$('history' + historyID).getElement('li.col03').getFirst().name = 'position0' + (historyID + 1);
					
					$('history' + historyID).getElement('li.col04').getFirst().id = 'period0' + (historyID + 1);
					$('history' + historyID).getElement('li.col04').getFirst().name = 'period0' + (historyID + 1);
					
					$('history' + historyID).getElement('li.col05').getFirst().id = 'salary0' + (historyID + 1);
					$('history' + historyID).getElement('li.col05').getFirst().name = 'salary0' + (historyID + 1);
					
					$('history' + historyID).getElement('li.col06').getFirst().id = 'reasonLeaving0' + (historyID + 1);
					$('history' + historyID).getElement('li.col06').getFirst().name = 'reasonLeaving0' + (historyID + 1);
				}
			} else {
				btnAddHistory.getElement('img').setOpacity(0.3);
			}
			
			if(historyID == 3) {
				btnAddHistory.getElement('img').setOpacity(0.3);
			}
		});
	}
	
	/////////////////////////////
	if(btnAddReferee){
		btnAddReferee.removeEvents().addEvent('click', function(e){
			var e = new Event(e).stop();
			var tempReferee = this.getParent().getPrevious().getElement('ul').clone();			
			if(refereeID < 3){
				refereeID++;
				tempReferee.setProperty('id', 'referee' + refereeID).injectInside(this.getParent().getPrevious(), 'bottom');			
				//increase value
				if($('referee' + refereeID)){
					$('referee' + refereeID).getElement('li').setHTML(refereeID + 1);				
					
					$('referee' + refereeID).getElement('li.col02').getFirst().id = 'nameReferee0' + (refereeID + 1);
					$('referee' + refereeID).getElement('li.col02').getFirst().name = 'nameReferee0' + (refereeID + 1);
					
					$('referee' + refereeID).getElement('li.col03').getFirst().id = 'companyReferee0' + (refereeID + 1);
					$('referee' + refereeID).getElement('li.col03').getFirst().name = 'companyReferee0' + (refereeID + 1);
					
					$('referee' + refereeID).getElement('li.col04').getFirst().id = 'positionReferee0' + (refereeID + 1);
					$('referee' + refereeID).getElement('li.col04').getFirst().name = 'positionReferee0' + (refereeID + 1);
					
					$('referee' + refereeID).getElement('li.col05').getElements('input')[0].id = 'supervisorRefereeYes0' + (refereeID + 1);
					$('referee' + refereeID).getElement('li.col05').getElements('input')[0].name = 'supervisorReferee0' + (refereeID + 1);
					$('referee' + refereeID).getElement('li.col05').getElements('label')[0].setProperty('for', 'supervisorRefereeYes0' + (refereeID + 1));
					
					$('referee' + refereeID).getElement('li.col05').getElements('input')[1].id = 'supervisorRefereeNo0' + (refereeID + 1);
					$('referee' + refereeID).getElement('li.col05').getElements('input')[1].name = 'supervisorReferee0' + (refereeID + 1);
					$('referee' + refereeID).getElement('li.col05').getElements('label')[1].setProperty('for', 'supervisorRefereeNo0' + (refereeID + 1));
					
					$('referee' + refereeID).getElement('li.col06').getFirst().id = 'contactAndFoneReferee0' + (refereeID + 1);
					$('referee' + refereeID).getElement('li.col06').getFirst().name = 'contactAndFoneReferee0' + (refereeID + 1);
				}
			} else {
				btnAddReferee.getElement('img').setOpacity(0.3);
			}
			if(refereeID == 3) {
				btnAddReferee.getElement('img').setOpacity(0.3);
			}
		});
	}
	if(btnAddAttached){
		btnAddAttached.removeEvents().addEvent('click', function(e){
			var e = new Event(e).stop();
			var tempddAttached = this.getParent().getPrevious().getElement('p').clone();			
			if(attachedID < 3){
				attachedID++;
				tempddAttached.setProperty('id', 'attachedFile' + attachedID).injectInside(this.getParent().getPrevious(), 'bottom');			
				//increase value
				$('attachedFile' + attachedID).getElement('input').id = 'txtDocument0' + (attachedID + 1);
				$('attachedFile' + attachedID).getElement('input').name = 'txtDocument0' + (attachedID + 1);
			} else {
				btnAddAttached.getElement('img').setOpacity(0.3);
			}
			if(attachedID == 3) {
				btnAddAttached.getElement('img').setOpacity(0.3);
			}
		});
	}		
}
function initCareerStep(){
	var tabsOverview = $$('.careerTab');
	if(tabsOverview.length == 0 ) return;
	var arrBtn = tabsOverview[0].getElements('a');
	var arrDiv = $$('.step');	
	if(arrDiv.length == 0) return;
	if(arrBtn.length > 0){
		arrBtn.each(function(btn, index){
			if(index==0){
				arrBtn[index].addClass('active');
				arrDiv[index].removeClass('hidden');
			}
			
			btn.addEvents({
				'click': function(e){
					var e = new Event(e).stop();					
					/*
					arrBtn.removeClass('active');
					arrDiv.addClass('hidden');
					arrBtn[index].addClass('active');
					arrDiv[index].removeClass('hidden');
					*/
				}
			});
			
		});
		/*
		//btn next to step 02
		var btnNext01 = arrDiv[0].getElements('input.btnNextCareer')[0];
		btnNext01.addEvents({
			'click': function(e1){
				var e1 = new Event(e1).stop();
				arrBtn.removeClass('active');
				arrDiv.addClass('hidden');
				arrBtn[1].addClass('active');
				arrDiv[1].removeClass('hidden');
			}
		});
		//btn next to step 03
		var btnNext02 = arrDiv[1].getElements('input.btnNextCareer')[0];
		btnNext02.addEvents({
			'click': function(e1){
				var e1 = new Event(e1).stop();
				arrBtn.removeClass('active');
				arrDiv.addClass('hidden');
				arrBtn[2].addClass('active');
				arrDiv[2].removeClass('hidden');
			}
		});
		*/
		//btn pre back step 01
		var btnPre01 = arrDiv[1].getElements('input.btnPreCareer')[0];		
		btnPre01.addEvents({
			'click': function(e){
				var e = new Event(e).stop();				
				arrBtn.removeClass('active');
				arrDiv.addClass('hidden');
				arrBtn[0].addClass('active');
				arrDiv[0].removeClass('hidden');
			}
		});
		
		
		
		//btn pre back step 02
		var btnPre02 = arrDiv[2].getElements('input.btnSubmit')[0];		
		btnPre02.addEvents({
			'click': function(e){
				var e = new Event(e).stop();				
				arrBtn.removeClass('active');
				arrDiv.addClass('hidden');
				arrBtn[1].addClass('active');
				arrDiv[1].removeClass('hidden');
			}
		});
	}
}
//
// init Career Step
//

//
// init photo gallery
//
function initPhotoGallery() {

	var viewPhoto = $('viewPhotoImage');	
	if(!viewPhoto)
		return;
	viewPhoto.fx = new Fx.Style(viewPhoto, 'opacity');
	
	var slideContent = $$('div.smScrollContent')[0];
	var slideGroup  = $('photoContainer');
	if (slideGroup) {
		var div = $('hScroller');						
		var photoTitle = $('photoTitle');
		var el = slideGroup.getChildren();
		var w = 0;
		var currentPicture = null;		
		var currentPictureIndex = 0;
		var noOfPictures = el.length;
		var imgTag = null;
		var buttonPrev = $('buttonPrev');
		var buttonNext = $('buttonNext');

		el.each(function(item, i){
			if(i == 0)
				currentPicture = item;
			w += 92;							
			item.addEvent("click", function(evt){
				evt = new Event(evt).stop();
				currentPicture.removeClass('selected');
				$(this).addClass('selected');
				imgTag = $(this).getFirst();	
				//new Fx.Styles(imgTag, {duration:500, wait:false}).start({
				//	'opacity': [0,1]
				//});					
				viewPhoto.setProperty('src', imgTag.getProperty('bigsrc'));
				//viewPhoto.fx.set(0);	
				//viewPhoto.fx.start(1);	
				photoTitle.innerHTML = imgTag.getProperty('title');				
				currentPicture = this;
				currentPictureIndex = i;
				if(currentPictureIndex == 0){
					buttonPrev.setStyle('visibility', 'hidden');					
					buttonNext.setStyle('visibility', 'visible');
				}
				else if (currentPictureIndex >= noOfPictures - 1) {
					buttonPrev.setStyle('visibility', 'visible');
					buttonNext.setStyle('visibility', 'hidden');				
				}
				else{
					buttonPrev.setStyle('visibility', 'visible');
					buttonNext.setStyle('visibility', 'visible');
				}	
			});			
		});
		imgTag = currentPicture.getFirst();
		//new Fx.Styles(imgTag, {duration:500, wait:false}).start({
		//	'opacity': [0,1]
		//});						
		currentPicture.addClass('selected');		
		viewPhoto.setProperty('src', imgTag.getProperty('bigsrc'));
		//viewPhoto.fx.set(0);	
		//viewPhoto.fx.start(1);			
		photoTitle.innerHTML = imgTag.getProperty('title');	
		buttonPrev.setStyle('visibility', 'hidden');				
		buttonPrev.addEvent('click', function(evt){
			evt = new Event(evt).stop();
			if(currentPictureIndex == 0){
				return;
			}	
			currentPicture.removeClass('selected');
			currentPicture = currentPicture.getPrevious();	
			currentPicture.addClass('selected');
			currentPictureIndex--;
			imgTag = $(currentPicture).getFirst();
			//new Fx.Styles(imgTag, {duration:500, wait:false}).start({
			//	'opacity': [0,1]
			//});			
			viewPhoto.setProperty('src', imgTag.getProperty('bigsrc'));
			//viewPhoto.fx.set(0);	
			//viewPhoto.fx.start(1);
			photoTitle.innerHTML = imgTag.getProperty('title');
			clearInterval(div.scrollInterval);			
			if(currentPictureIndex == 0){
				$(this).setStyle('visibility', 'hidden');									
			}
			else{
				buttonNext.setStyle('visibility', 'visible');	
			}
		});
		buttonPrev.addEvent("mousedown", function(evt) {
			clearInterval(div.scrollInterval);
			div.scrollInterval = setInterval(function () {
				moveObj(div.fx, -23);
			}, 100);
		});
		buttonPrev.addEvent("mouseout", function(evt) {
			clearInterval(div.scrollInterval);
		});
		buttonNext.addEvent('click', function(evt){
			evt = new Event(evt).stop();	
			if(currentPictureIndex >= noOfPictures - 1){
				return;
			}
			currentPicture.removeClass('selected');
			currentPicture = currentPicture.getNext();	
			currentPicture.addClass('selected');
			currentPictureIndex++;
			imgTag = $(currentPicture).getFirst();
			//new Fx.Styles(imgTag, {duration:500, wait:false}).start({
			//	'opacity': [0,1]
			//});					
			viewPhoto.setProperty('src', imgTag.getProperty('bigsrc'));
			//viewPhoto.fx.set(0);	
			//viewPhoto.fx.start(1);
			photoTitle.innerHTML = imgTag.getProperty('title');		
			clearInterval(div.scrollInterval);	
			if (currentPictureIndex >= noOfPictures - 1) {
				$(this).setStyle('visibility', 'hidden');								
			}	
			else{
				buttonPrev.setStyle('visibility', 'visible');
			}
		});
		buttonNext.addEvent("mousedown", function(evt) {
			clearInterval(div.scrollInterval);
			div.scrollInterval = setInterval(function () {
				moveObj(div.fx, 23);
			}, 100);
		});
		buttonNext.addEvent("mouseout", function(evt) {
			clearInterval(div.scrollInterval);
		});
		slideGroup.setStyle("width", w);
		div.setStyle("display", (w<=600) ? "none" : "block");
		div.scrollInterval = null;
		
		div.fx = new Slider(div.getChildren()[1], div.getChildren()[1].getFirst(), {
			onChange:function (pos){
				if (pos) {
					div.fx.curPos = pos;
					slideFx.set(pos);
				}
			}
		});
		div.fx.curPos = 0;		
		var slideFx = new Slider(slideContent, slideGroup);
		slideContent.removeEvents();
		slideContent.getFirst().removeEvents();
		
		div.getChildren()[0].getFirst().getFirst().addEvent("mousedown", function(evt) {
			clearInterval(div.scrollInterval);
			div.scrollInterval = setInterval(function () {
				moveObj(div.fx, -23);
			}, 100);
		});
		div.getChildren()[0].getFirst().getFirst().addEvent("click", function(evt) {
			clearInterval(div.scrollInterval);
		});
		div.getChildren()[0].getFirst().getFirst().addEvent("mouseout", function(evt) {
			clearInterval(div.scrollInterval);
		});
		div.getChildren()[2].getFirst().getFirst().addEvent("mousedown", function(evt) {
			clearInterval(div.scrollInterval);
			div.scrollInterval = setInterval(function () {
				moveObj(div.fx, 23);
			}, 100);
		});
		div.getChildren()[2].getFirst().getFirst().addEvent("click", function(evt) {
			clearInterval(div.scrollInterval);
		});
		div.getChildren()[2].getFirst().getFirst().addEvent("mouseout", function(evt) {
			clearInterval(div.scrollInterval);
		});
	}
	
	function moveObj(thisObj, thisPos) {
		if ((thisObj.curPos == 0) && (thisPos<0))  return;
		if ((thisObj.curPos == 100) && (thisPos>0)) return;
		thisObj.set(thisObj.curPos+thisPos);
	}				
}


Element.extend({
	getWidth: function(){
		return this.getCoordinates().width
	},
	getHeight: function(){
		return this.getCoordinates().height
	}
});
///////////////////////////////////

function initImages() {	
	//
	document.imageOut = new Object();
	document.imageOver = new Object();
	// PNG Fix for IE<7
	var png_fix = "images/blank.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 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);
}

var fShowLayer = function (oSourceLayer, linkObject){
	$('showDetailMap').innerHTML=oSourceLayer.innerHTML;
	if ($(linkObject)) {
		$('showDetailMap').setStyles({
			top: $(linkObject).getCoordinates().top,
			left: $(linkObject).getCoordinates().left
		});
	}
	opaceIt($('showDetailMap'), 0.9) 
}

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-3) {
				slideContent.fxScrollIndex++;
				slideContent.fxScroll.toElement(slideContent.li[slideContent.fxScrollIndex]);
				leftBtn.setOpacity(1);
				if (slideContent.fxScrollIndex == slideContent.li.length-3) {
					rightBtn.setOpacity(0.5);
				}
			}
		});
	}
	//
	if (slideContent.li.length <=5 ) {
		leftBtn.setOpacity(0);
		rightBtn.setOpacity(0);
	}
}

var initSlideShow = function(){
	return;
	if (!$('photoSlice')) return;
	var img = $('photoSlice').getFirst();
	if (!img) return;
	var aImage = new Array();
	//aImage.push("images/home_header_slice1.jpg");
	aImage.push("images/home_header_slice2.jpg");
	aImage.push("images/home_header_slice3.jpg");
	aImage.push("images/home_header_slice4.jpg");
	aImage.push("images/home_header_slice5.jpg");
	aImage.push("images/home_header_slice6.jpg");
	// aImage.push("images/home_header_slice7.jpg");
	// aImage.push("images/home_header_slice8.jpg");
	// aImage.push("images/home_header_slice9.jpg");
	aImage.push("images/home_header_slice10.jpg");
	
	//
	//img.getParent().setStyle("position", "relative");
	//
	document.slider = new Array();
	document.slideIndex = -1;
	document.sliding = true;
	$A(aImage).each(function(item, i){
		var slideImg = new Element("img").setProperties({
			id: "slide"+i,
			src: item+"?rand="+$time()
		}).setStyles({
			position: "absolute",
			left: "15px",
			top: "33px"
		}).injectAfter(img);
		slideImg.fx = new Fx.Style(slideImg, "opacity", {
			duration: 1000,
			onComplete: function(){
				img.setOpacity(0);
			}
		}).set(0);
		slideImg.addEvent("load", function(e){
			document.slider.push(slideImg);
		});
	});
	//
	document.slideInterval = setInterval(function(){
		slideIt(1);
	}, 6000);
	//
	//
	function slideIt(dir){
		$A(document.slider).each(function(item){
			item.fx.stop();
		});
		if (document.slider[document.slideIndex]) {
			document.slider[document.slideIndex].fx.start(0);
		}
		document.slideIndex += dir;
		if (dir>0) {
			if (document.slideIndex >= $A(aImage).length) document.slideIndex = 0;
		} else {
			if (document.slideIndex < 0) document.slideIndex = $A(aImage).length-1;
		}
		if (document.slider[document.slideIndex]) {
			document.slider[document.slideIndex].fx.start(1);
		}		
	}
}
////////////////////////////////
//
function initMenu(){
	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
			});
			//
			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 (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 initTips(){
	if ($$("a.tip").length == 0) return;
	var body = $$("body")[0];
	var frm = new Element("iframe").setProperties({
		"id": "tipPopupFrame",
		"src": "about:blank",
		"frameborder": "0"
	}).addClass("tipPopupFrame").injectInside(body);
	
	
	var tip = new Element("div").setProperty("id", "tipPopup").addClass("tipPopup").injectInside(body);
	
	tip.fx = new Fx.Style(tip, 'opacity', {
						  duration: 300, 
						  onComplete: function() {
							  if (tip.getStyle('opacity') == 0) {
								  tip.setStyle('visibility', 'hidden');
								  //frm.setStyle("visibility", "hidden");
								  frm.setStyle("display", "none");
								  tip.isShowed = false;
							  }
							}});

	tip.isShowed = false;
	
	//	
	$$("a.tip").each(function(a, i){
		a.addEvent("mouseover", function(evt){
			evt = new Event(evt).stop();
			
			if (tip.isShowed) {
				tip.fx.stop();
				tip.fx.set(0);
				tip.setStyle('visibility', 'hidden');
				//frm.setStyle("visibility", "hidden");
				frm.setStyle("display", "none");
			}
			
			tip.empty();
			//loader.setStyle("visibility", "visible");
			// call AJAX here based on ID of a tag
			var cont = $("detai1_" + i);
			if (cont) {
				tip.setStyles({
					"visibility": "hidden",
					"width": "auto"
				}).setHTML(cont.innerHTML);
			}
			
			//
			tip.setStyles({
				opacity: 0,
				"visibility": "visible",
				"width": tip.getWidth()+"px"
			});
			frm.setProperties({
				"width": tip.getWidth(),
				"height": tip.getHeight()
			}).setStyles({
				opacity: 0,
				filter: "alpha(opacity=0)",
				//"visibility": "visible",
				display: 'block',
				"width": tip.getWidth()+"px",
				"height": tip.getHeight()+"px"
			});
			if(a.hasClass('message_tip')) {
				tip.addClass('message');
			}
			setPosition(evt);
			
			tip.isShowed = true;
			tip.fx.start(1);
		});
		a.addEvent("mouseout", function(e){
			new Event(e).stop();
			//tip.setStyle("visibility", "hidden");
			//frm.setStyle("visibility", "hidden");
			tip.fx.stop();
			tip.fx.set(1);
			tip.fx.start(0);
		//	loader.setStyle("visibility", "hidden");
		
			setPosition(e);
			if(a.hasClass('message_tip')) {
				//tip.removeClass('message');
			}
		});
		
		a.addEvent("mousemove", function(e){
			setPosition(e);
		});
	});
	
	// e - event
	function setPosition(e) {
		var evt = new Event(e);
		var x = (tip.getWidth()+evt.page.x<window.getScrollWidth()-20) ? evt.page.x+10 : evt.page.x-tip.getWidth()-10;
		var y = (tip.getHeight()+evt.page.y<window.getHeight()+window.getScrollTop()-20) ? evt.page.y+10 : evt.page.y-tip.getHeight()-10;
		tip.setStyles({
			top: y,
			left: x
		});
		frm.setStyles({
			"top": y,
			"left": x
		});
	}
	//
	
}
//////
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);
}

function dayCalculation(){
	var day = $('day');
	if(day){
		var month = $('month');
		var year = $('year');
		var result = addDay(day.value, month.value, year.value, 1);		
		day.value = addZero(result[0]);
		month.value = addZero(result[1]);
		year.value = result[2];
	}
	
	var dday = $('dday');
	if(day){
		var dmonth = $('dmonth');
		var dyear = $('dyear');
		var dresult = addDay(dday.value, dmonth.value, dyear.value, 3);		
		dday.value = addZero(dresult[0]);
		dmonth.value = addZero(dresult[1]);
		dyear.value = dresult[2];
	}
	
	function addZero(num){
		if(num<10)
			num = '0'+num;
		return num;
	}
}

function addDay(day, month, year, num){
	var currentTime = new Date()
	var curMonth = currentTime.getMonth() + 1;
	var curDay = currentTime.getDate();
	var curYear = currentTime.getFullYear();
		
	var newMonth = curMonth;
	var newDay = curDay + num;
	var newYear = curYear;
	
	if(curYear % 4 == 0){
		if(curMonth == 2){
			if(curDay + num > 29){
				add(29);
			}
		}
	}else if(curMonth == 2){
		if(curDay + num > 28){
			add(28);
		}
	}else if(curMonth == 1 ||curMonth == 3 ||curMonth == 5 ||curMonth == 7 ||curMonth == 8 ||curMonth == 10 ||curMonth == 12){
		if(curDay + num > 31){
			add(31);			
		}
	}else if(curMonth == 4 ||curMonth == 6 ||curMonth == 9 ||curMonth == 11){
		if(curDay + num > 30){
			add(30);
		}
	}
	
	function add(days){
		newDay = (curDay + num) - days;		
		newMonth = curMonth + 1;		
		if(newMonth > 12){
			newMonth = 1;
			newYear = curYear + 1;
		}		
	}
	
	return [newDay,newMonth,newYear];
}

//show layer
function showPopupLayer(strId, param, param1){
	var that = this;
	var el = $(strId);			
	if(!el)	return;
	var _opacity = 0.5;
	var _color = '#000000';
	new Element('div',{
		'id': 'divPopup'+ strId,
		'styles':{
			'display': 'block',
			'position': 'absolute',
			'top': 0,
			'left': 0,
			'width': window.getWidth() + 'px',				
			'height': window.getSize().scrollSize.y,
			'z-index':5000,
			'backgroundColor': _color,
			'opacity': 0.5
		}
	}).injectInside($$('body')[0]);	
	el.injectInside($$('body')[0]);
	el.setStyle('display', 'block');
	var zIndex = 5001;		
	el.setStyles({		
		'position': 'absolute',
		'top': (window.getHeight() - el.getCoordinates().height)/2 + window.getScrollTop(),
		'left': (window.getWidth() - el.getCoordinates().width)/2 + 'px',
		'z-index': zIndex
	});
	// new Fx.Tween(el).start('opacity', 1).chain(function(){
		// if (el.getElements('input[type=text]').length>0){
			// el.getElements('input[type=text]')[0].focus();
		// }
	// });
	// if(document.body.getSize().scrollSize.y > window.getScrollTop()) {
		// window.removeEvents();
		// window.addEvent('scroll',function(){			
			// if(el){
				// el.setStyle('top',((window.getHeight() - el.getCoordinates().height)/2 + window.getScrollTop() + 'px'));				
				// var width = window.getSize().scrollSize.x;
				// var height = window.getSize().scrollSize.y;
				// if (height < document.body.clientHeight) {
					// height = document.body.clientHeight;
				// }				
				// if($('divPopup'+strId)){
					// $('divPopup'+strId).setStyles({
						// 'width': width, 
						// 'height': height
					// });
				// }
			// }
		// });
	// }
	window.addEvent('resize', function(e){
		var w = window.getWidth();			
		if($('divPopup'+strId)) {
			$('divPopup'+strId).setStyles({
				'width': window.getWidth() + 'px',
				'height': document.body.getScrollSize().y
			});
		}
	});
	//add event close 
	if($$('#' + strId + ' a.btnClose')[0])
		$$('#' + strId + ' a.btnClose')[0].addEvent('click', function(e){
			if (e) new Event(e).stop();
			// new Fx.Tween(el).start('opacity', 0);				
			// setTimeout(function(){
				el.setStyle('top',-1500);
				if(window.ie6) {
					//window.removeEvent('scroll');
				}
			// }, 500);
			if($('divPopup'+strId)) {
				$('divPopup'+strId).remove();
			}			
			//window.removeEvents();
		});			
}
function hideLayer(id){
	if(id && $(id)) $(id).setStyles({
		'top': -1500
	});
	if($('divPopup'+id)) {			
		$('divPopup'+id).remove();
	}		
	if(window.ie6) {
		//window.removeEvent('scroll');
	}
	//window.removeEvents();
}
