
$(document).ready(function(){
	// $('.offer h3 a').each(function () {
		// ($(this).height()<$(this).parents('h3').height())?$(this).css({'line-height':'34px'}):$(this).height();
	// });
	
	$('.totop').click(function () {
		scroll(0,0);
		return false;
	});
	
	$('#information p:odd').addClass('odd');
	$('#description p:odd').addClass('odd');
	
	$('input:text, input:password, textarea').focus(function () {
		if ($(this).val()==$(this).attr('sval')) $(this).val('');
		$(this).removeClass('invalid');
		$(this).addClass('active');
		$(this).parents('p').find('.err').removeClass('err');
		$(this).parents('p').find('.msg').remove();
	});
	$('input:text, input:password, textarea').blur(function () {
		if ($(this).val()=='') $(this).val($(this).attr('sval'));
		$(this).removeClass('active');
	});

	$('.translations a, .box a img, .offer a img').animate({opacity: 1},0);
	$('.translations a, .box a img, .offer a img').mouseover(function () { $(this).stop().animate({ opacity: .8 }, 200); });
	$('.translations a, .box a img, .offer a img').mouseout(function () { $(this).stop().animate({ opacity: 1 }, 200); });	
	
	$('#thumbnails li:first-child a').addClass('current');
	$('#thumbnails a img').not('#thumbnails a.current img').animate({opacity: .3},0);
	$('#thumbnails a.current img').animate({opacity: 1},0);
	$('#thumbnails a img').mouseover(function () { 
		if ($(this).parents('a').hasClass('current')) {
			return false;
		} else {
			 $(this).animate({ opacity: 1 }, 200);
		}
	});
	$('#thumbnails a img').mouseout(function () { 
		if ($(this).parents('a').hasClass('current')) {
			return false;
		} else {
			 $(this).animate({ opacity: .3 }, 200);
		}
	});
	$('#photos a').first().addClass('current');
	$('#photos a').not('#photos a.current img').hide();
	$('#photos a.current').show();
	
	var thumbs_h = 0;
	$('#thumbnails li').each( function(){
		thumbs_h += $(this).outerHeight(true);
	});
	$('#thumbnails .thumb_cont_in').height( thumbs_h );
	$('#thumbnails li a').click(function () {
		if ($(this).hasClass('current')) {
			
		} else {
			$('#photos a:eq('+$('#thumbnails a.current').parents('li').index()+')').hide();
			$('#thumbnails a').removeClass('current');
			$('#thumbnails a img').animate({opacity: .3},0);
			$(this).addClass('current');
			$('#thumbnails a.current img').animate({opacity: 1},0);
			$('#photos a:eq('+$('#thumbnails a.current').parents('li').index()+')').show();
		}
		
		var y = $(this).position().top;
		if ($(this).closest('li').prev().length > 0) {
			y -= $(this).closest('li').prev().outerHeight(true);
		}
		$('#thumbnails .thumb_cont_out').animate( {scrollTop:y}, 'slow' );

		return false;
	});
	/*
	$('#thumbnails li:gt(3)').addClass('hide');
	$('#thumbnails li:lt(4)').addClass('show');
	qty = $('#thumbnails li').size()-1;
	if ($('#thumbnails li.show').first().index()==0) $('#thumbnails_prev').addClass('disabled');
	if (qty<4) $('#thumbnails_next').addClass('disabled');
	*/
	$('#thumbnails_prev').click(function () {
		if ($('#thumbnails li a.current').closest('li').prev().length > 0) {
			$('#thumbnails li a.current').closest('li').prev().find('a').trigger('click');
		}

		return false;
	});
	$('#thumbnails_next').click(function () {
		if ($('#thumbnails li a.current').closest('li').next().length > 0) {
			$('#thumbnails li a.current').closest('li').next().find('a').trigger('click');
		}

		return false;
	});
	
	$('.navigation li').hoverIntent(hoverIn,hoverOut,{sensitivity: 1,timeout: 100});
	
	if ( $.browser.opera ) {
	}		
	if ( $.browser.msie ) {
		var i;
		for (i in document.images) {
			if (document.images[i].src) {
				var imgSrc = document.images[i].src;
				if (imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG') {
					document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
				}
			}
		}
	} 	
	if ( /chrome/.test( navigator.userAgent.toLowerCase() ) ) {
		$('.phone').css({'font-size':'14px', 'word-spacing':'-2px', 'letter-spacing':'-1px'});
	} 	
	if ( /safari/.test( navigator.userAgent.toLowerCase() ) ) {
	} 	
	
	$( '.datepicker' ).datepicker({ 
			showOn: 'both',
			buttonImage: '/commonResources/img/iconSets/aestetica/24x24/calendar_date.png',
			buttonImageOnly: true,
			autoSize: true,
			dateFormat: 'yy-mm-dd'
	});
	
	$( '.datepicker2' ).datepicker({ 
			showOn: 'focus',
			showButtonPanel: false,
			autoSize: true,
			dateFormat: 'yy-mm-dd'
	});
	
	$('form').each( function(){
		$(this).append(
			$('<input/>').attr({
				'name': '_jsval',
				'type': 'hidden'
			}).val( '1' )
		);
	});
	
	/*
	$("#ask").validate({	
		rules: {
			ask_email: {
				required: true,
				email: true
			},
			ask_qty: {
				required: true,
				minlength: 1,
				digits: true
			}
		},
        errorPlacement: function(error, element) {
            error.appendTo( element.parents('p') );
        }
	});
	*/
	
	$("#contact_form").validate();
	$("#reservation_form").validate();
	
	fancyboxInit();
});

function hoverIn(){ $(this).children('ul').animate({height: 'toggle'}, 400);}
function hoverOut(){ $(this).children('ul').animate({height: 'toggle'}, 400);}

function fancyboxInit(){ 
	$('.fancybox, #photos a').fancybox({
		'scrolling': 'no', 
		'titleShow': true, 
		'titlePosition': 'inside', 
		'overlayOpacity':'.7',
		'overlayColor':'#000'//, 'onComplete': 
	});
}
