
//window.addEvent('load', function() { - from MooTools to jQuery
$(document).load(function() {

  // Transparency hack for IE 6 (MooTools)
  //if (Browser.Engine.trident4) {
  //[$$('img[src$=.png]'), $('nav')].each(function(item) {
  //  item.setStyle('behavior', 'url(/_scripts/pngfix.htc)');
  //});
  //}

  // Transparency hack for IE6
  if ($.browser.msie) {
    if ($.browser.version <= 6) {
      [$('img[src$=.png]'), $('nav')].each(function(item) {
        item.css('behavior', 'url(/_scripts/pngfix.htc)');
      });
    }
  }

  // CSS3 hack for IE6+IE7
  //if (Browser.Engine.trident4) $$('div.AspNet-Menu-Horizontal li:first-child').setStyle('border-left', 'none');
  //if (Browser.Engine.trident) $$('div.AspNet-Menu-Horizontal ul ul').setStyle('opacity', 0.7);

  // CSS3 hack for IE6+IE7
  if ($.browser.msie) {
    if ($.browser.version <= 6) {
      $('div.AspNet-Menu-Horizontal li:first-child').css('border-left', 'none');
    }
    $('div.AspNet-Menu-Horizontal ul ul').css('opacity', 0.7);
  }

});


//window.addEvent('domready', function() { - from MooTools to jQuery
$(document).ready(function() {

  // replace all rel=external links with target=_blank
  //$$('a[rel=external]').setProperty('target', '_blank');
  $('a[rel=external]').attr('target', '_blank');
  
  // replace all rel=mediaitem links (media related to page) with target=blank
  //$$('a[rel=mediaitem]').setProperty('target', '_blank');
  $('a[rel=mediaitem]').attr('target', '_blank');

  getProductColors();

});

function getProductColors() {

  if ($('#Products')) {

    $('#Products input[type=hidden]').each(function(index) {
      var hfID = $(this).attr('id');
      var hfVal = $(this).val();
      // mp_cphArticle_ProductControl_Repeater3_ctl01_hfProdCode    (input:hiddenfield {input})
      // mp_cphArticle_ProductControl_Repeater3_ctl01_pnlProdColors (div              {output})
      var divTarget = hfID.replace('hfProdCode', 'pnlProdColors');
      $.ajax({ url: '/_components/productcolors.ashx?c=' + hfVal,
               context: $('#' + divTarget),
               success: function(data) {
                 $(this).html(data).find('a.productColor').colorSwapThumbnail();
               }
             });
    });

  }
}

$.fn.colorSwapThumbnail = function() {
    return this.each(function() {
        $(this).hover(function() {
            $(this).parent().parent()
                .find('.currentColor').removeClass('currentColor');
            $(this).parent().addClass('currentColor');
            $(this).parent().parent().parent().parent()
                .find('.prodImg img').attr('src', '/_images/product/thumbs/' + this.className.replace('productColor ', '') + '.png')
                .parent().attr('href', $(this).attr('href'))
                .parent().nextAll('a').attr('href', $(this).attr('href'));
        });
    });
}
