$(function() {
  $("div#asseenon_slider").easySlider({
    auto: true,
    continuous: true,
    controlsShow: false
  });

  // main menu

  $("#dropdown li ul").hover(
    function(){
     $(this).parent().find('a').addClass('hover');
  }, function() {
     $(this).parent().find('a').removeClass('hover');
  })
 
  // search input

  if ($("#search_box input").val() != "") {
      $("#search_box label").hide();
  }
  $("#search_box label").click(function(){
    $(this).hide();
  })
  $("#search_box input").blur(function(){
    if ($(this).val() == "") {
      $("#search_box label").show("fast");
    }
  })

  // newsletter input

  if ($(".newsletter-box input").val() != "") {
      $(".newsletter-box label").hide();
  }
  $(".newsletter-box label").click(function(){
    $(this).hide();
  })
  $(".newsletter-box input").blur(function(){
    if ($(this).val() == "") {
      $(".newsletter-box label").show("fast");
    }
  })

  //count the amount of thumbnails
  var th_num = $(".product_thumbs div > a").size();
  var th_pos = 0;

  //show arrows only if thumbnails are more than 3
  if (th_num <= 3) {
    $('.slide_left').hide();
    $('.slide_right').hide();
  } else {
    $('.slide_left').addClass('hide');
  }

  //product thumbnail enlarge
  $(".product_thumbs div a").click(function(){
    $(this).parent().find("a").each(function(){
      $(this).removeClass("active");
    })
    $(this).addClass("active");
    $(".product_image").attr("src", $(this).attr('href'));
    return false;
  });

  //product thumbnail scroll
  $('.slide_right').click(function() {
    if (th_pos < th_num-1) {
      th_pos += 1;
      //animate thumbnail to right. 62 — width of each thumbnail
      $(this).parent().find('#thumb_slider').animate({left: '-'+th_pos*62 + 'px'}, 100);
      $(this).parent().find('.slide_left').removeClass('hide');
      if (th_pos == th_num-1) {
        $(this).addClass('hide');
      }
    } else {
      $(this).addClass('hide');
      $(this).parent().find('.slide_left').removeClass('hide');
    }
    return false;
  });
  $('.slide_left').click(function() {
    if (th_pos > 0) {
      th_pos -= 1;
      //animate thumbnail to left. 62 — width of each thumbnail
      $(this).parent().find('#thumb_slider').animate({left: '-'+th_pos*62 + 'px'}, 100);
      $(this).parent().find('.slide_right').removeClass('hide');
      if (th_pos == 0) {
        $(this).addClass('hide');
      }
    } else {
      $(this).addClass('hide');
      $(this).parent().find('.slide_right').removeClass('hide');
    }
    return false;
  });

});


function calc_num(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (s.length < 2)
    s = "0" + s;
  return s;
}

function PriceTimer(secs) {
  if (secs < 0) {
    document.getElementById("price_timer").innerHTML = MesgExpired;
    window.location.href = PriceTimerURL;
    return;
  }
  MesgTimerStr = MesgStart + calc_num(secs,60,60) + ":" + calc_num(secs,1,60) + MesgEnd;
  document.getElementById("price_timer").innerHTML = MesgTimerStr;
  setTimeout("PriceTimer(" + (secs-1) + ")", 1000);
}


