/* ################################################################# */
/*                                                                   */
/*  TITLE:        GLOBAL.JS                                          */
/*  SITE:         men.style.com                                      */
/*  VERSION:      1.01                                               */
/*  LAST UPDATED: 2008/01/30                                         */
/*  UPDATED BY:   Jamilee Brown                                      */
/*                                                                   */
/* ################################################################# */
var browserPath = location.pathname;
var slideshowIndex = browserPath.indexOf('slideshow');


function includeJS(url) { document.writeln("<script type=\"text/javascript\" src=\"" + url + "\"></script>"); }
function includeCSS(url) { document.writeln("<style type=\"text/css\">@import url(\"" + url + "\");</style>"); }
 
includeJS("/scripts/HP.js");

if (slideshowIndex == -1) {
includeJS("/scripts/UtilityFunctions.js");
includeJS("/scripts/EventHandler.js");
includeJS("/scripts/CNT_ScrollBar.js");
includeJS("/scripts/CNT_RollOvers.js");
includeJS("/scripts/BrowserDetect.js");
includeJS("/scripts/prototype/prototype.js");
includeJS("/scripts/yui/build/yahoo-dom-event/yahoo-dom-event.js");
includeJS("/scripts/registration.js");
includeJS("/scripts/HP.js");
includeJS("/scripts/mbox.js");
}
/*
includeJS("/scripts/UtilityFunctions.js");
includeJS("/scripts/EventHandler.js");
includeJS("/scripts/CNT_ScrollBar.js");
includeJS("/scripts/CNT_RollOvers.js");
includeJS("/scripts/BrowserDetect.js");
includeJS("/scripts/prototype/prototype.js");
includeJS("/scripts/yui/build/yahoo-dom-event/yahoo-dom-event.js");
includeJS("/scripts/registration.js");
includeJS("/scripts/mbox.js");
*/
    dart = new Object();
    dart["sz"] = "";
    dart["site"] = "";
    dart["zone"] = "";
    dart["target"] = "";
    dart["url"] = "";
    dart["dcopt"] = "";

/* cache css bg images for IE6 */
if ( document.all )
{  
    try {
      document.execCommand("BackgroundImageCache", false, true);
    } catch(err) {}
}

//date for Homepage
var monthNames = new Array(
"January","February","March","April","May","June","July",
"August","September","October","November","December");

var dayNames = new Array(
"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");

var now = new Date();

//popups
window.name="main";

function popFullWindow(url) 
{ 
  var slideWindow="";
  slideWindow = window.open(url,'New Window','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=800,height=600, top=5, left=5');
  slideWindow.focus();
}
 

function popVideoConsole(url) 
{ 
  var videoWindow="";
  videoWindow = window.open(url,'Video','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=1050,height=723, top=5, left=5');
  videoWindow.focus();
}

function popGQRules(url) 
{ 
  var GQRulesWindow="";
  GQRulesWindow = window.open(url,'GQRules','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1020,height=768, top=5, left=5');
  GQRulesWindow.focus();
}

function popGQForm(url) 
{ 
  var slideWindow="";
  slideWindow = window.open(url,'Slideshow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=430,height=680, top=5, left=5');
  slideWindow.focus();
}

function popSlideShowDetails(url) 
{ 
  var slideWindow="";
  slideWindow = window.open(url,'SlideshowDetails','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=752,height=639, top=15, left=15');
}


/* Slideshow page width (old width:752) updated to fit new Ad unit size of 300x250 updates made by mbrown8 on 09/13/07 */

function popSlideShow(url) 
{ 
  var slideWindow="";
  slideWindow = window.open(url,'Slideshow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=845, height=601, top=5, left=5');
  slideWindow.focus();
}

function popSlideShowV(url) 
{ 
  var slideWindow="";
  slideWindow = window.open(url,'Slideshow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=1020,height=602, top=5, left=5');  
  slideWindow.focus();
}


function popSlideShowH(url) 
{ 
  var slideWindow="";
  slideWindow = window.open(url,'Slideshow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=730,height=562, top=5, left=5');
  slideWindow.focus();
}

function popSlideShowU(url) 
{ 
  var slideWindow="";
  slideWindow = window.open(url,'Slideshow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=751,height=620, top=5, left=5');
  slideWindow.focus();
}

function popVideo(url) 
{ 
  var videoWindow="";
  videoWindow = window.open(url,'Video','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=395,height=330, top=5, left=5');
  videoWindow.focus();
}

function popMP3(url) 
{ 
  var videoWindow="";
  videoWindow = window.open(url,'mp3','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=360,height=20, top=250, left=200');
  videoWindow.focus();
}

function popSurvey(url) 
{ 
  var slideWindow="";
  slideWindow = window.open(url,'Survey','toolbar=yes,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=766,height=690, top=5, left=5');
  slideWindow.focus();
}

function popVideoWide(url) 
{ 
  var videoWindow="";
  videoWindow = window.open(url,'Video','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=565,height=330, top=5, left=5');
  videoWindow.focus();
}

function popVideoWider(url) 
{ 
  var videoWindow="";
  videoWindow = window.open(url,'Video','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=715,height=330, top=5, left=5');
  videoWindow.focus();
}

function popVideoDetails(url) 
{ 
  var videoWindow="";
  videoWindow = window.open(url,'Video','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=489,height=340, top=5, left=5');
  videoWindow.focus();
}

function popContact(url) 
{ 
  var pop_width="";
  if (document.all)
  {
    pop_width = 447;
  }
  else
  {
    pop_width = 430;
  }
  var contact="";
  contact = window.open(url,'ContactUs','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + pop_width + ',height=680, top=5, left=5');
  contact.focus();
}

function popAskStyleguy(url) 
{ 
  var pop_width="";
  if (document.all)
  {
    pop_width = 447;
  }
  else
  {
    pop_width = 430;
  }
  var contact="";
  contact = window.open(url,'ContactUs','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + pop_width + ',height=798, top=5, left=5');
  contact.focus();
}

function popAskAlanRichman(url) 
{ 
  var pop_width="";
  if (document.all)
  {
    pop_width = 447;
  }
  else
  {
    pop_width = 430;
  }
  var contact="";
  contact = window.open(url,'ContactUs','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + pop_width + ',height=798, top=5, left=5');
  contact.focus();
}

function RssSeeWindow(url) { 
  var feedWindow="";
  feedWindow = window.open(url,'info', 'left=40,top=40,width=800,height=425,toolbar=1,resizable=1,scrollbars=yes,location=yes,status=yes,menubar=yes,copyhistory=yes');
  feedWindow.focus();
}

//parent window linking
 function parentWin(url) {
            opener.location.href = url;
            window.close();
      }

 function goHome(url) {
            opener.location.href = url;
      }
      
function newsPrevious(article) {
  var thisArticle = 'centercol_item_mid' + article
  var previousArticle;
  switch (thisArticle){
    case "centercol_item_mid1":
      previousArticle = 'centercol_item_mid2';
    break;
    case "centercol_item_mid2":
      previousArticle = 'centercol_item_mid3';
    break;    
    case "centercol_item_mid3":
      previousArticle = 'centercol_item_mid4';
    break;        
    case "centercol_item_mid4":
      previousArticle = 'centercol_item_mid5';
    break;                
  } 
  document.getElementById(thisArticle).style.display = 'none';
  document.getElementById(previousArticle).style.display = 'inline';
}

function newsNext (article) {
  var thisArticle = 'centercol_item_mid' + article
  var nextArticle;
  switch (thisArticle){
    case "centercol_item_mid2":
      nextArticle = 'centercol_item_mid1';
    break;
    case "centercol_item_mid3":
      nextArticle = 'centercol_item_mid2';
    break;    
    case "centercol_item_mid4":
      nextArticle = 'centercol_item_mid3';
    break;        
    case "centercol_item_mid5":
      nextArticle = 'centercol_item_mid4';
    break;                
  } 
  document.getElementById(thisArticle).style.display = 'none';
  document.getElementById(nextArticle).style.display = 'inline';
}



/* CSS Dropdown Functions
  Added by Eric Hwang
  21 Nov. 2005
*/
var totalLists = 1;
var ua = navigator.userAgent.toLowerCase();
var av = navigator.appVersion.toLowerCase();
var mac = ( av.indexOf( 'mac' ) != -1 );
var saf = ( ua.indexOf( 'safari' ) != -1 );
var ie5x = ( document.all && document.getElementById );
var ie5mac = ( mac && ie5x );
var defaultEdgeMargin = 170;

function checkHeight(ListNum, dir, edgeMargin) {
  var space = 1; // space between dropdown and list
  var list = document.getElementById('Lst' + ListNum);
  var drop = document.getElementById('Drp' + ListNum);
  var listPos = findPosY(list);
  var dropPos = findPosY(drop);
  var dropHeight = drop.offsetHeight;
  var winHeight = calcHeight();
  var listTable = document.getElementById('LstTable' + ListNum);
  
  if(saf || ie5mac) {
    if(listTable.offsetHeight + 2 > list.offsetHeight && list.offsetWidth <= listTable.offsetWidth + 2) list.style.width = list.offsetWidth + 15 + "px";
  }

  var scrollOffset = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
  var totalMenuHeight = dropPos + dropHeight + list.offsetHeight - scrollOffset;

  if(typeof(edgeMargin) == "undefined") edgeMargin = defaultEdgeMargin;

  if(!ie5mac) { 
    if(dir == "up") {
      if(list.offsetHeight > dropPos - edgeMargin) { /* if it won't fit above, make it fit */
        list.style.height = dropPos - edgeMargin + "px";
        list.style.overflow = "auto";
        if(saf || ie5mac) {
          if(listTable.offsetHeight + 2 > list.offsetHeight && list.offsetWidth <= listTable.offsetWidth + 2) list.style.width = list.offsetWidth + 15 + "px";
        }
      }
      if(listPos >= dropPos + dropHeight) {
        list.style.top = list.offsetTop - dropHeight - list.offsetHeight - space + "px";
        checkDiscrepancy(list);
      }
    } else {
      if(totalMenuHeight > winHeight ) { /* if menu won't fit below dropdown */
        if(list.offsetHeight > dropPos - scrollOffset) { /* if it also won't fit above, figure out if more space above or below */
          spaceBelow = winHeight - (dropPos + dropHeight - scrollOffset);
          spaceAbove = dropPos - scrollOffset;
          
          if(spaceAbove > spaceBelow) { /* if more space above than below, display above */
            if(listPos >= dropPos + dropHeight) {  /* if the menu is currently set to display below the dropdown */
              if(list.offsetHeight < dropPos) { /* if the menu can fit above the dropdown on the page, move it above */
                list.style.top = list.offsetTop - dropHeight - list.offsetHeight - space + "px";
                checkDiscrepancy(list);
              }
            }
          } else {  /* else display below */
            if(listPos < dropPos) { 
              list.style.top = list.offsetTop + dropHeight + list.offsetHeight + space + "px";
              checkDiscrepancy(list);
            }
          }
        } else if(listPos >= dropPos + dropHeight) {  /* if the menu is currently set to display below the dropdown */
          if(list.offsetHeight < dropPos) { /* if the menu can fit above the dropdown on the page, move it above */
            list.style.top = list.offsetTop - dropHeight - list.offsetHeight - space + "px";
            checkDiscrepancy(list);
          }
        }
      } else { /* else display menu below the dropdown */
        if(listPos < dropPos) {
          list.style.top = list.offsetTop + dropHeight + list.offsetHeight + space + "px";
          checkDiscrepancy(list);
        }
      }
    }
  }
}



/* this function is needed because of a Safari bug regarding style.top and offsetTop, when the dropdown is contained in a div with relative position and a top border */
function checkDiscrepancy(list) {
  // alert(list.style.top + " - " + list.offsetTop);
  tempOffsetTop = parseInt(list.offsetTop);
  tempStyle = parseInt(list.style.top);
  if(tempOffsetTop != tempStyle) {
    diff = tempStyle - tempOffsetTop;
    list.style.top = tempStyle + diff + "px";
    // alert(list.style.top + " - " + list.offsetTop);
  }
}

function calcHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    /*Non-IE*/
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    /*IE 6+ in 'standards compliant mode'*/
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    /*IE 4 compatible*/
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function findPosY(obj) {
  var curtop = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetTop;
      obj = obj.offsetParent;
    }
  }
  else if (obj.y)
    curtop += obj.y;
  return curtop;
}

function closeDropDown(){
  for(i=1; i <= totalLists; i++){
    list = 'Lst'+i;
    if(document.getElementById(list)) {
      ddl = document.getElementById(list).style.display;
      if(ddl=="block" || ddl==""){  
        hideall(i);
        break;
      }
    }
  }
}
  
function hideall(ListNum) {
  divItem = document.getElementById('Lst'+ListNum);
  divItem.style.display="none";
}

function showList(ListNum, dir, edgeMargin) {
  if (document.all && document.getElementById){
    list3 = 'Lst' + ListNum;
    ddl3 = document.getElementById(list3).style.display;  
    for(var i=1; i <= totalLists; i++) {
      if(ddl3=="none") {
        list2='Lst'+i;
        if(document.getElementById(list2)) {
          ddl2 = document.getElementById(list2).style.display;
          if(ddl2=="block" || ddl2=="") { 
            hideall(i); 
          }
          mnu = document.getElementById('Lst'+ListNum);
          mnu.style.display = "block";  
          checkHeight(ListNum, dir, edgeMargin);
        }
      }                   
      if(ddl3=="block") { 
        mnu = document.getElementById('Lst'+ListNum);
        mnu.style.display = "none";
        break;
      }         
    }             
  } else {
    list3='Lst'+ListNum;            
    ddl3=document.getElementById(list3).style.display;  
    for(var i=1; i <= totalLists; i++) {
      if(ddl3=="none") {
        list2='Lst'+i;
        if(document.getElementById(list2)) {
          ddl2=document.getElementById(list2).style.display;
          if(ddl2=="block"||ddl2=="") { 
            hideall(i); 
          }
          mnu = document.getElementById('Lst'+ListNum);
          mnu.style.display = "";
          checkHeight(ListNum, dir, edgeMargin);
        }
      }                   
      if(ddl3==""){ 
        mnu = document.getElementById('Lst'+ListNum);
        mnu.style.display="none";
        break;
      }         
    } 
  }
} 


// Slideshow Also on
  function go(url) {
  if (opener && !opener.closed) {
    opener.location.href = url;
    window.close();
  } else { 
    self.location.href = url;
  }
  }
  
  
 //fixes for gear subnav highlighting issues -SRL 
  if (location.href.indexOf('digital_camcorders') != -1 || location.href.indexOf('high_end_digicams') != -1 || location.href.indexOf('mp3players') != -1 || location.href.indexOf('cellphones') != -1 || location.href.indexOf('digicams') != -1 || location.href.indexOf('headphones') != -1 || location.href.indexOf('notebooks') != -1 || location.href.indexOf('personal_media') != -1 || location.href.indexOf('speakers') != -1)
  {document.write('<style>div#secnav a.secnav_sports, div#secnav a.secnav_sports:visited, div#secnav a.secnav_sports:active {width:90px;display:block;background-position: 0 -37px;/* hide from IE mac \*/background-position: 0 -38px;/* end hiding from IE5 mac */}</style>');}

  if (location.href.indexOf('flattvs') != -1 || location.href.indexOf('espresso_machines') != -1 || location.href.indexOf('gamesystems') != -1 || location.href.indexOf('homephones') != -1  || location.href.indexOf('avsystems') != -1)
  {document.write('<style>div#secnav a.secnav_home, div#secnav a.secnav_home:visited, div#secnav a.secnav_home:active {width:122px;display:block;background-position: 0 -37px;/* hide from IE mac \*/background-position: 0 -38px;/* end hiding from IE5 mac */}</style>');}

  if (location.href.indexOf('drivers') != -1 || location.href.indexOf('snowboards') != -1 || location.href.indexOf('skis') != -1 || location.href.indexOf('tennis_racquets') != -1)
  {document.write('<style>div#secnav a.secnav_sports, div#secnav a.secnav_sports:visited, div#secnav a.secnav_sports:active {width:90px;display:block;background-position: 0 -37px;/* hide from IE mac \*/background-position: 0 -38px;/* end hiding from IE5 mac */}</style>');}

    if (location.href.indexOf('blogs/details/') != -1)
  {document.write('<style>div#secnav a.details2, div#secnav a.details2:visited, div#secnav a.details2:active {display:block;width:185px;height:49px;position:absolute;top: -31px;left:502px;z-index:3;background: url(/images/hp_details2.gif) 0 0 no-repeat; }div#secnav a.details3, div#secnav a.details3:visited, div#secnav a.details3:active {display:block;width:69px;height:49px;position:absolute;top: -31px;left:618px;z-index:3;background: url(/images/hp_details2sub.gif) 0 0 no-repeat; }</style>');}



//Robert Eilam ***** Moved from Nav.jsp

function GetCookie (name) {  

    var arg = name + "=";  
    var alen = arg.length;  
    var clen = document.cookie.length;  
    var i = 0;  

    while (i < clen) {    
      var j = i + alen;    
      if (document.cookie.substring(i, j) == arg) {
        return getCookieVal (j);
      }

      i = document.cookie.indexOf(" ", i) + 1;    

      if (i == 0) {
        break;
      }
    }  

    return null;

  } 
       
  function getCookieVal(offset) {

    var endstr = document.cookie.indexOf (";", offset);

    if (endstr == -1) {
      endstr = document.cookie.length;
    }

    return unescape(document.cookie.substring(offset, endstr));

  }  
   
  function getWishlistCount(wishlistCookie) {

    var wishlistCount = 0;
    var index = 0;
    var value = wishlistCookie;

    if (wishlistCookie != null) {

      index =  wishlistCookie.indexOf('|');

      if(index == -1) {
        return 0;
      }
      else {
        while(index != -1 ) {
          wishlistCount = wishlistCount + 1;
          value = value.substring(index+1, value.length);
          index = value.indexOf('|');
        }
      }
    }
    else  {
       return 0;
    }

    return wishlistCount;
   }

                 
  //End Wishlist****             

  if(navigator.userAgent.toLowerCase().indexOf('7.0') != -1){document.write('<style>div.blog_desc{ margin: 10px 0 0 0; padding: 0; }</style>');}
 
   if(navigator.userAgent.toLowerCase().indexOf('safari') != -1){document.write('<style>div.blog_desc{ margin: 5px 0 0 0; padding: 0; }span.blog_title{display: block; padding: 0 0 5px 10px; font-size: 18px; font-weight: normal; width: 330px;}</style>');}
   
   
   
   //Upgrader Scrollers
   // This code is from the book JavaScript: The Definitive Guide, 5th Edition,
// by David Flanagan. Copyright 2006 O'Reilly Media, Inc. (ISBN #0596101996)
/*
 * Handler.js -- Portable event handler registration functions
 *
 * This module defines event handler registration and deregistration functions
 * Handler.add() and Handler.remove(). Both functions take three arguments:
 * 
 *   element: the DOM element, document, or window on which the handler
 *      is to be added or removed.
 * 
 *   eventType: a string that specifies the type of event for which the
 *      handler is to be invoked.  Use DOM-standard type names, which do
 *      not include an "on" prefix. Examples: "click", "load", "mouseover".
 *
 *   handler: The function to be invoked when an event of the specified type
 *      occurs on the specified element.  This function will be invoked as
 *      a method of the element on which it is registered, and the "this"
 *      keyword will refer to that element.  The handler function will be
 *      passed an event object as its sole argument.  This event object will
 *      either be a DOM-standard Event object or a simulated one. If a 
 *      simulated event object is passed, it will have the following DOM-
 *      compliant properties: type, target, currentTarget, relatedTarget,
 *      eventPhase, clientX, clientY, screenX, screenY, altKey, ctrlKey,
 *      shiftKey, charCode, stopPropagation(), and preventDefault()
 * 
 * Handler.add() and Handler.remove() have no return value.
 * 
 * Handler.add() ignores duplicate registrations of the same handler for
 * the same event type and element.  Handler.remove() does nothing if called
 * to remove a handler that has not been registered.
 *
 * Implementation notes:
 * 
 * In browsers that support the DOM standard addEventListener() and
 * removeEventListener() event registration functions, Handler.add() and
 * Handler.remove() simply invoke these functions, passing false as the 
 * third argument (meaning that the event handlers are never registered as
 * capturing event handlers).
 * 
 * In versions of Internet Explorer that support attachEvent(), Handler.add()
 * and Handler.remove() use attachEvent() and detachEvent(). To
 * invoke the handler function with the correct this keyword, a closure is
 * used.  Since closures of this sort cause memory leaks in Internet Explorer,
 * Handler.add() automatically registers an onunload handler to deregister
 * all event handlers when the page is unloaded. To keep track of
 * registered handlers, Handler.add() creates a property named _allHandlers on
 * the window object and creates a property named _handlers on any element on
 * which a handler is registered.
 */
var Handler = {};

// In DOM-compliant browsers, our functions are trivial wrappers around
// addEventListener() and removeEventListener().
if (document.addEventListener) {
    Handler.add = function(element, eventType, handler) {
        element.addEventListener(eventType, handler, false);
    };

    Handler.remove = function(element, eventType, handler) {
        element.removeEventListener(eventType, handler, false);
    };
}
// In IE 5 and later, we use attachEvent() and detachEvent(), with a number of
// hacks to make them compatible with addEventListener and removeEventListener.
else if (document.attachEvent) {
    Handler.add = function(element, eventType, handler) {
        // Don't allow duplicate handler registrations
        // _find() is a private utility function defined below.
        if (Handler._find(element, eventType, handler) != -1) return;
        
        // To invoke the handler function as a method of the
        // element, we've got to define this nested function and register
        // it instead of the handler function itself.
        var wrappedHandler = function(e) {
            if (!e) e = window.event;

            // Create a synthetic event object with partial compatibility
            // with DOM events.
            var event = {
                _event: e,    // In case we really want the IE event object
                type: e.type,           // Event type
                target: e.srcElement,   // Where the event happened
                currentTarget: element, // Where we're handling it
                relatedTarget: e.fromElement?e.fromElement:e.toElement,
                eventPhase: (e.srcElement==element)?2:3,

                // Mouse coordinates
                clientX: e.clientX, clientY: e.clientY,
                screenX: e.screenX, screenY: e.screenY,
                
                // Key state
                altKey: e.altKey, ctrlKey: e.ctrlKey,
                shiftKey: e.shiftKey, charCode: e.keyCode,

                // Event management functions
                stopPropagation: function() {this._event.cancelBubble = true;},
                preventDefault: function() {this._event.returnValue = false;}
            }

            // Invoke the handler function as a method of the element, passing
            // the synthetic event object as its single argument.
            // Use Function.call() if defined; otherwise do a hack
            if (Function.prototype.call) 
                handler.call(element, event);
            else {
                // If we don't have Function.call, fake it like this
                element._currentHandler = handler;
                element._currentHandler(event);
                element._currentHandler = null;
            }
        };

        // Now register that nested function as our event handler.
        element.attachEvent("on" + eventType, wrappedHandler);
        
        // Now we must do some record keeping to associate the user-supplied
        // handler function and the nested function that invokes it.

        // We have to do this so that we can deregister the handler with the
        // remove() method and also deregister it automatically on page unload.

        // Store all info about this handler into an object
        var h = {
            element: element,
            eventType: eventType,
            handler: handler,
            wrappedHandler: wrappedHandler
        };

        // Figure out what document this handler is part of.
        // If the element has no "document" property, it is not
        // a window or a document element, so it must be the document
        // object itself.
        var d = element.document || element;
        // Now get the window associated with that document
        var w = d.parentWindow;

        // We have to associate this handler with the window,
        // so we can remove it when the window is unloaded
        var id = Handler._uid();  // Generate a unique property name
        if (!w._allHandlers) w._allHandlers = {};  // Create object if needed
        w._allHandlers[id] = h; // Store the handler info in this object

        // And associate the id of the handler info with this element as well
        if (!element._handlers) element._handlers = [];
        element._handlers.push(id);

        // If there is not an onunload handler associated with the window,
        // register one now.
        if (!w._onunloadHandlerRegistered) {
            w._onunloadHandlerRegistered = true;
            w.attachEvent("onunload", Handler._removeAllHandlers);
        }
    };

    Handler.remove = function(element, eventType, handler) {
        // Find this handler in the element._handlers[] array.
        var i = Handler._find(element, eventType, handler);
        if (i == -1) return;  // If the handler was not registered, do nothing

        // Get the window of this element
        var d = element.document || element;
        var w = d.parentWindow;

        // Look up the unique id of this handler
        var handlerId = element._handlers[i];
        // And use that to look up the handler info
        var h = w._allHandlers[handlerId];
        // Using that info, we can detach the handler from the element
        element.detachEvent("on" + eventType, h.wrappedHandler);
        // Remove one element from the element._handlers array
        element._handlers.splice(i, 1);
        // And delete the handler info from the per-window _allHandlers object
        delete w._allHandlers[handlerId];
    };

    // A utility function to find a handler in the element._handlers array
    // Returns an array index or -1 if no matching handler is found
    Handler._find = function(element, eventType, handler) {
        var handlers = element._handlers;
        if (!handlers) return -1;  // if no handlers registered, nothing found

        // Get the window of this element
        var d = element.document || element;
        var w = d.parentWindow;

        // Loop through the handlers associated with this element, looking
        // for one with the right type and function.
        // We loop backward because the most recently registered handler
        // is most likely to be the first removed one.
        for(var i = handlers.length-1; i >= 0; i--) {
            var handlerId = handlers[i];        // get handler id
            var h = w._allHandlers[handlerId];  // get handler info
            // If handler info matches type and handler function, we found it.
            if (h.eventType == eventType && h.handler == handler) 
                return i;
        }
        return -1;  // No match found
    };

    Handler._removeAllHandlers = function() {
        // This function is registered as the onunload handler with 
        // attachEvent.  This means that the this keyword refers to the
        // window in which the event occurred.
        var w = this;

        // Iterate through all registered handlers
        for(id in w._allHandlers) {
            // Get handler info for this handler id
            var h = w._allHandlers[id]; 
            // Use the info to detach the handler
            h.element.detachEvent("on" + h.eventType, h.wrappedHandler);
            // Delete the handler info from the window
            delete w._allHandlers[id];
        }
    }

    // Private utility to generate unique handler ids
    Handler._counter = 0;
    Handler._uid = function() { return "h" + Handler._counter++; };
}





// This code is from the book JavaScript: The Definitive Guide, 5th Edition,
// by David Flanagan. Copyright 2006 O'Reilly Media, Inc. (ISBN #0596101996)
/*
 * runOnLoad.js: portable registration for onload event handlers.
 * 
 * This module defines a single runOnLoad() function for portably registering
 * functions that can be safely invoked only when the document is fully loaded
 * and the DOM is available.
 *
 * Functions registered with runOnLoad() will not be passed any arguments when
 * invoked. They will not be invoked as a method of any meaningful object, and
 * the this keyword should not be used.  Functions registered with runOnLoad()
 * will be invoked in the order in which they were registered.  There is no
 * way to deregister a function once it has been passed to runOnLoad().
 *
 * In old browsers that do not support addEventListener() or attachEvent(),
 * this function relies on the DOM Level 0 window.onload property and will not
 * work correctly when used in documents that set the onload attribute
 * of their body or frameset tags.
 */
function runOnLoad(f) {
    if (runOnLoad.loaded) f();    // If already loaded, just invoke f() now.
    else runOnLoad.funcs.push(f); // Otherwise, store it for later
}

runOnLoad.funcs = []; // The array of functions to call when the document loads
runOnLoad.loaded = false; // The functions have not been run yet.

// Run all registered functions in the order in which they were registered.
// It is safe to call runOnLoad.run() more than once: invocations after the
// first do nothing. It is safe for an initialization function to call
// runOnLoad() to register another function.
runOnLoad.run = function() {
    if (runOnLoad.loaded) return;  // If we've already run, do nothing
    for(var i = 0; i < runOnLoad.funcs.length; i++) {
        try { runOnLoad.funcs[i](); }
        catch(e) { /* An exception in one function shouldn't stop the rest */ }
    }
    
    runOnLoad.loaded = true; // Remember that we've already run once.
    delete runOnLoad.funcs;  // But don't remember the functions themselves.
    delete runOnLoad.run;    // And forget about this function too!
};

// Register runOnLoad.run() as the onload event handler for the window
if (window.addEventListener)
    window.addEventListener("load", runOnLoad.run, false);
else if (window.attachEvent) window.attachEvent("onload", runOnLoad.run);
else window.onload = runOnLoad.run;






function CNT_ScrollBar(scrollAreaId, scrollBarId, autoHide)
{
  /* self-referencing instance variable; needed for event handling and execution contexts
  where 'this' refers to something else */
  var myself = this;

  this.scrollActiveIntervalId = null;
  this.scrollInterval = 50;
  this.scrollStep = 50;
  this.autoHide = (autoHide == null) ? false : autoHide;
  this.isScrollBarHidden = false; 
  this.scrollJumpOffsetFactor = 0.5;
  
  this.doScrollUp_interval = function()
  {
    with (myself) {
      scrollArea.scrollTop = Math.max(scrollArea.scrollTop - scrollStep, 0);
      doAdjustScrollBar();
    }
  }

  
  
  this.doScrollDown_interval = function()
  {
    with (myself) {
      scrollArea.scrollTop = Math.min(scrollArea.scrollHeight - scrollArea.clientHeight, scrollArea.scrollTop + scrollStep);
      doAdjustScrollBar();
    }
  }

  
  
  this.handleDocumentEvent = function(e)
  {   
    e.preventDefault();
    e.stopPropagation();
    
    with (myself) {
      if (e.type == "mousemove") {
        event_document_mousemove(e);
      }
      else if (e.type == "mouseup") {
        event_document_mouseup(e);
      }
    }
  
  } 

  
  
  this.handleScrollAreaEvent = function(e)
  {   
    var className = e.target.className;
    if (!className)
      className = "";
    
    with (myself) {
      if (!myself.isScrollBarHidden && (e.type == "DOMMouseScroll" || e.type == "mousewheel")) {
        e.preventDefault();
        e.stopPropagation();
        event_scrollArea_wheel(e);
      }
    }
  }

  this.handleScrollBarEvent = function(e)
  {
    var className = e.target.className;
    if (!className)
      className || "";

    e.preventDefault();
    e.stopPropagation();

    with (myself) {
      /* need to handle thumb first before trough, because thumb is a descendant of trough */
      if (/\bcnt-scroll-thumb\b/.test(className) || isNodeOrDescendant(e.target, scrollThumb)) {
        if (e.type == "mousedown")
          event_thumb_mousedown(e);
      }
      else if (/\bcnt-scroll-trough\b/.test(className) || isNodeOrDescendant(e.target, scrollTrough)) {
        if (e.type == "mousedown")
          event_trough_mousedown(e);
      }
      else if (/\bcnt-scroll-button-up\b/.test(className) || isNodeOrDescendant(e.target, scrollButtonUp)) {
        if (e.type == "mousedown")
          event_buttonUp_mousedown(e);
      }
      else if (/\bcnt-scroll-button-down\b/.test(className) || isNodeOrDescendant(e.target, scrollButtonDown)) {
        if (e.type == "mousedown")
          event_buttonDown_mousedown(e);
      }
    }
  }

  this.scrollAreaId = scrollAreaId;
  this.scrollBarId = scrollBarId;
  this.scrollArea = document.getElementById(scrollAreaId);
  this.scrollArea.scrollBar = this;
  this.scrollBar = document.getElementById(scrollBarId);

  this.scrollButtonUp = getElementsByClass("scroll-button-up", this.scrollBar, "div")[0];
  this.scrollButtonDown = getElementsByClass("scroll-button-down", this.scrollBar, "div")[0];
  this.scrollTrough = getElementsByClass("scroll-trough", this.scrollBar, "div")[0];
  this.scrollThumb = getElementsByClass("scroll-thumb", this.scrollTrough, "div")[0];

  Handler.add(this.scrollBar, "mousedown", this.handleScrollBarEvent);

  Handler.add(this.scrollArea, "DOMMouseScroll", this.handleScrollAreaEvent);
  Handler.add(this.scrollBar, "DOMMouseScroll", this.handleScrollAreaEvent);
  Handler.add(this.scrollArea, "mousewheel", this.handleScrollAreaEvent);
  Handler.add(this.scrollBar, "mousewheel", this.handleScrollAreaEvent);
  this.scrollArea.onmousewheel = this.scrollBar.onmousewheel = function()
  {
    myself.event_scrollArea_wheel(window.event);
  }
    
  this.doAdjustScrollBar();
}

CNT_ScrollBar.prototype.doScrollUp = function()
{
  this.scrollActiveIntervalId = setInterval(this.doScrollUp_interval, this.scrollInterval);
}

CNT_ScrollBar.prototype.doScrollDown = function()
{
  this.scrollActiveIntervalId = setInterval(this.doScrollDown_interval, this.scrollInterval);
}

CNT_ScrollBar.prototype.doScrollJump = function(y)
{
  this.scrollArea.scrollTop = y;
  this.doAdjustScrollBar();
}

CNT_ScrollBar.prototype.doScrollJumpToId = function(id)
{
  var element = document.getElementById(id);
  if (element && element != this.scrollArea && isNodeOrDescendant(element, this.scrollArea))
    this.doScrollJump(getOffsetFrom(element, this.scrollArea) - this.scrollArea.clientHeight * this.scrollJumpOffsetFactor);
}

CNT_ScrollBar.prototype.doAdjustScrollBar = function()
{
  if (this.scrollArea.clientHeight == 0 && this.scrollArea.scrollHeight == 0)
  {
    
    
  }
  else if ((this.scrollArea.clientHeight >= this.scrollArea.scrollHeight) || this.scrollArea.clientHeight == 0) {
    this.scrollThumb.style.height = this.scrollTrough.clientHeight + "px";
    if (this.autoHide) {
      this.isScrollBarHidden = true;
      this.scrollBar.style.display = "none";
      if (isSafari) {  // workaround for Safari float layout flow bug
        this.scrollArea.style.width = "100%";
      }
    }
  }
  else {
    var thumbHeightFrac = this.scrollArea.clientHeight / this.scrollArea.scrollHeight;
  
    if (isNaN(thumbHeightFrac) || !isFinite(thumbHeightFrac))
      thumbHeight = 1.0;
      
    thumbHeightFrac = Math.max(0.1, thumbHeightFrac);
    
    
    if (thumbHeightFrac == 1.0 && this.autoHide) {
      this.isScrollBarHidden = true;
      this.scrollBar.style.display = "none";
      if (isSafari) { // workaround for Safari float layout flow bug
        this.scrollArea.style.width = "100%";
      }
    }
    else {
      this.isScrollBarHidden = false;
      this.scrollBar.style.display = "block";
      if (isSafari) { // workaround for Safari float layout flow bug
        this.scrollArea.style.width = "";
      }
    }
  
    var thumbHeightPx = Math.round(this.scrollTrough.clientHeight * thumbHeightFrac);
    if (this.thumbHeightPx != thumbHeightPx)
    {
      if( this.scrollArea.id == 'hotlist-style-scroll-area2' || this.scrollArea.id == 'features-style-scroll-area2' ||
          this.scrollArea.id == 'hotlist-gear-scroll-area2' || this.scrollArea.id == 'features-gear-scroll-area2' ||
          this.scrollArea.id == 'hotlist-living-scroll-area2' || this.scrollArea.id == 'features-living-scroll-area2')
      {
        this.scrollThumb.style.height = "19px";
      }
      else
        this.scrollThumb.style.height = (this.thumbHeightPx = thumbHeightPx) + "px";
    }
      
  }

  var scrollAreaPercent = this.scrollArea.scrollTop / (this.scrollArea.scrollHeight - this.scrollArea.clientHeight);

  var thumbTop = scrollAreaPercent * (this.scrollTrough.clientHeight - this.scrollThumb.clientHeight);

  /* if thumb is at the bottom, align it exactly with the bottom */
  thumbTop = Math.min(thumbTop, this.scrollTrough.clientHeight - this.scrollThumb.clientHeight);
  /* if thumb is at the top, align it exactly with the top */
  if (this.scrollArea.scrollTop == 0)
    thumbTop = 0;
  
  thumbTop = Math.round(thumbTop);

  if (this.thumbTop != thumbTop)
    this.scrollThumb.style.top = (this.thumbTop = thumbTop) + "px";

}

CNT_ScrollBar.prototype.stopScroll = function()
{
  clearInterval(this.scrollActiveIntervalId);
}

CNT_ScrollBar.prototype.event_trough_mousedown = function(e)
{
  var absoluteY = e.clientY + ((isIE && (isIE < 7)) ? document.body.scrollTop : document.documentElement.scrollTop);
  var relativeY = absoluteY - getTotalOffset(this.scrollTrough); // relative to trough
  var relativeThumbOffset = Math.round(Math.max(Math.min(relativeY - this.scrollThumb.clientHeight / 2.0, this.scrollTrough.clientHeight - this.scrollThumb.clientHeight), 0));
  var scrollAreaPercent = relativeThumbOffset / (this.scrollTrough.clientHeight - this.scrollThumb.clientHeight);
  var scrollAreaScrollTop = Math.round((this.scrollArea.scrollHeight - this.scrollArea.clientHeight) * scrollAreaPercent);
  this.scrollArea.scrollTop = scrollAreaScrollTop;
  this.scrollThumb.style.top = "" + relativeThumbOffset + "px";
  this.event_thumb_mousedown(e);
}

CNT_ScrollBar.prototype.event_scrollArea_wheel = function(e)
{
  if (e.detail) {
    if (e.detail < 0)
      this.doScrollUp_interval();
    else
      this.doScrollDown_interval();
  }
  else if (e.wheelDelta) {
    if (e.wheelDelta > 0)
      this.doScrollUp_interval();
    else
      this.doScrollDown_interval();
  }
}

CNT_ScrollBar.prototype.event_buttonDown_mousedown = function(e)
{
  Handler.add(document, "mouseup", this.handleDocumentEvent);
  this.doScrollDown();  
}

CNT_ScrollBar.prototype.event_buttonUp_mousedown = function(e)
{
  Handler.add(document, "mouseup", this.handleDocumentEvent);
  this.doScrollUp();
}



/**
 * This function handles the mouseup event when it is registered on the document
 * element.  In the CNT_ScrollBar object, this event is only triggered for 
 * the scroll up and down buttons, or when the thumb is released from being
 * dragged.  The code is the same for all three cases, so no checking is 
 * necessary to see which case occurred.
 */
CNT_ScrollBar.prototype.event_document_mouseup = function(e)
{
  /*
  The mousemove event is registered only for the duration of a thumb drag;
  if the thumb has been released, the event handler should be removed.
  if the thumb is not being dragged, removing the (non-existant) event is
  harmless.
  */
  Handler.remove(document, "mousemove", this.handleDocumentEvent);

  /*
  The mouseup event is registered only when a corresponding mousedown event
  is triggered over the scroll buttons or the thumb.  When the mouse button
  is released, the event is no longer needed and should be removed.
  */
  Handler.remove(document, "mouseup", this.handleDocumentEvent);

  /* in case the scroll buttons were pressed, so that the scrollarea was
  being scrolled at scrollInterval intervals, stop the scrolling */
  this.stopScroll();
}



CNT_ScrollBar.prototype.event_thumb_mousedown = function(e)
{
  Handler.add(document, "mousemove", this.handleDocumentEvent);
  Handler.add(document, "mouseup", this.handleDocumentEvent);
  this.scrollThumb.dragThumbOffsetY = e.clientY - getTotalOffset(this.scrollThumb) + document.documentElement.scrollTop;
}



/**
 * This function handles the mousemove event when it is registered on the document
 * element.  In the CNT_ScrollBar object, this only happens when the thumb is being
 * dragged, so this code assumes that is the case.
 */
CNT_ScrollBar.prototype.event_document_mousemove = function(e)
{
  var absoluteY = e.clientY + document.documentElement.scrollTop;
  var relativeY = absoluteY - getTotalOffset(this.scrollTrough); // relative to trough
  var relativeThumbOffset = Math.round(Math.max(Math.min(relativeY - this.scrollThumb.dragThumbOffsetY, this.scrollTrough.clientHeight - this.scrollThumb.clientHeight), 0));
  var scrollAreaPercent = relativeThumbOffset / (this.scrollTrough.clientHeight - this.scrollThumb.clientHeight);
  var scrollAreaScrollTop = Math.round((this.scrollArea.scrollHeight - this.scrollArea.clientHeight) * scrollAreaPercent);
  this.scrollArea.scrollTop = scrollAreaScrollTop;
  this.scrollThumb.style.top = "" + relativeThumbOffset + "px";
}


function getElementsByClass(searchClass, node, tag) {
  if (!(searchClass instanceof RegExp))
    searchClass = new RegExp("\\b" + searchClass + "\\b");
  var classElements = new Array();
  if (node == null)
    node = document;
  if (tag == null)
    tag = '*';
  var els = node.getElementsByTagName(tag);
  for (i = 0, j = 0; i < els.length; i++) {
    if (searchClass.test(els[i].className)) {
      classElements[j] = els[i];
      j++;
    }
  }
    return classElements;
} /* aliases: */ var getElementsByClassName = getElementsByClass;

var Navigator = {
  _getVersion: function (a, b) {
    var t = navigator.userAgent.split(a)[1];
    return (t) ? t.split(b)[0] : false;
  },
  isOpera: function () {
    return (
      (window.opera) ?
        (document.createElementNS) ?
          (document.createCDATASection) ?
            (document.styleSheets) ? 9 : 8
          : 7
        : 6
      : false
    );
  },
  isSafari: function () {
    return (document.createCDATASection && document.createElementNS) ? Navigator._getVersion('AppleWebKit/', '(') : false;
  },
  isKDE: function () {
    return (document.createCDATASection && document.createElementNS) ? Navigator._getVersion('Konqueror/', ';') : false;
  },
  isGecko: function () {
    return (document.createCDATASection && document.createElementNS) ? Navigator._getVersion('Gecko/', ' ') : false;
  },
  isNN4: function () {
    return (document.layers && typeof document.layers == 'object') ? true : false;
  },
  isWinIE: function () {
    return (
      /*@cc_on @if (@_win64 || @_win32 || @_win16)
      (document.getElementsByTagName) ?
        (@_jscript_version > 5.6) ? 7 :
        (@_jscript_version == 5.6) ? 6 :
        (@_jscript_version == 5.5) ? 5.5 :
        5
      : 4
      @else@*/false/*@end @*/
    );
  },
  isMacIE: function () {
    return (
      /*@cc_on @if (@_mac && (@_PowerPC || @_mc680x0))
        (document.getElementsByTagName) ? 5 : 4
      @else@*/false/*@end @*/
    );
  }
};

var isSafari = Navigator.isSafari();
var isIE = Navigator.isWinIE();

function getTotalOffset(element) {
  var total = 0;
  if (element.offsetParent)
    total += element.offsetTop + getTotalOffset(element.offsetParent);
  return total;
} /* aliases: */ var getOffset = getTotalOffset; var findPosY = getTotalOffset;



function isNodeOrDescendant(node, ancestor) {
  if (!node)
    return false;
  else if (node == ancestor)
    return true;
  else
    return isNodeOrDescendant(node.parentNode, ancestor);
} /* aliases: */ var isNodeOrDescendent = isNodeOrDescendant; var isDescendant = isNodeOrDescendant; var isDescendent = isNodeOrDescendant;



