var current_rollover;

$(document).ready(function() {
  
  // Fix background PNGs in IE6
  fix_pngs();
  
  
  $('#primary-links > ul > li.expanded').mouseover(function() {
    if (current_rollover != this.id) {
      menu_rollout(current_rollover);
    }
        
    clearTimeout(this.t);
    $(this).addClass('over');
    current_rollover = this.id;
  });
  
  $('#primary-links > ul > li.expanded').mouseout(function() {
    this.t = setTimeout("menu_rollout('" + this.id + "');", 1000);
  });
  
  // make content links open in a new window
  $(function() {
    $('a[@href^=http]').not('[@href*=butterlondon.com]').not('[@href*=butterlondon.local]').not('[@href*=butterlondondev.com]').not('[@href*=butterlondon-drupal.wants.thisbythem.com]').not('[@href*=butterlondon.wants.thisbythem.com]')
      .addClass('external-link')
      .click(function() {
        window.open(this.href, '_blank');
        return false;
      });
  });
  
});

function menu_rollout(id) {
  var item = $('#'+id);
  item.removeClass('over');
}

function fix_pngs() {
  if (navigator.appVersion.match(/MSIE [0-6]\./)) {
    $('.png').each(function () {
      if (this.currentStyle.backgroundImage != 'none') {
        var image = this.currentStyle.backgroundImage;
        image = this.currentStyle.backgroundImage.substring(5, image.length - 2);
        $(this).css({
          'backgroundImage': 'none',
          'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
        });
      }
    });
  }
}

