ddClasses = function() {
    function insertMouseOver(id) {
    var hoverClass = 'hovering';
    // get the LI top level descendents from the id element
    var els = document.getElementById(id).getElementsByTagName('ul')[0].childNodes;
    // loop through the li elements and add and remove classes upon mouse entry and exit
    for (var i=0; i<els.length; i++) {
        // only change the LI elements
        if (els[i].nodeName != 'LI') continue;
   	    var aelem = els[i].getElementsByTagName('a')[0];
            // add selected and dropdown for classes not initially selected
            if (!hasClass(aelem, hoverClass)) {
                // item is not orginally selected
                els[i].onmouseover=function() {
		    var aelem = this.getElementsByTagName('a')[0];
                    addClass(this, 'dropdown');
                    addClass(aelem, hoverClass);
                }
                els[i].onmouseout=function() {
		    var aelem = this.getElementsByTagName('a')[0];
                    removeClass(this, 'dropdown');
                    removeClass(aelem, hoverClass);
                }
            }
            else {
                // item was orginally selected, only add dropdown
                els[i].onmouseover=function() {
                    addClass(this, 'dropdown');
                }
                els[i].onmouseout=function() {
                    removeClass(this, 'dropdown');
                }
            }
        }
    }

    insertMouseOver("nav");
    insertMouseOver("subnav");
}

/** Preload images if they have been defined
*/
var product_images = [];
if (typeof product_image_names !== 'undefined') {
    for (var i = 0; i < product_image_names.length; i++) {
        product_images[i] = new Image();
        product_images[i].src = product_image_names[i]; 
    }
}
addEvent(window, 'load', ddClasses);


/*******************************************************
 *   Feature related functions
 ******************************************************/
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// function for home feature product swap
function dofeatswap (x, e, makeSelected) {
    if (makeSelected) {
        var ft = document.getElementById('featured-thumbnails');
        var as = ft.getElementsByTagName('a');
        for (i=0;i<as.length;i++) {
            if (as[i]==e) {
                if (!hasClass(as[i], 'selected')) {
                	addClass(as[i], 'selected');
                }
            }
            else {
                if (hasClass(as[i], 'selected')) {
                	removeClass(as[i], 'selected');
                }
            }

        }
    }
	var features = [];
	
	
	for (var i=0; true; i++) {

        var ele = document.getElementById('feature'+i);
        if (!ele) break;

        var feature = {};
        feature.element = ele;

        var img = document.getElementById('feat_prod'+i);
        feature.image = img;
	
        var pic = document.getElementById('feature_review_type'+i);
        feature.pic = pic;

        features.push(feature);
	}

	set_features_style(features,  parseInt(x.substring("feature".length)));
	
	return;
}

/**
 * Clears a fields value if it is equal to the default value
 */
function clearIt(field) {
    if (field.defaultValue == field.value) {
        field.value = "";
    }
}


/**
 * Sets the display styles for all the features in a section
 * if the index matches the feature, the display style is block
 * otherwise, the display style is set to none
 */
function set_features_style(features, index) {
  for (var i=0; i<features.length; i++) {
    var style = "none";
    if (index === i) style = "block";
    set_feature_style(features[i], style);
  }
}

/**
 * Sets the style for a feature
 * This includes the element and the pic
 */
function set_feature_style(feature, style) {
  set_style(feature.element, style);
  set_style(feature.pic, style);
}

/**
 * Basic function to set the display style of an element
*/
function set_style(ele, val){
  if (ele) ele.style.display = val;
  return
}

/******************************************************
 *   Generic functions
 ******************************************************/

/**
 * Generic function to add an event to an object
 */
function addEvent( obj, type, fn ) {
    if (obj.addEventListener) {
        obj.addEventListener( type, fn, false );
    }
    else if (obj.attachEvent) {
        obj.attachEvent( "on"+type, fn);
    }
    else {
        obj["on"+type] = obj["e"+type+fn];
    }
}

/**
 * Tests if an element has a class set
 */
function hasClass(ele,cls) {
    return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

/**
 * Adds a class to an element
 */
function addClass(ele,cls) {
    if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

/**
 * Removes a class from an element
 */
function removeClass(ele,cls) {
    if (hasClass(ele,cls)) {
        var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
        ele.className=ele.className.replace(reg,' ');
    }
}
