$(document).ready(function(){
  $('#discover .discover_next, #discover .discover_prev').css('visibility', 'hidden');
  /*
  $('.discover_slide').jCarouselLite({
    btnNext: "#discover .discover_next",
    btnPrev: "#discover .discover_prev",
    visible: 3,
    scroll: 3,
    beforeStart: function(a) {
      $(a).parent().fadeTo(1000, 0);
    },
    afterEnd: function(a) {
      $(a).parent().fadeTo(1000, 1);
    }
  });
  
  When you active discover carousel, you must put -326px below...
  */
  $('#discover').css('left', '0px'); // ... and delete this line
  $('.button_slider').click(function(){
    if($('#discover').css('left') == '0px'){
      $('#discover').animate({'left': '-=240px'}, 'slow');
    }else{
      $('#discover').animate({'left': '0px'}, 'slow');
    }
  });
  
  $(".discover_slide img").reflect();
    
  $('.discover_slide a').each(function(i){
    $(this).click(function(){
      var cache = [];
      var img = $(this).attr('href');
	  
      // We create pre-load for big images
      var cacheImg = document.createElement('img');
      cacheImg.src = img;
      cache.push(cacheImg);
      
      // We get the index for text and change the background
      var id = $(this).attr('rel');
      $('#background').fadeOut('slow', function(){
        $('img', this).attr('src', img);
      }).fadeIn('slow');
      
      // If text exists, we change it on content scrollbar
      if(discovers_items[parseInt(id)].text.length > 0) {
        $('#content .scrollbar').fadeOut('slow', function(){
          $(this).empty().html(discovers_items[parseInt(id)].text);
        }).fadeIn('slow');
      }
      
      // Avoid the normal action when 
      return false;
    });
  });
  
  $("#newsletter_form").submit(function(){
    var y=true;
    $("#newsletter_form input").removeClass("error");
    if($("#firstname").val().length<1){
      y = false;
      $("#firstname").addClass("error");
    }
    if($("#lastname").val().length<1){
      y = false;
      $("#lastname").addClass("error");
    }
    if($("#country").val().length<1){
      y = false;
      $("#country").addClass("error")
    }
    if(!/^.+@.+\..+$/i.test($("#email").val())){
      y = false;
      $("#email").addClass("error")
    }
    return y;
  });
});

