$(document).ready(function(){

	FoldBox.init();

	Terms.init();
	


});



var Terms = {

	init: function(){

		$("#TermsAndConditions").hide();

	}

}


var FoldBox = {

    init: function(){

		$("#Menu > LI > UL").hide();



		$("#Menu > LI > A").bind("click", function(e){

			$("#Menu > LI:has(UL) > UL").hide("slow");

			$("#Menu > LI").css("background","none");

			$($(this)).parent().css("background","#8ba082");

            Paging.Open($(this));

        });

		$("#Menu > LI > UL > LI > A").bind("click", function(e){

            Paging.Open($(this));

        });

		$("#Menu > LI:has(UL) > A").bind("click", function(e){

            FoldBox.toggle($(this));

        });

    },

    toggle: function(target){



        var Block = $(target.parent().children("UL")[0]);

		if(Block != null){

			if(Block.css("display") == "none"){

				Block.show("slow");

			}

		}

    }

}





var Paging = {

	Attach : function(){

		$("#Menu > LI > A").bind("click", function(e){

            Paging.Open($(this));

        });

	},

	Open : function(target){

		$('#date3').DatePickerHide();

		var DivName = $(target).attr("href");

/*		$("#ManContent").html($(DivName + " > .ManBar").html());

*/		

		$("#Midbar").html($(DivName).html());

		$("#Midbar").hide();

		$("#Midbar").show("slow");

		$("#Content > H2 > A").bind("click", function(e){

			$("#TermsAndConditions").show();

		});

		$(".lightbox").lightbox();

		$("#Slideshow").cycle({ 

			timeout: 7000, 

			speed: 3000 

		}); 
		
		var tmp = new Date();
		var prettyDate =(tmp.getFullYear() + '/' + (tmp.getMonth() + 2) + '/' + tmp.getDate()); 
		$('#check_in').val(prettyDate);
		$('#check_out').val(prettyDate);

		$('#date3').DatePicker({
			flat: true,					   
			format:'Y-m-d',
			date: prettyDate,
			current: prettyDate,
			starts: 1,
			position: 'r',
			calendars: 3,
			mode: 'range',
			onChange: function(formated, dates){
				var dateString=formated.toString();
				var commaPos=dateString.indexOf(',');
				var arrivalDate=dateString.substr(0,commaPos);
				var lengte=dateString.length;
				var departureDate=dateString.substr(commaPos+1,lengte);
				$('#check_in').val(arrivalDate);
				$('#check_out').val(departureDate);
			}
		});
		
		
	},

	OpenFromFlash : function(target){



		var DivName = target;

/*		$("#ManContent").html($(DivName + " > .ManBar").html());

*/		

		$("#Midbar").html($(DivName).html());

		$("#Midbar").hide();

		$("#Midbar").show("slow");

		$("#Content > H2 > A").bind("click", function(e){

			$("#TermsAndConditions").show();

		});

		$(".lightbox").lightbox();

		$("#Slideshow").cycle({ 

			timeout: 7000, 

			speed: 3000 

		});

		$("#Menu > LI:first").css("background","#8ba082");

		FoldBox.toggle($("#Menu > LI:first > A:first"));

	}

}