
// Navigation

Menu = {timer : null, current : null};
Menu.show = function(name){
	if(this.timer) clearTimeout(this.timer);
	$("subnav").style.display = "block";

	// turn on current subnav
	this.subnavElement = $("subnav_" + name);
	if (this.subnavElement){
			this.subnavElement.style.display = "block";
	}
	// turn on current nav
	this.parentNavElement = $("nav_link_" + name);
	$(this.parentNavElement).style.backgroundImage = 'url("/images/template/nav/' + name + '_on.gif")';
	
	// remember which is on
	this.current = name;

}
Menu.hide = function(){
	this.timer = setTimeout("Menu.doHide()",300);
}
Menu.doHide = function(){
	if(this.current){
		// turn off current subnav
		this.subnavElement = $("subnav_" + this.current);
		if (this.subnavElement){
			this.subnavElement.style.display = "none";
		}
		$("subnav_parts").style.display = "none";
		$("subnav_models").style.display = "none";
		$("subnav_advantages").style.display = "none";
		$("subnav_about").style.display = "none";
		$("subnav_contact").style.display = "none";
		$("subnav").style.display = "none";
		// turn off current nav
		this.parentNavElement = $("nav_link_" + this.current);
		$(this.parentNavElement).style.background = 'transparent'; // fall back to displaying the "preload_X" div which is positioned directly underneath this one. This is done to avoid flicker as IE blindly reloads css background images each time on rollover no matter what.
		
		// remember none are on
		this.current = null;
	}
}

// preload navigation images

models_off = new Image();
models_off.src = "/images/template/nav/models_off.gif";
models_on = new Image();
models_on.src = "/images/template/nav/models_over.gif";

advantages_off = new Image();
advantages_off.src = "/images/template/nav/advantages_off.gif";
advantages_on = new Image();
advantages_on.src = "/images/template/nav/advantages_over.gif";

about_off = new Image();
about_off.src = "/images/template/nav/about_off.gif";
about_on = new Image();
about_on.src = "/images/template/nav/about_over.gif";

contact_off = new Image();
contact_off.src = "/images/template/nav/contact_off.gif";
contact_on = new Image();
contact_on.src = "/images/template/nav/contact_over.gif";

parts_off = new Image();
parts_off.src = "/images/template/nav/parts_off.gif";
parts_on = new Image();
parts_on.src = "/images/template/nav/parts_over.gif";



function subnav_on(which_id){
	$(which_id).style.backgroundImage = 'url("/images/template/nav/subnav_on.gif")';
}

function subnav_off(which_id){
	$(which_id).style.backgroundImage = 'url("/images/template/nav/subnav_off.gif")';
}


// Utility Functions

// form field default value replacement
function clearDefaultValue(formField){
	if ($(formField).defaultValue==$(formField).value){
		$(formField).value = ""
	}
} 
function restoreDefaultValue(formField){
	if ($(formField).value==""){
		$(formField).value = $(formField).defaultValue;
	}
} 
/// select menu navigation
function selectMenuNavigation(selectId){
	newUrl = $(selectId).options[$(selectId).selectedIndex].value;
	if (newUrl != "#"){
		window.location.href = newUrl;
	}
}

// from prototype
Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
}

Object.extend(String.prototype, {
  stripTags: function() {
    return this.replace(/<\/?[^>]+>/gi, '');
  },

  camelize: function() {
    var oStringList = this.split('-');
    if (oStringList.length == 1) return oStringList[0];

    var camelizedString = this.indexOf('-') == 0
      ? oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1)
      : oStringList[0];

    for (var i = 1, len = oStringList.length; i < len; i++) {
      var s = oStringList[i];
      camelizedString += s.charAt(0).toUpperCase() + s.substring(1);
    }

    return camelizedString;
  },

  inspect: function() {
    return "'" + this.replace('\\', '\\\\').replace("'", '\\\'') + "'";
  }
});

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

// javascript image rollovers

function imgOn(imgName){
	if(document.images){
			document[imgName].src = eval(imgName + "_on.src");
	}
}
function imgOff(imgName){
	if(document.images){
			document[imgName].src = eval(imgName + "_off.src");
	}
}
