var currentTooltip = false;
var previousShowBigger = false;

$(function() {
  // Open link in new window
  $(".external").attr("target","_blank");
  
  $("input").focus(function() {
    if( this.value == this.defaultValue ) {
      this.value = "";
    }
  }).blur(function() {
    if( !this.value.length ) {
      this.value = this.defaultValue;
    }
  });
  
  if($('#equalize').equalHeights) 
    $('#equalize').equalHeights(true);
  
  // Write elements when javascript is enabled
  $(".image_slider, .theme-image").append("<img src='/static/vogelsinternetpresentation/images/globals/corner-slide-lt.png' class='corner-slide' alt='' />");
  $(".image_slider").append("<img src='/static/vogelsinternetpresentation/images/globals/corner-slide-lb.png' class='corner-slide-lb' alt='' />");
  $(".theme-image").append("<img src='/static/vogelsinternetpresentation/images/globals/corner-slide-lb.png' class='corner-theme-lb' alt='' />");
  $(".theme-image").append("<img src='/static/vogelsinternetpresentation/images/globals/corner-slide-rt.png' class='corner-theme-rt' alt='' />");
  $(".theme-image").append("<img src='/static/vogelsinternetpresentation/images/globals/corner-slide-rb.png' class='corner-theme-rb' alt='' />");

  $('.media-right img, .media-left img').each(function(){
    width = this.width + 2;
    $(this.parentNode.parentNode).css('width', width + 'px');
    
    this.onload = function(){
      width = this.width + 2;
      $(this.parentNode.parentNode).css('width', width + 'px');
    }
  });
    
  $(".media-right span, .media-left span").prepend("<img src='/static/vogelsinternetpresentation/images/globals/border-lt.png' class='border-lt' alt='' />");
  $(".media-right span, .media-left span").prepend("<img src='/static/vogelsinternetpresentation/images/globals/border-rt.png' class='border-rt' alt='' />");
  $(".media-right span, .media-left span").prepend("<img src='/static/vogelsinternetpresentation/images/globals/border-lb.png' class='border-lb' alt='' />");
  $(".media-right span, .media-left span").prepend("<img src='/static/vogelsinternetpresentation/images/globals/border-rb.png' class='border-rb' alt='' />");

  
  //$(".refine-afb li span, .result-afb li span, .sort-video li span, .image-thumbs dd a, .sort-column span a").prepend("<img src='/static/vogelsinternetpresentation/images/globals/border-86x65.png' class='border86x65' alt='' />");
  $(".result-afb li span, .sort-video li span, .image-thumbs dd a, .sort-column span a").prepend("<img src='/static/vogelsinternetpresentation/images/globals/border-86x65.png' class='border86x65' alt='' />");
  $(".refine-afb-wide li span").prepend("<img src='/static/vogelsinternetpresentation/images/globals/border-220x165.png' class='border220x165' alt='' />");
  $(".image-fragment a, .block-sidebar-grey span").prepend("<img src='/static/vogelsinternetpresentation/images/globals/border-86x65.png' class='border-thumbs' alt='' />");
  $(".image-big a").prepend("<img src='/static/vogelsinternetpresentation/images/globals/border-368x276.png' class='border-big' alt='' />");
  $(".product-overview span a").prepend("<img src='/static/vogelsinternetpresentation/images/globals/border-111x111.png' class='overlay-img' alt='' />");
  $(".product-overview:nth-child(odd)").addClass("margin-right18");
  $(".news-links li:last-child").addClass("rss-news-home");

  
  $(".hide-info, #frm-download-hidden").hide()
  $(".more-info, .hide-info, .close").click(function() {
  
    if ($(this).hasClass('more-info')){
      $(this).removeClass('more-info').addClass('hide-info');
      $(this).children('a').hide();
      $(this).children('.hide-more-info').show();
    }
    else{
      $(this).removeClass('hide-info').addClass('more-info');
      $(this).children('a').show();
      $(this).children('.hide-more-info').hide();
    }
    $("#more-text, #frm-download-hidden").slideToggle("slow");
  });
  
  // Hover and click the brandlist
  $(".news-column, .table-download tr td").click(function(){
    window.location=$(this).find("a").attr("href");return false;
  });
  $(".news-column, .table-download tr").hover(function(){
    $(this).addClass('over-pointer'); // Plaats een class op een hover
  },function(){
  $(this).removeClass('over-pointer'); // Verwijder de class op een mouseout
  });

  
  // Stripe
  $(".detail-table li:nth-child(even), .table-detail tr:nth-child(even)").addClass("striped");
  $(".page-options li:nth-child(even)").addClass("print-page");
  $(".compare tr").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
  $(".compare tr:nth-child(even), .table-download tr:nth-child(even)").addClass("stripe-table");
  
  // $(".refine dd:last-child").addClass("bullet-refine");
  $(".address-list ul li:first-child").addClass("block-address");
  $(".address-list ul li:nth-child(2)").addClass("prev-address");
  $("#news-column dl dd:last-child").addClass("all-news");
  
  // Hide tooltip
  $(".tooltip, .hover-tip").click(function() {
    node = this;
    do{
      cn = node.className;
    }
    while(!cn.match(/tooltip(\d+)/) && (node=node.parentNode));
    
    tooltipID = cn.match(/tooltip(\d+)/);
    if (tooltipID){
      tooltipID = tooltipID[1];
      
      $('.hover-tip.tooltip' + tooltipID + ', .tooltip.tooltip' + tooltipID).animate({ opacity: 'hide' }, "slow")
    
    }
    else{
      $(".tooltip, .hover-tip").animate({ opacity: 'hide' }, "slow")
    }
    });
    
    // Show tooltip
    $(".show-tooltip").click(function() {
    if (tooltipID = this.className.match(/tooltip(\d+)/)){
      if (currentTooltip){
        $('.tooltip.tooltip' + currentTooltip).animate({ opacity: 'hide' }, "slow")
      }
      currentTooltip = tooltipID = tooltipID[1] * 1;
      $('.tooltip.tooltip' + tooltipID).animate({ opacity: 'show' }, "slow")
    }
    });

  // Show tooltip
    $(".hover-tooltip").hover(function() {
    if (tooltipID = this.className.match(/tooltip(\d+)/)){

      tooltipID = tooltipID[1] * 1;
      $('.hover-tip.tooltip' + tooltipID ).animate({ opacity: 'show' }, "slow")
    }
    }, function(){}); 
  
  window.bind_click = function(){
    // remove ALL click handlers - including PrettyPhoto.click()
    $('.show-bigger').unbind('click');
  
    // Show 2nd size image in bigger image box
    // allow 3rd size image to be shown in prettyphoto box.
    $('.show-bigger').click(function(){
      relSplit = this.rel.split(/\s/);
      
      image_id = relSplit[1];
      image_url = relSplit[2];
      
      $('#' + image_id).attr('src', image_url);
      $('#' + image_id).attr('alt', this.childNodes[1].alt);
      $('#' + image_id).parent().attr('href', this.href);

      return false;
    });
  }
  window.bind_click();
  
  $(".get-media,.hide-media").click(function() {
    
    $(this).parent().find('.showed-media').slideToggle("fast",
    
      function(){ 
        if (this.style.display != 'none'){
          $(this).parent().find('.hide-media').css('display', 'block');
          $(this).parent().find('.get-media').css('display', 'none');
        }
        else{
          $(this).parent().find('.hide-media').css('display', 'none');
          $(this).parent().find('.get-media').css('display', 'block');        
        }
      }
    
    );
    
  });
  
  $(".pane .verwijder").click(function(){
  
    if ($('.pane:not(.hidden)').length<=1){
      var feedback = function(){
        $('#download-actions').hide();
        $('#basket-empty').animate({ opacity: 'show' } , 'slow');
      }
    }
    else{
      var feedback = null;
    }
    $(this).parents(".pane").animate({ opacity: 'hide' }, "slow", feedback).addClass('hidden');
    

  });

  
  // PNG fix for IE
  $('img[@src$=.png],ul#sub-tabs li a, .home h2, ul#innerfade_list li.current a, ul#random_images li span, #random_images dt, .product-overview h2 a').ifixpng();
  
});