$(document).ready(function(){

    $("#adv_search_options").hide();
    $("#adv_search_options_full").hide();
    $(".adv_cottage_search p").toggle(
		function(){ //shows content add shows close icon
			$("#adv_search_options").show();
		}, function() { //hides content add shows open icon
			$("#adv_search_options").hide();
		});
    $(".adv_cottage_search_full p").toggle(
		function(){ //shows content add shows close icon
			$("#adv_search_options_full").show();
		}, function() { //hides content add shows open icon
			$("#adv_search_options_full").hide();
		});
	
	/* initia tab ui and enable tabs sorting */
	
	$(function() {
		$("#tabs").tabs();
	});
	
	/* scroll back to top */
	
	$('div.back_to_top').click(function(){//all divs w/class back_to_top
		$.scrollTo(0,800);
	});

	/* toggles cottage features */
	
	/*$(".show_cottage_features").hide();*/
	$(".cottage_features_toggle").toggle(
		function(){ //shows content add shows close icon
			$(".show_cottage_features").hide("fast");
			$(".cottage_features_toggle_indicator").addClass("cottage_features_toggle_indicator_showopen");
		}, function() { //hides content add shows open icon
			$(".show_cottage_features").show("fast");
			$(".cottage_features_toggle_indicator").removeClass("cottage_features_toggle_indicator_showopen");
		});
	
	/* toggles cottage description */
	
	/*$(".show_description").hide();*/
	$(".cottage_description_toggle").toggle(
		function(){ //shows content add shows close icon
			$(".show_description").hide("fast");
			$(".cottage_description_toggle_indicator").addClass("cottage_description_toggle_indicator_showclose");
		}, function() { //hides content add shows open icon
			$(".show_description").show("fast");
			$(".cottage_description_toggle_indicator").removeClass("cottage_description_toggle_indicator_showclose");
		});
	
	/* toggles cottage accommodation */
	
	/*$(".show_accommodation").hide();*/
	$(".cottage_accommodation_toggle").toggle(
		function(){ //shows content add shows close icon
			$(".show_accommodation").hide("fast");
			$(".cottage_accommodation_toggle_indicator").addClass("cottage_accommodation_toggle_indicator_showclose");
		}, function() { //hides content add shows open icon
			$(".show_accommodation").show("fast");
			$(".cottage_accommodation_toggle_indicator").removeClass("cottage_accommodation_toggle_indicator_showclose");
		});
	
	/* toggles cottage local info */
	
	/*$(".show_localinfo").hide();*/
	$(".cottage_localinfo_toggle").toggle(
		function(){ //shows content add shows close icon
			$(".show_localinfo").hide("fast");
			$(".cottage_localinfo_toggle_indicator").addClass("cottage_localinfo_toggle_indicator_showopen");
		}, function() { //hides content add shows open icon
			$(".show_localinfo").show("fast");
			$(".cottage_localinfo_toggle_indicator").removeClass("cottage_localinfo_toggle_indicator_showopen");
		});
	
	/* toggles cottage services */
	
	/*$(".show_services").hide();*/
	$(".cottage_services_toggle").toggle(
		function(){ //shows content add shows close icon
			$(".show_services").hide("fast");
			$(".cottage_services_toggle_indicator").addClass("cottage_services_toggle_indicator_showclose");
		}, function() { //hides content add shows open icon
			$(".show_services").show("fast");
			$(".cottage_services_toggle_indicator").removeClass("cottage_services_toggle_indicator_showclose");
		});
	
	/* toggles cottage notes */
	
	/*$(".show_notes").hide();*/
	$(".cottage_notes_toggle").toggle(
		function(){ //shows content add shows close icon
			$(".show_notes").hide("fast");
			$(".cottage_notes_toggle_indicator").addClass("cottage_notes_toggle_indicator_showclose");
		}, function() { //hides content add shows open icon
			$(".show_notes").show("fast");
			$(".cottage_notes_toggle_indicator").removeClass("cottage_notes_toggle_indicator_showclose");
		});

    /* Colorbox for cottage images */
    $(".slideshow").colorbox({transition:'elastic', slideshow:true, slideshowSpeed:4500});
    
    /* Location dropdown binding */
    $("#county").change(function () {
              var svalue = "";
              $("#county option:selected").each(function () {
                    svalue = $(this).attr("value");
              });
              
              if(svalue != "") {
                $.post("/ajax/get-locations.aspx", { region_id: svalue },
                function(data){
                    if(data != "error") {
                        $("#location").html(data);
                    }
                });
              }
              else {
                $("#location").html('<option value="">Please select...</option>');
              }
            })
            .change();
            
    $("#cottagesearchagain_county").change(function () {
              var svalue = "";
              $("#cottagesearchagain_county option:selected").each(function () {
                    svalue = $(this).attr("value");
              });
              
              if(svalue != "") {
                $.post("/ajax/get-locations.aspx", { region_id: svalue },
                function(data){
                    if(data != "error") {
                        $("#cottagesearchagain_location").html(data);
                    }
                });
              }
              else {
                $("#cottagesearchagain_location").html('<option value="">Please select...</option>');
              }
            })
            .change();
            
    $("#cottagesearchall_county").change(function () {
              var svalue = "";
              $("#cottagesearchall_county option:selected").each(function () {
                    svalue = $(this).attr("value");
              });
              
              if(svalue != "") {
                $.post("/ajax/get-locations.aspx", { region_id: svalue },
                function(data){
                    if(data != "error") {
                        $("#cottagesearchall_location").html(data);
                    }
                });
              }
              else {
                $("#cottagesearchall_location").html('<option value="">Please select...</option>');
              }
            })
            .change();
            
    /* Date picker */
    $(".date-pick").datePicker();
});
