$(document).ready(function(){

/* Sub navegation */
/*---------------------------------------------------------------*/

  $('nav ul li').hover(
    function () {
      $('ul', this).slideDown(100);
    }, 
    function () {
      $('ul', this).slideUp(100);			
    }
  );

/* Tooltip */
/*---------------------------------------------------------------*/

  $("form p input, form p select").mouseover(function() {
    if ($(this).attr('rel') == "help_alert") {
      var pos = $(this).position();
      var width = $(this).width();
      var new_pos = pos.left+width+20;
      var help_text = $(this).attr('data-content');
      $("<span class='form-help-text' style='left:"+new_pos+"px; display:none;'>"+help_text+"</span>").insertAfter(this).fadeIn();
    }
  });

  $("form p input, form p select").mouseout(function(){
    $("span.form-help-text").fadeOut('fast');
  });

/* Search input */
/*---------------------------------------------------------------*/

  var initValue = "Restaurante, tipo de comida, distrito";
  $("#searchform .text").val(initValue);
  $("#searchform .text").focusin(function(){
    var value = $("#searchform .text").val();
    if( value == initValue ) {
      $("#searchform .text").val("").css("color","#333");
    }
  });

  $("#searchform .text").focusout(function(){
    var value = $("#searchform .text").val();
    if( value == "" ) {
      $("#searchform .text").val(initValue).css("color","#aaa");
    }
  });

/* Slide list */
/*---------------------------------------------------------------*/

  var slideWidth = $("#list-slide").width();
  var elementsWidth = slideWidth/5;

  setInterval(function() {
    slidePos = $("#list-slide").position();
    if( Math.abs(slidePos.left)+elementsWidth != slideWidth ) {
      var SlidenewPos = slidePos.left - elementsWidth;
      $("#list-slide").animate({
        left:'-='+elementsWidth
        }, 500);
    } else {
      $("#list-slide").animate({
        left:'+='+(slideWidth - elementsWidth)
        }, 500);
    }
  }, 5000);


/* Fade */
/*---------------------------------------------------------------*/

  $('#fade').cycle({ 
    fx:     'fade', 
    speed:  'fast', 
    delay:  -5000,
    next:   '#next', 
    prev:   '#prev'
  });

});

