$(document).ready(function(){

	$('.body-inner').find('table').each(function(){
		if(!/bez-ramja-tabula/.test($(this).attr('className'))) {
			if(!/tabula-bez-galvenes/.test($(this).attr('className'))){
				$($(this).find('tr').get(0)).addClass('first')
			}else{
				$($(this).find('tr').get(0)).css({'border-top-width':'2px'})
			}
			var rows=$(this).find('tr');
			$($(rows).get($(rows).size()-1)).addClass('table-last-row');
		}
	});
	
	$('#building_type').change(function(){
		$('#room_type>option').remove();
		var si=$(this).attr('selectedIndex');
		$('#room_number').attr('disabled',0);
		if(buildings[si]){
			var op=buildings[si];
			for(var i=0;op.length>i;i++){var v=op[i];$('<option value="'+v+'">'+v+'</option>').appendTo($('#room_type'));}
		}
	});
	$('#room_type').change(function(){
		var op=buildings[$('#building_type').attr('selectedIndex')];
		var si=$(this).attr('selectedIndex');
		$('#room_number').attr('disabled',(op.length==(si+1)));
	});
	
	try{
		$('#close').click(function(event){
			event.preventDefault();
			var m=parseFloat($('#content').width()*-1);
			$('#content').animate({marginLeft : m},600)
		});	
	}catch(e){}
	
	try{initBookingForm()}catch(e){}
	try{initGallery()}catch(e){}
	if($('#pageContent').size()){$('.print').click(function(){initPrintButton()})}
	
	$($('.submenu').get(0)).css('margin-left','-40px');
	$('.submenu').each(function(){
		$(this.parentNode).hover(
			function(){
				$($(this).find('a').get(0)).addClass('hover');
				$(this).addClass('active')
			},
			function(){
				$($(this).find('a').get(0)).removeClass('hover');	
				$(this).removeClass('active')
			}
		);
	});
	$('.subsubmenu').each(function(){
		$(this.parentNode).hover(function(){$(this).addClass('subactive')},function(){$(this).removeClass('subactive')});
	});

	$('#pageMiddle').height($(document).height()-$($('.container>.head').get(0)).height()-$($('.container>foot').get(0)).height()-210);
	$('.target').attr({'target':'_blank'});
	$('.container').height($(document).height());
	$('#subscribe_form').submit(function(){
		if(!isMail($('#subscribeInput').val())){
			alert(lng[1]);
			return false;
		}else{
			alert(a2('act=addEMail&mail='+urlencode($('#subscribeInput').val()),'ajax'));
			$(this).val($(this).attr('rel'));
			return false;
		}
	});
	$('#subscribeInput')
		.bind('focus',function(){if($(this).attr('rel')==$(this).val())$(this).val('')})
		.bind('blur',function(){if($(this).val()=='')$(this).val($(this).attr('rel'))});
	setcalendar();
	
	var h=$(document).height()-$('.container>.head').height()-$('.container>.foot').height()-40;
	if($('#pageMiddle').height()<h){$('#pageMiddle').height(h)}
	
	$('input[type=submit]').hover(function(){$(this).addClass('act')},function(){$(this).removeClass('act')});
	

});
