 $(function(){
  // Position label over text fields
  $("label.overfield").siblings("input[type=text], textarea").focus(function(){
    $(this).parent().find("label").hide();    
  }).blur(function(){
    if (!$(this).val()) $(this).parent().find("label").show();    
  }).each(function(){
    if ($(this).val()) $(this).parent().find("label").hide();
    else $(this).parent().find("label").show();
    $(this).attr("title", "");
  });
  
  // Hover fix for IE 6
  if ($.browser.msie && parseInt(jQuery.browser.version) < 7)
  {
    $("#primary > ul > li").hover(function(){
      $(this).addClass("hover");
      if ($(this).hasClass("expanded")) $(this).addClass("hover-expanded");
    }, function(){
      $(this).removeClass("hover");
      if ($(this).hasClass("expanded")) $(this).removeClass("hover-expanded");
    });
    $("#primary div.li li").hover(function(){
      $(this).addClass("hover");
    }, function(){
      $(this).removeClass("hover");
    });
  }
  
  $("#primary div.li li a").hover(function(){
      if ($(this).attr("rel"))
      {
        $(this).closest("div.li").find("dl").addClass("hide");
        $("#"+$(this).attr("rel")).removeClass("hide");
      }
    }, function(){
      if ($(this).attr("rel"))
      {
        $(this).closest("div.li").find("dl").addClass("hide");
        $(this).closest("div.li").find("dl:first").removeClass("hide");
      }
    });
  
  $("#secondary ul li:not(.expanded) ul").hide();
  $("#secondary li").has("ul").find(">a").click(function(){
    
    subtree = $(this).parent();
    if (subtree.length)
    {
      if (subtree.hasClass("expanded")) 
      {
        subtree.find("ul").slideUp();
        subtree.removeClass("expanded");
      }
      else
      {
        subtree.find("ul").slideDown();
        subtree.addClass("expanded");
      }
      return false;
    }
  });
  
  $(".tab-content .hide").hide();
  $(".tabs a").click(function(){
    if ($($(this).attr("href")).length)
    {
      $($(this).attr("href")).show();
      $(this).closest("ul").find("li").removeClass("active");
      $(this).parent().addClass("active");
      $($(this).attr("href")).siblings().hide();
    }
    return false;
  });
  
  $("#content h1").each(function(){
    $(this).css("padding-right", $(this).nextAll(".pager:first").width()+10+"px")
  });
  if (!$.browser.webkit)
  {
    $("#product-detail .tab-content .image .item").each(function(){
      $(this).find("img").css("margin-top", ($(this).height() - $(this).find("img").height())/2 +"px")
    });
    
//    $("#product-detail .top-left .image").each(function(){
//      $(this).css("margin-top", ($("#product-detail .top-right").height() - $(this).height())/2 +"px")
//    });
  }
  
  $("a.colorbox").colorbox({transition:"fade"});

  $('.all-rand').cycle({fx: 'fade'});
  $('.new-product-div').cycle({fx: 'scrollUp'});
});

