// rooms galleries vars
	thumbsOffset = new Array();
	thumbsHeight = new Array();
	thumbsDnLimit = new Array();
$(function(){
// sidenav hover in ie6
	if($('#sidenav').length > 0 && jQuery.browser.msie) {
		$('#sidenav li')
			.mouseenter(function(){$(this).addClass('sfhover')})
			.mouseleave(function(){$(this).removeClass('sfhover')});
	}

// nav hover in ie6
	if($('#nav').length > 0 && jQuery.browser.msie) {
		$('#nav li')
			.mouseenter(function(){$(this).addClass('sfhover')})
			.mouseleave(function(){$(this).removeClass('sfhover')});
	}

// opacity on nav
//	$('#nav li ul a').css("opacity", "0.9");

// homepage main image area tabs
	$('.main_image_area #tabs a').click(function() {
		if($(this).parent().hasClass('on')) {
			return;
		}
		ind = $('.main_image_area #tabs a').index($(this));
		$('.main_image_area #tabs li').removeClass();
		$(this).parent().addClass('on');
		$('.main_image_area .item.on').css({zIndex: '5'});
		$('.main_image_area .item:eq('+ind+')').css({zIndex: '10'}).fadeIn(function(){
				$('.main_image_area .item.on').removeClass('on').css({display: 'none'});
				$(this).addClass('on');
		});
		return false;
	});

// gallery on spa page
	if ($(".gallery_nav a").length > 0) {
		$(".gallery_nav a").fancybox({
				'easingIn':300,
				'easingOut':300,
				'overlayShow':true,
				'imageScale':false,
				'overlayOpacity': 0.3
			});
		}
		
// gallery on spa page
	if ($(".photo_video_nav a").length > 0) {
		$(".photo_video_nav a").fancybox({
				'easingIn':300,
				'easingOut':300,
				'overlayShow':true,
				'imageScale':false,
				'overlayOpacity': 0.3
			});
		}

	if ($(".enlarge").length > 0) {
		$(".enlarge").fancybox({
				'easingIn':300,
				'easingOut':300,
				'overlayShow':true,
				'imageScale':false,
				'overlayOpacity': 0.3
			});
		}

// mid area tabs
	$('.mid_tabs a').click(function() {
		if($(this).parent().hasClass('on')) {
			return false;
		}

		ind = $('.mid_tabs a').index($(this));
		$('.mid_tabs li').removeClass('on');
		$(this).parent().addClass('on');
		$('.m_tabs_content .m_item.on').css({zIndex: '5'});
		$('.m_tabs_content .m_item:eq('+ind+')').css({zIndex: '10'}).fadeIn(function(){
			$('.m_tabs_content .m_item.on').removeClass('on').css({display: 'none'});
			$(this).addClass('on');
			if(typeof(thumbsOffset[ind]) == "undefined") {
				thumbsOffset[ind] = 0;
				thumbsHeight[ind] = $('.m_thumb_area:eq('+ind+')').height() + 5;
				thumbsDnLimit[ind] = -1*(thumbsHeight[ind] - thumbHeight*thumbsVisible);
			}
		});
		newHeight = $('.m_tabs_content .m_item:eq('+ind+')').height();
		$('.m_tabs_content').animate({height: newHeight+'px'});
		return false;
	});
// calendar
	$('#checkin').datepicker({
		showOn: 'button',
		buttonImage: calIcon,
		buttonImageOnly: true,
		minDate: +0,
		maxDate: '+1Y',
		onSelect: function(dateText, inst) {
			md = $(this).datepicker('getDate');
			md.setDate(md.getDate() + 1);
			$('#checkout').datepicker('option', 'minDate', md);
		}
	});
	$('#checkout').datepicker({
		showOn: 'button',
		buttonImage: calIcon,
		buttonImageOnly: true,
		minDate: +1,
		maxDate: '+1Y +1D'
	});
	$('#datepicker_572_id').datepicker({
		showOn: 'button',
		buttonImage: calIcon,
		buttonImageOnly: true,
		minDate: +1,
		maxDate: '+1Y +1D'
	});
	$('#datepicker_408_id').datepicker({
		showOn: 'button',
		buttonImage: calIcon,
		buttonImageOnly: true,
		minDate: +0,
		maxDate: '+1Y',
		onSelect: function(dateText, inst) {
			md = $(this).datepicker('getDate');
			md.setDate(md.getDate() + 1);
			$('#datepicker_409_id').datepicker('option', 'minDate', md);
		}
	});
	$('#datepicker_409_id').datepicker({
		showOn: 'button',
		buttonImage: calIcon,
		buttonImageOnly: true,
		minDate: +1,
		maxDate: '+1Y +1D'
	});
	$('#datepicker_573_id').datepicker({
		showOn: 'button',
		buttonImage: calIcon,
		buttonImageOnly: true,
		minDate: +1,
		maxDate: '+1Y +1D'
	});
	$('#datepicker_426_id').datepicker({
		showOn: 'button',
		buttonImage: calIcon,
		buttonImageOnly: true,
		minDate: +0,
		maxDate: '+1Y',
		onSelect: function(dateText, inst) {
			md = $(this).datepicker('getDate');
			md.setDate(md.getDate() + 1);
			$('#datepicker_427_id').datepicker('option', 'minDate', md);
		}
	});
	$('#datepicker_427_id').datepicker({
		showOn: 'button',
		buttonImage: calIcon,
		buttonImageOnly: true,
		minDate: +1,
		maxDate: '+1Y +1D'
	});
});

$(window).load(function () {
// startHeight of m_tabs_content
	startHeight = $('.m_item').height();
	$('.m_tabs_content').animate({height: startHeight+'px'});
	
	

// photo gallery on the rooms pages
	thumbHeight = 70;
	thumbsVisible = 3;
	thumbsOffset[0] = 0;
	thumbsHeight[0] = $('.m_thumb_area:eq(0)').height() + 5;
	thumbsDnLimit[0] = -1*(thumbsHeight[0] - thumbHeight*thumbsVisible);

	// thumbs scrolling and fading
	$('.r_controls .down').click(function(){
		ind = $('.r_controls .down').index($(this));
		if ((thumbsOffset[ind]-thumbHeight) >= thumbsDnLimit[ind]) {
			thumbsOffset[ind] -= thumbHeight;
			$(this).parents('.r_controls').children('.mt_container').children('.m_thumb_area').animate({marginTop: thumbsOffset[ind]+'px'});
		}
	});
	$('.r_controls .up').click(function(){
		ind = $('.r_controls .up').index($(this));
		if ((thumbsOffset[ind]+thumbHeight) <= 0) {
			thumbsOffset[ind] += thumbHeight;
			$(this).parents('.r_controls').children('.mt_container').children('.m_thumb_area').animate({marginTop: thumbsOffset[ind]+'px'});
		}
	});
	$('.m_thumb_area li.on img').animate({opacity: '0.8'});
	$('.m_thumb_area img')
		.mouseenter(function(){ if($(this).parents('li').hasClass('on')) {return} $(this).stop(true,true).animate({opacity: '0.8'}); })
		.mouseleave(function(){ if($(this).parents('li').hasClass('on')) {return} $(this).stop(true,true).animate({opacity: '1'}); });
	// image change
	$('.m_thumb_area a').each(function(){
		ind = $('.m_thumb_area a').index($(this));
		src=$(this).attr('href');
		hrf=$(this).parents('.mid_gallery').children('.m_image_container').children('a').attr('href');
		$(this).parents('.mid_gallery').children('.m_image_container').append('<a href=""><img style="display:none" class="img'+ind+'" src="'+src+'" alt=""/></a>');
	});
	$('.m_thumb_area li').click(function(){
		if($(this).hasClass('on')) {
			return false;
		}
		indPrev = $('.m_thumb_area li').index($(this).siblings('.on'));
		$(this).siblings('.on').removeClass().children('a').children('img').animate({opacity: '1'});
		$(this).addClass('on');
		ind = $('.m_thumb_area li').index($(this));
		$(this).parents('.mid_gallery').children('.m_image_container').children('a').children('img.img'+ind).css({zIndex: '5'}).fadeIn('fast', function(){
			$(this).parents('.mid_gallery').children('.m_image_container').children('a').children('img.img'+indPrev).css({zIndex: '1', display: 'none'});
		});
		return false;
	});
});

// external links
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}
function init() {
	externalLinks();
}
window.onload = init;

