﻿$(document).ready(function() {
  var recentlyAdded = $('.RecentlyAdded');
  var newTable = $('<table id="recentTable" style="background-color: yellow"></table>');
  var Tds = $('.RecentlyAdded td.NEW');
  if (Tds) {
    var copyTds = Tds.clone().removeClass().addClass('recentAddons').wrap('<tr></tr>');
    $(copyTds).find('h5').remove();

    $('#RecentAddons').append('<h3>Recent Add-Ons and Plug-Ins</h3>');
    $(copyTds).wrap('<table id="recentTable" style="background-color: yellow"></table>').appendTo('#RecentAddons');
    $('#RecentAddons table').remove();

  }
  else {
    $('#RecentAddons').remove();
  }

  var showDate = new Date();
  showDate.setFullYear(2010, 1, 22);
  var today = new Date();

  // see if this is a product page with sku querystring
  var qs = window.location.href.split("?");

  if (1 < qs.length) {
    // get sku from product page
    var sku = qs[1].toUpperCase(); // get the ?sku-part if a product page
    //alert(sku);

    if (sku) {
      
//      console.log("sku before: " + sku);
      sku = sku.replace(".", "-"); // replace periods with "-" jQuery does not like periods.
//      console.log("sku after:  " + sku);

      // add "loading..." spinner image to div & load appropriate award section of awards page (turning off the heading link)
      $('div.thisAward')
        .html("<img src='/Images/Icons/indicator.gif'></img>")
        .load('/company/press/awards.aspx div.Award-' + sku, function() {
          $('h2.headingLink').remove(); // do not need link to self
        });
    }
  }







  //  $('.RecentlyAdded').wrapAll("<table id='recentTable' style='background-color: yellow'></table>").after('div#RecentAddons');


  //$(recentlyAdded).parent().parent().css("border","thin solid red");
  //      var prodImg = $(recentlyAdded td);
  //      var prodLink = $('td.Content form#frm > p table[width=100%] td[width=87%] a').css("border", "thin solid red");
  //      var prodLinkText = $('td.Content form#frm > p table[width=100%] td[width=87%]').text();
  //      console.log("===============================================\n");
  //      console.log(prodLinkText);
  //      console.log("===============================================\n");
  //      var prodNewButton = $('td.Content form#frm > p table[width=100%] td[width=87%] h5').css("border", "thin solid red");
  //      var prodOrderTable = $('td.Content form#frm > p table[width=100%] td.p table td').;

  //$('#h1').append(recentlyAdded).css("background-color", "linen");
});

