// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
// helper functions for Ajaxifying standard links and forms, and evaluating returned Javascript


$(document).ready(function(){
        //$(".toggle").hide();
        $(".toggle").attr({style:"display:none"});
        $("a.toggle_link").click( function(){
            $(this).next(".toggle").slideToggle("fast");
            return false;
            });
        $("a.rjs-photo").click(  function() {
            $(this).next(".photos").toggle();
            $.ajax({
                //type: "POST",
                //url: this.getAttribute("href"),
                url: '/'+this.href.replace(/http:\/\/.+?\//,''),
                //url: this.href,
                dataType: "script",
                beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");}
            });

            return false;
         });
        
       $("a.rjs").click(  function() {
            $.ajax({
                //type: "POST",
                //url: this.getAttribute("href"),
                url: '/'+this.href.replace(/http:\/\/.+?\//,''),
                //url: this.href,
                dataType: "script",
                beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");}
            });

            return false;
         });
       
      // requires jQuery.form plugin
      $("form.rjs").ajaxForm({
        dataType: 'script',
        beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");},
        resetForm: true
      });
      
      $("div.photos").hide();
  
       $(".hidden").hide();
        $("a.show_hidden").click(function(){
            $(this).next(".hidden").toggle(180);
            return false;
         });
     
    $("#slide_menu").accordion({
       //event: "mouseover",
       autoheight: false
    });
    
     $("select[@name='location[id]']").change(function () {
          $("select[@name='location[id]'] option:selected").each(function () {
            if ($(this).attr("selected")==true) { 
                $.ajax({
                    url: "/locations/"+this.value+"/distance_selector_for",
                    dataType: "script",
                    beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");}
                });}
            else  $('#entrytype').hide();
          })
          //if ($("option[@value='iblock_entries',@selected]")) {$('#entrytype').hide()}
        })
        .change();
        
        
   

    $(".full_accommodation_description").hide();
    $("a.read_full_accommodation_description").click(function(event){
        $(this).next(".full_accommodation_description").toggle("fast");

        // Stop the link click from doing its normal thing
        return false;
     });
    
});


