$(document).ready(function() {
  $('nav#main li').last().addClass('last');
  $('#products li tr:odd').addClass('odd');
  
  $(':input[title]').each(function() {
  var $this = $(this);
  if($this.val() === '') {
    $this.val($this.attr('title'));
  }
  $this.focus(function() {
    if($this.val() === $this.attr('title')) {
      $this.val('');
    }
  });
  $this.blur(function() {
    if($this.val() === '') {
      $this.val($this.attr('title'));
    }
  });
  });

  
  $(document).ready(function() {
  $("#form").validate({
    submitHandler: function(form) {
      // do some ajax
      if ($("#name").val() == "") {
        $.post("/modules/forms/mailer.php", $(form).serialize(), function(response) {
          form.reset()
          $("#result").html(response)
        })
      }
    }
  });

  var spinner = $('<div id="loader"><img src="/public/gfx/ajax-loader.gif" /></div>')

    spinner.ajaxStart(function() {
	  $(this).appendTo("#result").show()
	}).ajaxStop(function() {
	  $(this).hide()
	});

  });
  
});


// slide box

$(document).ready(function() {
	
  $("#banner nav button:first").addClass("active");

  var imageWidth = $("#banner").width();
  var imageSum = $("#banner .image_reel img").size();
  var imageReelWidth = imageWidth * imageSum;

  $("#banner .image_reel").css({'width' : imageReelWidth});
  
  rotate = function(){
      var triggerID = $active.attr("tabindex") - 1; 
      var image_reelPosition = triggerID * imageWidth;

      $("#banner nav button").removeClass('active');
      $active.addClass('active');

      
      $("#banner .image_reel").animate({
          left: -image_reelPosition
      }, 1000 );
  }; 
  
  rotateSwitch = function(){
      play = setInterval(function(){ 
          $active = $('#banner nav button.active').next(); 
          if ( $active.length === 0) { 
              $active = $('#banner nav button:first');
          }
          rotate();
      }, 5000);
  };

  rotateSwitch(); 

  //On Click
  $("#banner nav button").click(function() {
      $active = $(this); 

      clearInterval(play);
      rotate();
      rotateSwitch();
      return false;
  });
});

