var ie6, ie7, ie8;
$(function () {
  if(jQuery.browser.safari && document.readyState != "complete") {
    setTimeout( arguments.callee, 100 );
    return;
  }
  
  ie6 = $.browser.msie && $.browser.version < 7 || false,
  ie7 = !ie6 && $.browser.msie && $.browser.version < 8 || false,
  ie8 = !ie7 && $.browser.msie && $.browser.version < 9 || false;

  $("#browseProducts")
    .find("ul li")
    .last()
    .remove(); // temporarilly removing the product search feature
  
  if (/video-library/i.test(window.location.href)) {
    $("article")
      .removeClass()
      .addClass("grid_12");
    
    $("aside")
      .remove();

    $("#vimeos")
      .cmpvimeo();
  }
  
  // this is hilarious!
  $("dl.alphaHeadings").
    alphaHeadings();
  
  $("span.email").
    autoEmailLinks();
  
  $("#browseProducts").
    browseProducts();
  
  $("a.bulleted").
    bulleted();
  
  $(".centurion_rotator").
    centurion_rotator();
  
  $("button, input[type=button], input[type=submit]").
    imageButtons();
  
  $("#productImages").
    productImages();
  
  $(".productMedia").
    productMedia();
  
  $("#soiledLinen").
    soiledLinen();
  
  $("div#CMP-SaleRegionsMap").
    salesRegions();
  
  $(".verticalSlider")
    .verticalSlider();
    //.vertSlider();
  
  // no marching ants on main menu
  $("nav ul a").
    click(function () {
      this.blur();
    });
  
  // disable right-click on images
  //$("img").bind("contextmenu", function () {return false;});
  
  // inject the centurion direct link into the products and services sub-menu list
  $("nav > ul > li.selected").
    filter(function () {
      return /^products/i.test($(this).children("a").text());
    }).
      children("ul").
        append("<li><a href=\"//www.centuriondirect.com\">Centurion Direct</a></li>");
  
  // fake the video link on the home page for demo purposes.
  $("div#corporateOverview")
    .click(function () {
      var cmpOverview = '<iframe src="http://player.vimeo.com/video/36082925" width="601" height="338" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'
      $().colorbox({
         fastIframe  : false
        ,fixed       : true
        ,innerHeight : /height.+?(\d+)/.exec(cmpOverview)[1]
        ,html        : cmpOverview
        ,onComplete  : function () {
          $("#cboxLoadedContent")
            .removeAttr("style");
        }
        ,returnFocus : true
        ,scrolling   : false
        ,innerWidth  : /width.+?(\d+)/.exec(cmpOverview)[1]
      });
    })
    .css({
       "background": "url('/media/51658-videothumb.jpg') scroll no-repeat 0px 0px"
      ,"border": "1px solid"
      ,"cursor": "pointer"
      ,"height": 165
      ,"margin-top": "1em"
      ,"position": "relative"
      ,"width": 298
    }).
    html("");
  
  // add user agent className for use in css to help style things in diff browsers
  (function (h) {
    $.each(["msie", "mozilla", "webkit"], function (i, a) {
      !$.browser[a]
        ? h.addClass("not-" + a)
        : h.addClass(a);
    });
  }($("html")));
});
