$(document).ready(function(){
// Top menu
  $("ul#top-menu > li > a").click(function(){
    if ($("body").height() < $(window).height()) {
      $('#menu-overlay').height($(window).height());
    } else {
      $('#menu-overlay').height($("body").height());
    }
    if ($(this).parent().children("div").length != 0) {
      $(this).parent().siblings().removeClass("act").children("div").hide("300");
      $(this).parent().addClass("act").children("div").show("300");
      if($.browser.msie && ($.browser.version=="7.0" || $.browser.version=="8.0")) {
        $("div#menu-overlay").css({opacity: 0});
      }
      if(!($.browser.msie) || ($.browser.msie && $.browser.version!="6.0")) {
        $("div#menu-overlay").css({'display':'block'}).animate({opacity: 0.33}, { duration: 500, queue: false });
      }
      return false;
    }
  });
  $(".sub-menu-close-button").click(function(){
    $(this).parent().parent().removeClass("act").children("div").hide("300");
    if(!($.browser.msie) || ($.browser.msie && $.browser.version!="6.0")) {
      $("div#menu-overlay").css({'display':'none'});
    }
    return false;
  });

// Top menu ends
  $("div.sub-menu > ul:last-child").css({'border':0});
  $("div.column-fourth").last().css({'border':0});
// Clickable images in corresponding divs
  $(".product-preview").click(function(){
    window.location=$(this).find("a").attr("href"); return false;
  });
  $(".top-pick").click(function(){
    window.location=$(this).find("a").attr("href"); return false;
  });
// Clickable images in corresponding divs ends

// Tooltips
  $("a[title]").tooltip({
    position:"top center",
    offset: [5, 0],
    effect: 'slide',
    predelay: 300
  }).dynamic({ bottom: { direction: 'down', bounce: true } });
  $("div[title]").tooltip({
    position:"center center",
    offset: [-50, 0],
    effect: 'slide',
    predelay: 300
  }).dynamic({ bottom: { direction: 'down', bounce: true } });
// Tooltips ends

// Map highlight
  $('img[usemap]').maphilight()
// Map highlight ends

// Fancybox
  $("a.gallery-image").fancybox({
    'opacity':'false',
    'easingIn': 'easeOutBack',
    'easingOut': 'easeInBack',
    'overlayOpacity': 0.75,
    'overlayColor': '#000',
    'titlePosition': 'over',
    'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
      return '<span id="fancybox-title-over">' +  (currentIndex + 1) + ' / ' + currentArray.length + '<br>'+title+'</span>';
    },
    'centerOnScroll':'true'
  });
  $("a.product-image").fancybox({
    'opacity':'false',
    'easingIn': 'easeOutBack',
    'easingOut': 'easeInBack',
    'overlayOpacity': 0.75,
    'overlayColor': '#000',
    'titlePosition': 'none',
    'centerOnScroll':'true'
  });
  $("a.modalWindow").fancybox({
    'width':640,
    'height':420,
    'opacity':'false',
    'type': 'iframe',
    'modal':'true',
    'easingIn': 'easeOutBack',
    'easingOut': 'easeInBack',
    'overlayOpacity': 0.75,
    'overlayColor': '#000',
    'centerOnScroll':'true'
  });
  $("a.compareWindow").fancybox({
    'width':'96%',
    'height':'96%',
    'opacity':'false',
    'type': 'iframe',
    'easingIn': 'easeOutBack',
    'easingOut': 'easeInBack',
    'overlayOpacity': 0.75,
    'overlayColor': '#000',
    'onClosed': function() {
      location.reload(true);
    },
    'centerOnScroll':'true'
  });
// Fancybox ends

// Accordions & tabs
  $(function() {
    $("#accordion").tabs("#accordion div", {tabs: 'h2', effect: 'slide', initialIndex: 0});
  });
  $(function() {
    $("#product-image-changer").tabs("#panes > span", {effect: 'fade', fadeOutSpeed: 400});
  });
// Accordions & tabs ends

// Open external links in _blank from retailer list
  $('.retailer-list a[href^="http://"]')
  .attr("target", "_blank");
// Open external links in _blank from retailer list ends
});

// Product search input
function onFocusProductSearch(input) {
  if(input.value=='Etsi tuotteita' || input.value=='Search products' || input.value=='Produktsuche') {
    input.value='';
  }
};
// Product search input ends
