//Main = "http://localhost/campbells";
Main = "http://campbells.com.mx";
$(document).ready(function(){
   $("#email form").submit(function(){
    $.post(Main+"/ajax/compartir.php", $(this).serialize(), function(msg){
      if( msg == "ok" ) {
        alert("Tu correo ha sido enviado.\n\nMuchas gracias.\n\nAtte. Campbell's");
        $("#email form input").attr("disabled","disabled");
        $("#email").slideUp();
      } else {
        alert(msg);
        $('#email form input[type="text"]').focus();
      }
    });
    return false;
  });
  
  $(".zebraTbl tr").mouseover( function(){
    $(this).addClass("over");
  }).mouseout( function(){
    $(this).removeClass("over");
  });
  $('.zebraTbl tr:even').addClass('alt');

  $(".forma").submit(function(){
    $(this).find("input[type='submit']").val("").addClass("load").attr("disabled","disabled");
    $.post(Main+"/ajax/contacto.php", $(this).serialize(), function(msg){
      if( msg.id == "ok" ) {
        $(".forma input[type='submit']").val("").removeClass("load").addClass("done");
      } else {
        $(".forma input[type='submit']").val("Enviar").removeClass("load");
        setTimeout(function (){ $("#contacto input[type='submit']").removeAttr("disabled") }, 3000);
        $('.forma input[name="'+msg.id+'"]').focus();
        $('.forma select[name="'+msg.id+'"]').focus();
        $('.forma textarea[name="'+msg.id+'"]').focus();
      }
      $("#status").hide().html(msg.mensaje).fadeIn();
      setTimeout(function () { $("#status").fadeOut() }, 3000);
    }, "json");
    return false;
  });

  $(".votar li a").click(function(){
    rid = $(this).parents(".votar").attr("id");
    $.post(Main+"/ajax/votar.php", { q: $(this).attr("id"), id: rid }, function(msg){
      alert(msg);
      window.location.reload();
    });
    return false;
  });

  $("#back.cambiar").toggle(
    function () {
      $(this).text("Persona");
      $("#persona").fadeOut(function(){ $("#empresa").fadeIn(); });
    },
    function () {
      $(this).text("Empresa");
      $("#empresa").fadeOut(function(){ $("#persona").fadeIn(); });
    }
  );

  carplaying = true;
  function historia_carousel(carousel){
    carousel.buttonNext.click( function() {
      if ( carplaying == true ) $("#pp").click();
    });
    carousel.buttonPrev.click( function() {
      if ( carplaying == true ) $("#pp").click();
    });
    $('#control a').click(function() {
      $("#control .active").removeClass();
      $(this).addClass("active");
      carousel.scroll(jQuery.jcarousel.intval($(this).attr("id")));
      return false;
    });
    $("#pp").click(function() {
      if ( carplaying != true ){
        $(this).removeClass().addClass("play");
        carousel.startAuto();
        carplaying = true;
      } else {
        $(this).removeClass().addClass("pausa");
        carousel.stopAuto();
        carplaying = false;
      }
    });
    carousel.clip.hover(
      function() { if ( carplaying == true ) carousel.stopAuto() },
      function() { if ( carplaying == true ) carousel.startAuto() }
    );
  };
  function item_vis(carousel, item, idx, state) {
    // ida = ( idx <= 12 ) ? idx : idx - 12;
    $("#control .active").removeClass();
    $("a#"+idx).addClass("active");
  };
  $('#slider').jcarousel({
      scroll: 1,
      auto: 12,
      wrap: "both",
      initCallback: historia_carousel,
      itemVisibleInCallback: { onBeforeAnimation: item_vis }
  });
  $('#productos.slider').jcarousel({
      scroll: 1,
      initCallback: historia_carousel,
      itemVisibleInCallback: { onBeforeAnimation: item_vis }
  });

	$.superbox.settings = {
	loadTxt: "Cargando...", // Loading text
	closeTxt: "<img src='"+Main+"/images/bg_btn_cerrar.gif'>", // "Close" button text
	};
  
  
  $('#texto').blur(function(){
    if ( $(this).val() != "" ) $(this).css("background-color","#ffffff");
    else $(this).css("background","none");
  });

  if ( $('#texto').val() != "" ) $('#texto').css("background-color","#ffffff");

  $('#mosval').click(function(){
    $(".cols").animate({left:'-=440'});
  });

  $('#mosmis').click(function(){
    $(".cols").animate({left:'+=440'});
  });

  $('#vermas').toggle(
    function(){
      $(this).text("Ver menos recetas");
      $("#navi").animate({height:'+=290'});
    },
    function(){
      $(this).text("Ver m\u00E1s recetas");
      $("#navi").animate({height:'-=290'});
    }
  );

  $('#vermasart').toggle(
    function(){
      $(this).text("Ver menos art\u00EDculos");
      $("#navi").animate({height:'+=290'});
    },
    function(){
      $(this).text("Ver m\u00E1s art\u00EDculos");
      $("#navi").animate({height:'-=290'});
    }
  );
  
  $('#vermaspromo').toggle(
    function(){
      $(this).text("Ver menos");
      $("#navi").animate({height:'+=140'});
    },
    function(){
      $(this).text("Ver m\u00E1s");
      $("#navi").animate({height:'-=140'});
    }
  );
  $(".fav").click(function(){
    $.post(Main+"/ajax/fav.php", { id: $(this).attr("id") }, function(msg){
      alert(msg);
    });
    return false;
  });

  setTimeout(function () { $("#cstatus").fadeOut() }, 10000);
  $.superbox();

});
