jQuery(document).ready(function()
{
  // the direct source of the delay function in 1.4+
  jQuery.fn.extend({
    delay: function( time, type ) {
      time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
      type = type || "fx";
      return this.queue( type, function() {
        var elem = this;
        setTimeout(function() {
          jQuery.dequeue( elem, type );
        }, time );
      });
    }
  });
  
  // Display notice
  jQuery.notice.init();
  jQuery.notice.show();
  
  // Color form inputs in error
  jQuery('form ul.error_details').each(function(e)
  {
    jQuery(this).parents('li').find('input[type=text],input[type=password],textarea').addClass('error');
  });

		// quick search place holder
		var searchValue = jQuery('#quicksearch #search_box');
		searchValue.focus(function() {
    if (this.value == 'Rechercher...') {
     this.value = '';
    }
		}).blur(function() {
    if (this.value == '') {
				  this.value = 'Rechercher...';
    }
		});
  
  // tooltips management
  //Create default user picture mouseover tooltips
  jQuery('.user_tooltiped_picture').each(function()
  {
    mr.tips.add(jQuery(this), jQuery(this).parent().attr('alt'));
  });
  
  // show logo after scroll
  jQuery(window).scroll(function()
  {
    var scrollPosition = jQuery(document).scrollTop();
    if (scrollPosition >= 55)
    {
      jQuery('.fix_logo').fadeIn(500, function()
      {
        jQuery(this).stop(true, false);
      });
    } else
    {
      jQuery('.fix_logo').fadeOut(500);
    }
  });

	// bubble info
	jQuery('.bubble_trigger').each(function() {
    var $trigger    = jQuery(this),
        $bubbleInfo = $trigger.find('.bubble-info');

    if ($bubbleInfo.length === 0) {
      $bubbleInfo  = $trigger.parent().find('.bubble-info');
    }

    if ($bubbleInfo.length > 0) {
      $trigger.hover(function() {
        $bubbleInfo.stop(true, true).fadeIn(200);
      }, function() {
        $bubbleInfo.fadeOut(200);
      });
    }
  });

	// Change right buttons with the screen width
	jQuery(window).resize(buttonsChange);
	function buttonsChange() {
	  var screenWidth = jQuery(this).width(),
	  		rightButtons  = jQuery('#feedback_button, #lab_button'),
	  		bottomButtons = jQuery('#feedback_button_resize, #lab_button_resize');

	  if (screenWidth <= 1024) {
	    rightButtons.hide();
	    bottomButtons.show();
	  } else {
	    rightButtons.show();
	    bottomButtons.hide();
	  }
	}
	buttonsChange();

  // Sub building navigation
  jQuery('#navigation .my_building > a').click(function(e) {
    e.preventDefault();
    jQuery(this).next('.sub_building').toggle();
  });
});
