jQuery.fn.hint = function (blurClass) {
  if (!blurClass) { 
    blurClass = 'blur';
  }

  return this.each(function () {
    // get jQuery version of 'this'
    var $input = jQuery(this),

    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = jQuery(this.form),
      $win = jQuery(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title

      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};

$.fn.newsScroll = function(options) {  
  
    return this.each(function() {     
  
        var $this = $(this),   
        defaults = {  
            speed: 400,  
            delay: 3000,
            limit: 5,
            list_item_height: $this.children('li').outerHeight()  
         },  
         lgt = $this.children('li').length;
         settings = $.extend({}, defaults, options);   
         
         for (i=(settings.limit);i<=lgt;i++) {
            $this.children('li:eq('+ i +')').animate({opacity: 'hide'});
         }

         setInterval(function() {  
            $this.children('li:first')  
                .animate({  
                   marginTop : '-' + settings.list_item_height,  
                   opacity: 'hide' },  

                   settings.speed,  

                   function() {
                        $this  
                          .children('li:first')
                          .appendTo($this)  
                          .css('marginTop', 0);
                        $this  
                          .children('li:eq('+ (settings.limit - 1) +')')
                          .fadeIn(600);
                  }  
              ); // end animate  
         }, settings.delay); // end setInterval  
    });  
};

$.fn.scrollableAddClones = function(addItems) {
  // grab scrollable plugin
  var scrollable;
  if (!(scrollable = $(this).data('scrollable')) || !scrollable.getConf().circular)
    return;
  // grab scrollable elements and remember it's count
  var nodes = scrollable.getItems();
  var length = nodes.length;
  // grab class for the nodes
  var clonedClass = scrollable.getConf().clonedClass;
  // get wrap object to append the clones to
  var wrap = scrollable.getItemWrap();
  // fill as much nodes as needed for 500 pixels
  if (!addItems) addItems = Math.ceil(500 / nodes.eq(1).width());
  // create fake container to add the clones to (max 15 clones)
  var newNodesAppend = $('<span />');
  for (var i = 1; i <= 5; i++)
    nodes.eq(i % length).clone().addClass(clonedClass).appendTo(newNodesAppend);
  // insert HTML
  newNodesAppend.children().appendTo(wrap);
}


$.tools.validator.localize("fr", {
	':email'  		: 'Veuillez saisir une adresse email valide',
	':number' 		: 'Veuillez saisir un nombre',
        ':url' 		        : 'Veuillez saisir une adresse valide',
	'[max]'	 		: 'Veuillez saisir une valeur superieur à $1',
	'[min]'	 		: 'Veuillez saisir une valeur inferieur à $1',
	'[required]' 	        : 'Ce champ est obligatoire'
    });
    
$(function(){ 
    // find all the input elements with title attributes
    $('input[title!=""]').hint();
    
    //$(".scrollable").scrollable();
    
    $(".subnav .more").hover(function() {
	$(".subnav span").show();
    });
    
    $(".subnav span").hover(function() {
	$(this).show();
    }, function() {
	$(this).hide();
    });
    
    $('input').customInput();
    
    //$(".news-scrollable").scrollable({ circular: true, vertical: true, mousewheel: true }).autoscroll(3000);
    $(".news-scrollable").scrollable({ 
            // up/down keys will always control this scrollable 
            keyboard: 'static',
            // number of items to scroll on up/down keys
            keyboardSteps: 1,
            // number of items shown in the scroller
            size: 5,
            // scrolling speed
            speed: 1000,
            // enable vertical scroller
            vertical: true,
            circular: true, 
            // get the all items and fade them to 1
            onBeforeSeek: function() { 
                    var items = this.getItems(); 
                    items.fadeTo(10, 1);
            }			
    })		
    .autoscroll({ 
            steps: 1, 
            interval: 5000, 
            autoplay: true, 
            autopause: true 
    });
                
    $('.news-scrollable').scrollableAddClones();
    
    $(".folder-companies-scrollable").scrollable({ circular: true, keyboard: false, next: "test", prev: "test" }).autoscroll(3000);
    var api = $(".folder-companies-scrollable").data("scrollable");
    if (api != null) {
        api.getConf().keyboard = false;
    }
    

    $('.facebox').facebox();
    
    //form.attr('novalidate', 'novalidate');
    
    $("#profileForm").validator({ lang: 'fr' });
    $("#contactForm").validator({ lang: 'fr' });
    $("#commentForm").validator({ lang: 'fr' });
    $("#applicationForm").validator({ lang: 'fr' });
    $("#surveyForm").validator({ lang: 'fr' });
    
    $("#aside-depotoffre").click(function() {
        $("#aside-annuairerh-roll").hide();
        $("#aside-annuairerh").show();
        $(this).hide();
	$("#aside-depotoffre-roll").show();
    });
    
    $("#aside-depotoffre-roll").click(function() {
        $(this).hide();
	$("#aside-depotoffre").show();
    });
    
    $("#aside-annuairerh").click(function() {
        $("#aside-depotoffre-roll").hide();
        $("#aside-depotoffre").show();
        $(this).hide();
	$("#aside-annuairerh-roll").show();
    });
    
    $("#aside-annuairerh-roll").click(function() {
        $(this).hide();
	$("#aside-annuairerh").show();
    });
    
    //inputs.data("validator").checkValidity();
});

function addToFavorite(url) {
    $.get(url, function(data){
        $('#notification').html(data).fadeIn();
    });
}

var addthis_share = {
   templates : {
      twitter : "{{title}} {{url}} via @myrhline"
   }
}
