//Promo banners jumping
$(document).ready(
	function()
	{
		var frontpagePromo = $( 'div.calloutsBlock_design_l' );
		var animating = false;
		if( $( frontpagePromo ) )
		{
			$( frontpagePromo ).mouseenter(
				function()
				{
					if(!animating)
					{
						$(this).animate({'margin-bottom': 23}, 200);
					}
				}
			);
			$( frontpagePromo ).mouseleave(
				function()
				{
					animating = true;
					$(this).animate({'margin-bottom': 13}, 300, function(){animating=false;});
				}
			);
		}
	}
);
//Properties bar

$( document ).ready(
	function()
	{
		var openProperties = $( "#utility_navigation>a.properties" );
		var closeBar = $("#properties_bar a.close_bar, #mainarea");
		var propertiesBar = $( "#properties_bar" );
		if( openProperties.length > 0 )
		{
			$( openProperties ).click(
				function(e)
				{
					$( propertiesBar ).slideDown(500);
					return false;
				}
			);
			$( closeBar ).click(
				function(e)
				{
					$( propertiesBar ).slideUp(300);
				}
			);
		}
	}
);

//Main menu
$( document ).ready(
	function()
	{
		var menuElements = $( "#mainmenu>li" );
		var menuHeight = $( "#mainmenu" ).height();
		if( menuElements.length > 0 )
		{
			$( menuElements ).each(
				function(index, item)
				{
					if($( item ).children( 'div.secondlevel_position' ))
					{
						$( item ).children( 'div.secondlevel_position' ).css('visibility', 'hidden').show();
						var menuSubElementsHeight = $( item ).children( 'div.secondlevel_position' ).height();
						$( item ).children( 'div.secondlevel_position' ).hide().css('visibility', 'visible');
						if( menuHeight - ($( item ).position().top+ menuSubElementsHeight) < 0 )
						{
							$( item ).children( 'div.secondlevel_position' ).css({'top':'auto','bottom':0});
						}
					}
				}
			);
			$( menuElements ).mouseenter(
				function(e)
				{
					if($( this ).children( 'div.secondlevel_position' ))
					{
						$( this ).find( 'div.secondlevel_position' ).show();
					}
				}
			);
			$( menuElements ).mouseleave(
				function(e)
				{
					if($( this ).children( 'div.secondlevel_position' ))
					{
						$( this ).find( 'div.secondlevel_position' ).hide();
					}
				}
			);
		}
	}
);
//Main menu coloring
$( document ).ready(
	function()
	{
		var menuColoredElements = $( "#mainmenu>li.has_children" );
		var subMenuElements = $( 'ul.secondlevel>li' );
		if( menuColoredElements.length > 0 )
		{
			$( menuColoredElements ).mouseenter(
				function(e)
				{
					$( this ).addClass('hoverli');
					$( "#mainmenu>li:not(.hoverli) div.main_item span.main" ).hide();
					$( "#mainmenu>li:not(.hoverli) div.main_item span.replaced" ).show();
					$( subMenuElements ).mouseenter(
						function(e)
						{
							$( this ).addClass( 'hoverli_2' );
							$('ul.secondlevel>li:not(.hoverli_2) span.main').hide();
							$('ul.secondlevel>li:not(.hoverli_2) span.replaced').show();
						}
					);
					$( subMenuElements ).mouseleave(
						function(e)
						{
							$('ul.secondlevel>li:not(.hoverli_2) span.replaced').hide();
							$('ul.secondlevel>li:not(.hoverli_2) span.main').show();
							$( this ).removeClass( 'hoverli_2' );
						}
					);
				}
			);
			$( menuColoredElements ).mouseleave(
				function(e)
				{
					$( "#mainmenu>li:not(.hoverli) div.main_item span.replaced" ).hide();
					$( "#mainmenu>li:not(.hoverli) div.main_item span.main" ).show();
					$( this ).removeClass('hoverli');
				}
			);
		}
	}
);

//Left navigation MAP Popup
$( document ).ready(
	function()
	{
		var openMap = $( "#mapview" );
		var mapBox = $("#mapview div.map_popup");
		var animating = false
		if( $( '#mapview' ).length > 0 )
		{
			$( openMap ).mouseenter(
				function(e)
				{
						$( '#mapview a.view_map' ).addClass( 'active' );
						$( mapBox ).css('visibility','visible');						
				}
			);
			$( openMap ).mouseleave(
				function(e)
				{
					if( window.mapLightboxOpened === false ) {
						$( mapBox ).css('visibility','hidden');						
						$( '#mapview a.view_map' ).removeClass( 'active' );	
					}
				}
			);
		}
	}
);

//accomodation lightbox
$(document).ready( function() {
	var accomodationLink = $('#accomodation_lightbox_link');
	if( accomodationLink.length > 0 )
	{	
		$('#accomodation_lightbox_link').click(function(){ 
			var lightboxContent=$('div.accomodation_lightbox').clone();
			$(lightboxContent).appendTo('#accomodation_lightbox_content_body');
			$(lightboxContent).show();
			$('#accomodation_lightbox_content_body').fadeIn(1000);
			return false;
		});
		$('a.close_lightbox').live('click',function(){ 
			$('#accomodation_lightbox_content_body').fadeOut(1000);
			$('#accomodation_lightbox_content_body').html('');
			return false;
		});
	}
} );

//suites gallery
$( document ).ready(
	function()
	{
		var generalBlock = $( 'div.suites_slider' );
		var generalBlockWidth = $( 'div.suites_slider' ).width();
		var galleryItems = $( 'div.suites_slider div.suite' );
		var controlLeft = $( 'div.suites_slider a.previous' );
		var controlRight = $( 'div.suites_slider a.next' );
		var previousActiveItem = 0;
		var currentActiveItem = 0;
		if( galleryItems.length > 0 )
		{
			var tempWidth = $( galleryItems[currentActiveItem] ).children( 'div.suite_title' ).width();
			$( galleryItems[currentActiveItem] ).children( 'div.suite_title' ).animate( { 'left': ( generalBlockWidth - tempWidth ) / 2 }, 200 );
			$( controlLeft ).click(
				function( event )
				{
					currentActiveItem--;
					if( currentActiveItem < 0 )
					{
						currentActiveItem = galleryItems.length - 1;
					}
					$( galleryItems[previousActiveItem] ).fadeOut( 600 );
					$( galleryItems[currentActiveItem] ).fadeIn( 600 );
					var tempWidth = $( galleryItems[currentActiveItem] ).children( 'div.suite_title' ).width();
					$( 'div.suite_title' ).animate( { 'left': ( generalBlockWidth - tempWidth ) / 2 }, 200 );
					previousActiveItem = currentActiveItem;
					return false;
				}
			);
			$( controlRight ).click(
				function( event )
				{
					currentActiveItem++;
					if( currentActiveItem == galleryItems.length )
					{
						currentActiveItem = 0;
					}
					$( galleryItems[previousActiveItem] ).fadeOut( 600 );
					$( galleryItems[currentActiveItem] ).fadeIn( 600 );
					var tempWidth = $( galleryItems[currentActiveItem] ).children( 'div.suite_title' ).width();
					$( 'div.suite_title' ).animate( { 'left': ( generalBlockWidth - tempWidth ) / 2 }, 200 );
					previousActiveItem = currentActiveItem;
					return false;
				}
			);
		}
	}
);

//packages scroller
$( document ).ready(
	function()
	{
		var visibleHeight = $( 'div.package_items' ).height();
		var generalPackagesBlock = $( 'div.package_items_content' );
		var packageItems = $( 'div.package_items_content div.pk_item' );
		var packageControlLeft = $( 'div.packages_switcher a.previous' );
		var packageControlRight = $( 'div.packages_switcher a.next' );
		var mouseStatus = { 'left': false, 'right': false, 'moving': false, 'firstPos': 0, 'currentPos': 0 };
		var defaultInertion = 5;
		var currentTop = 0;
		var currentInnertion = 0;
		if( ( visibleHeight > 0 ) && ( packageItems.length > 0 ) )
		{
			function update()
			{
				if( mouseStatus.moving )
				{
					var tempHeight = mouseStatus.currentPos - mouseStatus.firstPos;
					currentInnertion += ( tempHeight / 5 );
					
					mouseStatus.firstPos = mouseStatus.currentPos;
				}
				else
				{
					if( mouseStatus.left )
					{
						currentInnertion = defaultInertion;
					}
					if( mouseStatus.right )
					{
						currentInnertion = -defaultInertion;
					}
				}
				if( currentInnertion != 0 )
				{
					currentTop += currentInnertion;
					if( currentInnertion > 0 )
					{
						currentInnertion -= 0.06;
					}
					else
					{
						currentInnertion += 0.06;
					}
					if( Math.abs( currentInnertion ) < 0.1 )
					{
						currentInnertion = 0;
					}
				
					if( currentTop < visibleHeight - $( generalPackagesBlock ).height() )
					{
						currentTop = visibleHeight - $( generalPackagesBlock ).height();
						currentInnertion = 0;
					}
					if( currentTop > 0 )
					{
						currentTop = 0;
						currentInnertion = 0;
					}
					$( generalPackagesBlock ).css( 'top', currentTop );
				}
			}
			var scrollUpdater = window.setInterval( update, 20 );
			
			$( packageControlLeft ).click(
				function( event )
				{
					return false;
				}
			);
			
			$( packageControlRight ).click(
				function( event )
				{
					return false;
				}
			);
			
			$( packageControlLeft ).mousedown(
				function( event )
				{
					mouseStatus.left = true;
					return false;
				}
			);
			
			$( packageControlRight ).mousedown(
				function( event )
				{
					mouseStatus.right = true;
					return false;
				}
			);
			
			$( packageControlLeft ).mouseup(
				function( event )
				{
					mouseStatus.left = false;
					return false;
				}
			);
			
			$( packageControlRight ).mouseup(
				function( event )
				{
					mouseStatus.right = false;
					return false;
				}
			);
			
			/*$( generalPackagesBlock ).mousedown(
				function( event )
				{
					mouseStatus.moving = true;
					mouseStatus.firstPos = event.layerY;
					if( $( generalPackagesBlock ).hasClass( 'cursor_1' ) )
					{
						$( generalPackagesBlock ).removeClass( 'cursor_1' );
					}
					$( generalPackagesBlock ).addClass( 'cursor_2' );
					return false;
				}
			);
			$( generalPackagesBlock ).mouseup(
				function( event )
				{
					mouseStatus.moving = false;
					if( $( generalPackagesBlock ).hasClass( 'cursor_2' ) )
					{
						$( generalPackagesBlock ).removeClass( 'cursor_2' );
					}
					$( generalPackagesBlock ).addClass( 'cursor_1' );
					return false;
				}
			);
			
			$( generalPackagesBlock ).mousemove(
				function( event )
				{
					mouseStatus.currentPos = event.layerY;
				}
			);*/
			
		}
	}
);
//Select menu

$( document ).ready(
	function() 
	{
		var bookSelects = $('#nnights, #nadult, #nchild');
		if( bookSelects.length > 0 )
		{
			/*$('#nnights, #nadult, #nchild').selectmenu({'style':'popup', 'maxHeight': 150});
			setTimeout(
			function()
			{
				$('#nchild-menu, #nnights-menu, #nadult-menu').jScrollPane({'showArrows': true, 'animateScroll': true});
			}, 1000
			);*/
			$( bookSelects ).NXCselect().hide();
		}
	}
);
//readmore-readless-AB edit

$(document).ready( function() {
	var readmoreButton = $('a.readmore');
	if( readmoreButton.length > 0 )
	{
		$('a.readmore').click(function(){
			if ($(this).text() == 'read less') {
				$(this).text('read more');
				$("div.columns-frontpage").animate({'margin-top': -11}, 600 ); 
				$('.text-more').slideToggle(300);
				Cufon.replace( 'a.readmore', { fontFamily: "Gotham Medium"});
				if ($(this).hasClass('readless'))
				{
					$(this).removeClass('readless');
				}
			}
			else {
				$(this).text('read less');
				$("div.columns-frontpage").animate({'margin-top': -185}, 600 ).css('z-index', '200'); 
				$('.text-more').slideToggle(300);
				Cufon.replace( 'a.readmore', { fontFamily: "Gotham Medium"});
				$(this).addClass('readless');
			}
			return false;
		
		});
	}
} );

$( document ).ready(
	function()
	{
		var objects = $("a.readmore_service")
		$.each( objects,
			function( index, item )
			{
				$( item ).click(
					function( event )
					{
						if( $( this ).hasClass( 'opened' ) )
						{
							$( this ).removeClass( 'opened' );
							$(this).parents("div.service_item_block").find("div.service_desc").slideUp( 300 );
							var temp = $( this ).attr( 'rel' );
							$( this ).attr( 'rel', $( this ).text() );
							$( this ).text( temp );
							return false;
						}
						else
						{
							$( this ).addClass( 'opened' );
							$(this).parents("div.service_item_block").find("div.service_desc").slideDown( 300 );
							var temp = $( this ).attr( 'rel' );
							$( this ).attr( 'rel', $( this ).text() );
							$( this ).text( temp );
							return false;
						}
					}
				);
			}
		);
		
	}
);

//restaurant menu navigation
$(document).ready(function() {

	// adjust slider height 
	var diff = $('#cosmo .class-menu .menu_description').height() - 35;
	$('#cosmo .menu-content .parts-wrapper, #cosmo .menu-content .parts-wrapper .menu-part').css('height', 557-diff + 'px');
	diff = $('#pantages .class-menu .content-holder').height() - 131;
	$('#pantages .menu-content .parts-wrapper').css('height', 509-diff + 'px');
	$('#pantages .menu-content .parts-wrapper .menu-part').css('height', 509-diff-parseInt($('#pantages .menu-part').css('marginTop')) + 'px');
	// show/hide scroller
	if ( $('.parts-wrapper .sliding-menu').eq(0).height() < $('.parts-wrapper').height() )
		$('.class-menu .scroller').css('display', 'none')
	else $('.class-menu .scroller').css('display', 'block');

	var partw = $('.menu-content .parts-wrapper .menu-part:eq(0)').width();
	$('.menu-content .menu-nav li').click(function() {
		if (!$(this).hasClass('active')) {
			$('.menu-content .menu-nav li').removeClass('active to-left to-right');
			$('.menu-content .parts-wrapper .menu-part').removeClass('active');
			var id = $(this).index();
			$(this).addClass('active')
				.siblings('li').addClass('to-right');
			/*$('.menu-content .menu-nav li').each(function() {
				if ($(this).index() < id)
					$(this).addClass('to-left')
				else if ($(this).index() > id)
					$(this).addClass('to-right');
			});*/
			
			$('.menu-content .parts-wrapper .menu-part').eq(id).addClass('active');
			var wrap_left = - partw * id;
			$('.menu-content .parts-wrapper').animate({left: wrap_left}, 600, function() {
				if ( $('.parts-wrapper .sliding-menu').eq( ( Math.abs( parseInt($('.parts-wrapper').css('left')) ) ) / ($('.parts-holder').width()) ).height() < $('.parts-wrapper').height() )
					$('.class-menu .scroller').css('display', 'none')
				else $('.class-menu .scroller').css('display', 'block')
			});
		}
	});
	$('.class-menu .scroller a').click(function() {
		var l = parseInt($('.parts-wrapper').css('left'));
		l = isNaN(l) ? 0 : l;
		var ind = Math.abs(l) / $('.parts-holder').width();
		var menu = $('.parts-wrapper .sliding-menu').eq(ind);
		$(menu).stop(true, true);
		if ( $(menu).height() < $('.parts-wrapper').height() )
			return false;
		var step = 300;
		var t = parseInt( $(menu).css('top'));
		t = isNaN(t) ? 0 : t;
		if ( $(this).hasClass('next') && ($(menu).height() + t > $('.parts-wrapper').height()) ) {
			step = '-=' + step + 'px';
		} else if ( $(this).hasClass('previous') && (t < 0) ) {
			step = '+=' + step + 'px';
		}
		if (typeof(step) == 'string')
			$(menu).animate({top:step}, 400);
		return false;
	});

	// highlight current menu
	$('.class-menu .menu_description a.button.m_pink').each(function() {
		if ( $(this).attr('href') == document.location.pathname )
			$(this).addClass('pdfbutton');
	});

});
//billboard resize
function billboard_resize() {
	var billboardContainer = $('#billboard');
	var billboardItems = $('#billboard div.billboard-item');
	if( (billboardContainer.length > 0) && (billboardItems.length > 0) ) {
		//var billboardHeight = window.location.pathname.length > 1 ? 726 : 606;
		var billboardWidth = parseInt( $( billboardContainer ).width() );
		billboardItems.each(function() {
			if(billboardWidth < 1500) {
				$(this).width(billboardWidth);
				//$(this).find('img').removeAttr('height').attr('width', billboardWidth);
				//$(billboardContainer).height(( billboardHeight / 1500 ) * billboardWidth);
			} else {
				$(this).width(1500);
				//$(this).find('img').attr('width', 1500);
				//$(billboardContainer).height(billboardHeight);
			}
		});
	}
}
$(document).ready(function() { billboard_resize(); });
$(window).resize(function() { billboard_resize(); });

$(document).ready(function() {

	var objects = $('div.attr_description a[href^="/Shizen-Spa/Services/"]');
	
	$.each( objects,
	function( index, item )
	{ 
				$( item ).click(
		function( event )
		
					{	
						var desc_a_href=$( this ).attr( 'href' );
						
						$( 'a.service_item_a[rel="'+desc_a_href+'"]' ).parents("div.service_item_block").find("div.service_desc").slideDown( 300 );
						a_service_item=$( 'a.service_item_a[rel="'+desc_a_href+'"]' ).parents("div.service_item_block").find("a.readmore_service");
						if( $( a_service_item ).hasClass( 'opened' ) )
						{
							$( a_service_item ).removeClass( 'opened' );
							var temp = $( a_service_item ).attr( 'rel' );
							$( a_service_item ).attr( 'rel', $( a_service_item ).text() );
							$( a_service_item ).text( temp );
						}
						else
						{
							$(  a_service_item ).addClass( 'opened' );
							var temp = $(  a_service_item ).attr( 'rel' );
							$(  a_service_item ).attr( 'rel', $(  a_service_item ).text() );
							$(  a_service_item ).text( temp );
							return false;
						}
						return false; 
					}
		);
	});
});


