// JavaScript OnLoad Document for KAO Ban website
$(document).ready(function (){
  $.preLoadImages('/images/products_solids_over.jpg','/images/products_roll-ons_over.jpg','/images/logos_all_over.jpg');
  $(".scrollpane").jScrollPane();
  $("#faq_qa h2, #faq_qa dl").hide();
  $("#faq_qa h2.how_work, #faq_qa dl.how_work").show();
  $(".submit").attr({value: ''});
  $(".eventPage input[type='submit']").attr({value: ''});
  $("a[href='#charts']").click(function(e){
    e.preventDefault();
    $("#charts a").colorbox({
      open: "true",
      rel: "chartphotos",
      current:"Chart {current} of {total}",
      scrolling: "true"
    });
    $('html, body').animate({scrollTop: "100px"}, 1500);
    $('html, body').mousewheel(function(){$('html, body').stop();});
  });
  $().bind('cbox_complete', function(){
    $('html, body').animate({scrollTop: "100px"}, 1500);});
  $().bind('cbox_closed', function(){
    $('html, body').animate({scrollTop: "0px"}, 500);});

  // Events
  // Solid mouse hover
  $("#solids_image").mouseover(function(){
    $("#solids_text:animated").stop({clearQueue: true});
    if($("#solids_text").css("display") == "none") $("#solids_text").fadeIn("fast");
    else $("#solids_text").fadeTo(400, 1.0);
    $("#products").addClass("solids"); //.fadeIn("slow"); //remove fadeIn for instant
  });
  $("#solids_image").mouseout(function(){
    $("#solids_text").fadeTo(0, 0.0);
    $("#products").removeClass("solids"); //.hide().fadeIn("slow");  //remove hide and fadeIn for instant
  });
  
  // Roll-on mouse hover
  $("#roll-ons_image").mouseover(function(){
    $("#roll-ons_text:animated").stop({clearQueue: true});
    if($("#roll-ons_text").css("display") == "none") $("#roll-ons_text").fadeIn("fast");
    else $("#roll-ons_text").fadeTo(400, 1.0);
    $("#products").addClass("roll-ons"); //.fadeIn("slow");  //remove fadeIn for instant
  });
  $("#roll-ons_image").mouseout(function(){
    $("#roll-ons_text").fadeTo(0, 0.0);
    $("#products").removeClass("roll-ons"); //.hide().fadeIn("slow");  //remove hide and fadeIn for instant
  });
  // If fadeIn code is removed, also need to remove display: none
  // in the roll-ons and solids classes in global.css
  
  
  // FAQ page events
  $("#faq_sidebar li a").click(function(e){
    e.preventDefault();
    $("#faq_sidebar li").removeClass("active");
    $(this).parent().addClass("active");
    var faqtoshow = $(this).attr("href");
    faqtoshow = "."+faqtoshow.substring(1);
    $("#faq_qa h2, #faq_qa dl").hide();
    $("#faq_qa h2"+faqtoshow).show();
    $("#faq_qa dl"+faqtoshow).show();
  });
  $("#faq_qa h2 a").click(function (e){
    e.preventDefault();
    $("#faq_sidebar li").removeClass("active");
    $("#faq_sidebar li#fn_work").addClass("active");
    $.scrollTo(0);
  });
});
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
