jQuery(document).ready(function($) {
	$('.inactive > div').css('top', '-2000px');
	$('#small_boxes_wrap').css('top', '-500px');
	$('#startpage').children().css('bottom', '80px');
	$('#close_menu').hide();
});

var lastSite = 9;
var lastSite_pack = 9;
var toChange = 0;

function show_page(site){
		
	if(site != lastSite){
	
	if(site == 9) { bgimg = 'img/back1.jpg'; window.location = "#rooms_and_rates"; }
	if(site == 1) { bgimg = 'img/back2.jpg'; window.location = "#rooms_and_rates"; }
	if(site == 2) { bgimg = 'img/back3.jpg'; window.location = "#packages"; } 
	if(site == 3) { bgimg = 'img/back4.jpg'; window.location = "#hotel"; } 
	if(site == 30) { bgimg = 'img/back5.jpg'; window.location = "#location"; } 
	if(site == 31) { bgimg = 'img/back31.jpg'; window.location = "#rooms_and_rates"; } 
	if(site == 5) { bgimg = 'img/back5.jpg'; window.location = "#guestbook"; } 
	if(site == 6) { bgimg = 'img/back6.jpg'; window.location = "#rooms_and_rates"; } 
	if(site == 7) { bgimg = 'img/back7.jpg'; window.location = "#contact"; } 
	
	if((site < 10 && site != 4 && site != 8) || site == 30 || site == 0 || site == 31){
		$(".act_bg").attr('src', bgimg);
	}
	
	
		if(lastSite == 9){
			$('.active').children().animate({bottom:'-1800px'}, 1300, 'easeInQuart', function(){
				$('.active').children().css('bottom', '1800px');
				$('.active')
				.addClass('inactive')
				.removeClass('active');
				animate(site);
			});

		} else if(lastSite == 2){
			/*$('#psb').animate({'top':'1800px'}, 1300);*/
			$('.active').children().animate({top:'1800px'}, 1300, 'easeInQuart', function(){
				$('.active').children().css('top', '-2400px');
				$('.active')
				.addClass('inactive')
				.removeClass('active');
				animate(site);
				/*$('#psb').css({'top':'-180px'});*/
			});
		
		} else {
			$('.active').children().animate({top:'1800px'}, 1300, 'easeInQuart', function(){
				$('.active').children().css('top', '-2400px');
				$('.active')
				.addClass('inactive')
				.removeClass('active');
				animate(site);
			});
		
		}
	
		lastSite = site;
	
	} else if(site == 2){
		$('.pack_cont_active').slideUp('slow', function(){$('#pack_cont0').delay(300).slideDown('slow');}); 
		$('.pack_cont_active').addClass('pack_cont_inactive').removeClass('pack_cont_active');
		$('#pack_cont0').addClass('pack_cont_active').removeClass('pack_cont_inactive');
		$('.act_pack').addClass('packs').removeClass('act_pack');
	}
}


function animate(site){
		if(site == 1){
			//$(".act_bg").attr('src', 'img/back2.jpg');
			$('#page_roomsrates').removeClass('inactive').addClass('active');
			$('#page_roomsrates').children().css('top', '-1800px');
			$('#page_roomsrates').children().animate({top:'0px'}, 1300, function(){
				//animateSmall(1);
				animateboxes(rooms);
				switch_bg(1);
				if(psb_active && $('#psb').css('top') == "217px") { psb_active = false; $('#psb').animate({top:'1800px'}, 800, function() { $(this).css({'top':'-1800px'}); }); }
			});
		}
		
		if(site == 2){
			//$(".act_bg").attr('src', 'img/back3.jpg');
			$('#page_packages').removeClass('inactive').addClass('active');
			$('#page_packages').children().css('top', '-1800px');
			$('#page_packages > div').animate({top:'0px'}, 1300, function(){
				//animateSmall(2);
				animateboxes("666 "+packages);
				switch_bg(2);
			});
		}

		if(site == 3){
			//$(".act_bg").attr('src', 'img/back4.jpg');
			$('#page_hotel').removeClass('inactive').addClass('active');
			$('#page_hotel').children().css('top', '-2400px');
			$('#page_hotel > div').animate({top:'0px'}, 1300, function(){
				//animateSmall(3);
				animateboxes(hotel);
				switch_bg(3);
				if(psb_active && $('#psb').css('top') == "217px") { psb_active = false; $('#psb').animate({top:'1800px'}, 800, function() { $(this).css({'top':'-1800px'}); }); }
			});
		}
		
		if(site == 30){
			//$(".act_bg").attr('src', 'img/back4.jpg');
			$('#page_location').removeClass('inactive').addClass('active');
			$('#page_location').children().css('top', '-2400px');
			$('#page_location > div').animate({top:'0px'}, 1300, function(){
				animateboxes(locatio);
				//animateSmall(30);
				switch_bg(30);
				if(psb_active && $('#psb').css('top') == "217px") { psb_active = false; $('#psb').animate({top:'1800px'}, 800, function() { $(this).css({'top':'-1800px'}); }); }
			});
		}

		if(site == 31){
			//$(".act_bg").attr('src', 'img/back4.jpg');
			$('#page_gallery').removeClass('inactive').addClass('active');
			$('#page_gallery').children().css('top', '-2400px');
			$('#page_gallery > div').animate({top:'0px'}, 1300, function(){
				//animateSmall(31);
				switch_bg(31);
			});
		}
		
		if(site == 5){
			//$(".act_bg").attr('src', 'img/back5.jpg');
			$('#page_guestbook').removeClass('inactive').addClass('active');
			$('#page_guestbook').children().css('top', '-1800px');
			$('#page_guestbook > div').animate({top:'0px'}, 1300, function(){
				//animateSmall(4);
				animateboxes(guestbook);
				switch_bg(4);
				if(psb_active && $('#psb').css('top') == "217px") { psb_active = false; $('#psb').animate({top:'1800px'}, 800, function() { $(this).css({'top':'-1800px'}); }); }
			});
		}
		
		if(site == 6){
			//$(".act_bg").attr('src', 'img/back6.jpg');
			$('#page_team').removeClass('inactive').addClass('active');
			$('#page_team').children().css('top', '-1800px');
			$('#page_team > div').animate({top:'0px'}, 1300, function(){
				animateSmall(5);
				switch_bg(5);
				if(psb_active && $('#psb').css('top') == "217px") { psb_active = false; $('#psb').animate({top:'1800px'}, 800, function() { $(this).css({'top':'-1800px'}); }); }
			});
		}
		
		if(site == 7){
			//$(".act_bg").attr('src', 'img/back7.jpg');
			$('#page_contact').removeClass('inactive').addClass('active');
			$('#page_contact').children().css('top', '-1800px');
			$('#page_contact > div').animate({top:'0px'}, 1300, function(){
				//animateSmall(6);
				animateboxes(contact);
				switch_bg(6);
				if(psb_active && $('#psb').css('top') == "217px") { psb_active = false; $('#psb').animate({top:'1800px'}, 800, function() { $(this).css({'top':'-1800px'}); }); }
			});
		}
		
		if(site == 8){
			$('#page_impressum').removeClass('inactive').addClass('active');
			$('#page_impressum').children().css('top', '-1800px');
			$('#page_impressum > div').animate({top:'0px'}, 1300, function(){
				//animateSmall(8);
				animateboxes(impressum);
				if(psb_active && $('#psb').css('top') == "217px") { psb_active = false; $('#psb').animate({top:'1800px'}, 800, function() { $(this).css({'top':'-1800px'}); }); }
			});
		}
		if(site == 9){
			//$("#slider_bg img").attr('src', 'img/back1.jpg');
			$('#startpage').removeClass('inactive').addClass('active');
			$('#startpage').children().css('bottom', '1500px');
			animateSmall(9);
			if(psb_active && $('#psb').css('top') == "217px") { psb_active = false; $('#psb').animate({top:'1800px'}, 800, function() { $(this).css({'top':'-1800px'}); }); }
		}
		if(site == 10){
			$('#page_special').removeClass('inactive').addClass('active');
			$('#page_special').children().css('top', '-1800px');
			$('#page_special > div').animate({top:'0px'}, 1300, function(){
				animateSmall(10);
			});
		}
}




function change_button(site){

	$('.active_button > .btn_left_act').addClass('btn_left').removeClass('btn_left_act');
	$('.active_button .btn_mid_act').addClass('btn_mid').removeClass('btn_mid_act');
	$('.active_button > .btn_right_act').addClass('btn_right').removeClass('btn_right_act');

	$('.active_button').addClass('inactive_button').removeClass('active_button');

	if(site == 1) var new_active = '#rooms_rates';
	if(site == 2) var new_active = '#packages';
	if(site == 3) var new_active = '#hotel';
	if(site == 30) var new_active = '#location';
	if(site == 31) var new_active = '#gallery';
	if(site == 5) var new_active = '#guestbook';
	if(site == 6) var new_active = '#team';
	if(site == 7) var new_active = '#contact';
	if(site == 8) var new_active = '#impressum';
	if(site == 9) var new_active = '#startseite';
	if(site == 10) var new_active = '#special';
	
	
	$(new_active + ' > .btn_left').addClass('btn_left_act').removeClass('btn_left');
	$(new_active + ' .btn_mid').addClass('btn_mid_act').removeClass('btn_mid');
	$(new_active + ' > .btn_right').addClass('btn_right_act').removeClass('btn_right');

	$(new_active).addClass('active_button').removeClass('inactive_button');

	
	if(site == 1){ $('#item1').parent().append('<div id="item01">&nbsp;</div>'); $('#item1').remove(); }	
	if(site == 2){	$('#item2').parent().append('<div id="item02">&nbsp;</div>'); $('#item2').remove(); } 
	if(site == 3){	$('#item3').parent().append('<div id="item03">&nbsp;</div>'); $('#item3').remove(); } 
	if(site == 30){	$('#item30').parent().append('<div id="item030">&nbsp;</div>'); $('#item30').remove(); } 
	if(site == 31){	$('#item31').parent().append('<div id="item031">&nbsp;</div>'); $('#item31').remove(); } 
	if(site == 5){	$('#item5').parent().append('<div id="item05">&nbsp;</div>'); $('#item5').remove(); } 
	if(site == 6){	$('#item6').parent().append('<div id="item06">&nbsp;</div>'); $('#item6').remove(); } 
	if(site == 7){	$('#item7').parent().append('<div id="item07">&nbsp;</div>'); $('#item7').remove(); } 
	
	
	
	if(site != toChange){
		
		var position = ['-190px', '-122px', '-103px', '0px', '-130px', '-76px', '-122px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '0px', '-130px', '-105px'];
		
		var mouseEffect = 'onmouseout="$(this).stop().animate({marginLeft:\'0px\'}, 150);" onmouseover="$(this).stop().animate({marginLeft:\'' + position[toChange-1] + '\'}, 150);"';
		$('#item0' + toChange).parent().append('<div style="background-position:5px 6px;" ' + mouseEffect + ' id="item' + toChange + '">&nbsp;</div>'); 
		$('#item0' + toChange).remove();
	
	}

	toChange = site;
	
}


function animateboxes(all_boxes) {
	var state1 = true;
	var state2 = true;

	split_boxes = all_boxes.split(" ");
	
	if(split_boxes[0] == 62 || split_boxes[0] == 0) {
		//alert("no box 0");
		state1 = false;
	}
	if(split_boxes[1] == 62 || split_boxes[1] == 0) {
		//alert("no box 1");
		state2 = false;
	}
	
	
	if(lastbox1 != split_boxes[0] && lastbox1 != split_boxes[1]) { $('#be_sb'+lastbox1).animate({top:'1800px'}, 800, function() { $(this).css({'top':'-1800px'}); }); }
	if(lastbox2 != split_boxes[0] && lastbox2 != split_boxes[1]) { $('#be_sb'+lastbox2).animate({top:'1800px'}, 800, function() { $(this).css({'top':'-1800px'}); }); }
	
	
	animate_booking(state1, state2);
	
	if(split_boxes[0] == "666") {
		psb_active = true;
		$('#psb').animate({top:'217px'}, 1300, function(){
			
		});
	} else {
		if(state1) {
			$('#be_sb' + split_boxes[0]).animate({top:'217px'}, 1300, function(){
				
			});
		}
	}
	
	if(state2 && !state1) {
		$('#be_sb' + split_boxes[1]).animate({top:'217px'}, 1300, function(){

		});
	} else if(state2 && state1) {
		$('#be_sb' + split_boxes[1]).animate({top:'375px'}, 1300, function(){

		});
	}
	
	lastbox1 = split_boxes[0];
	lastbox2 = split_boxes[1];
	
}

function animate_booking(state1, state2){
	if(state1 && state2) {
		$('#location_sb2').animate({top:'533px'}, 1300, function(){
			$('#close_menu').hide();
		});
	} else if((state1 && !state2) || (!state1 && state2)) {
		$('#location_sb2').animate({top:'375px'}, 1300, function(){
			$('#close_menu').hide();
		});
	} else if(!state1 && !state2) {
		$('#location_sb2').animate({top:'217px'}, 1300, function(){
			$('#close_menu').hide();
		});
	}
}


function animateSmall(site){
	/*if(site == 2){
		$('#small_boxes').children().animate({top:'380px'}, 1300, function(){
			$('#psb').animate({'top':'217px'}, 1300);
			$('#page_packages > div').animate({top:'0px'}, 1300, function(){
				switch_bg(2);
			});
		});
	} else */ if(site == 9){
		$('#psb').animate({top:'1800px'}, 1300);
		$('#small_boxes').children().animate({top:'1800px'}, 1300, function(){
			$('#startpage').children().animate({bottom:'80px'}, 1300, function(){
				$('#small_boxes').children().css({top:'-1800px'});
				$('#psb').css({top:'-1800px'});
				switch_bg(0);
			});
		});
		
	} 
		/*else {
			$('#small_boxes').children().animate({top:'217px'}, 1300);
			if(site == 8) { $('#close_menu').hide(); }
		}
	}*/
}




function hide_menu(site){

	if(site == lastSite_pack){
		
	} else {
		lastSite_pack = site;
		$('#close_menu').show();
	}
	
}
