jQuery(document).ajaxSend(function(event, request, settings) {
if (typeof(AUTH_TOKEN) == "undefined") return;
settings.data = settings.data || "";
    if (settings.type=='POST' || settings.type=='PUT'){
        settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
    }
});
// add javascript request type
jQuery.ajaxSetup({
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
});

function search(letter){
    jQuery('#letter').val(letter);
    jQuery('#members_search').trigger('submit');
  }

jQuery(document).ready(
    function () {

        // MENU
        jQuery("#top_nav li.first_level").mouseenter(function() {
            child = jQuery(this).find("ul:first");
            if (child.css("display") == "none"){
                child.slideToggle();
            }
        }).mouseleave(function() {
            child = jQuery(this).children("ul");
            if (child.css("display") == "block"){
                child.slideToggle();
            }
        });

    
        // PAGE PARTENAIRES
        jQuery(".blue_logo").mouseover(function() {
         // jQuery(".original_logo").hide();
         src = jQuery(this).attr("src");
         jQuery(this).attr("src",jQuery(this).attr("rel"));
         jQuery(this).attr("rel",src);
        }).mouseleave(function() {
          src = jQuery(this).attr("src");
          jQuery(this).attr("src",jQuery(this).attr("rel"));
          jQuery(this).attr("rel",src);});


          // LES GRANDS EQUIPEMENTS
        jQuery(".big_equipment_tool").mouseover(function() {
         // jQuery(".original_logo").hide();
         jQuery(".big_equipment_tool").removeClass("active");
         jQuery(this).addClass("active");
         src = jQuery(this).attr("rel");
         jQuery(".big_equipment_image").attr("src",src);
        }).mouseleave(function() {
          jQuery(".big_equipment_tool").removeClass("active");
          jQuery(".big_equipment_tool:first").addClass("active");
          src =  jQuery(".big_equipment_tool:first").attr("rel");
          jQuery(".big_equipment_image").attr("src",src);
        });



        

        // PETIT CALENDRIER
        jQuery("#small_calendar").datepicker({
            prevText: "",
            nextText: "",
            disabled: true,                         
            onChangeMonthYear: function(year, month, inst){
                jQuery.getJSON(
                "/actualities/show_events?month="+month+"&year="+year,
                function(data){
                        jQuery.each(data, function(i,event){
                            jQuery.each(jQuery(".ui-datepicker-calendar td"), function() {
                                jQuery(this).removeAttr('onclick');
                                td_id = jQuery(this).attr("id");
                                if (td_id.split("-")[0] == event.day){
                                    jQuery(this).addClass("active");
                                    jQuery(this).children("a").attr("name", event.title);
                                    jQuery(this).children("a").attr("href", event.url);
                                    jQuery(this).children("a").tooltip({showURL:false,fade: 250});
                                }

                            });
                        });

                });

            }

        });

        jQuery.each(jQuery(".ui-datepicker-calendar td"), function() {
            jQuery(this).removeAttr('onclick');

        });


        // MENU GAUCHE
        var document_location = document.location.href;
        var current_location = document_location.substring(document_location.lastIndexOf( "/" ));
        
        jQuery(".left_link").removeClass("active");
        jQuery(".left_link").each(function() {                  
           if (jQuery(this).attr("href") == current_location){
               jQuery(this).addClass("active");
           }

        });


        // MESSAGES FLASH
        setTimeout (function() {
            $(".flashes").fadeOut("slow");
             $(".flashes").html('');
        }, 8000 );




});

 


function obtenerPosicionY(elemento)
{
var y=0;
while(elemento)
{
y += elemento.offsetTop;
elemento=elemento.offsetParent;
}
return y;
}

