
// Navigation

Menu = {timer : null, current : null};
Menu.show = function(name){
	if(this.timer) clearTimeout(this.timer);
	$("#subnav").show();

	// turn on current subnav
	this.subnavElement = $("#subnav_" + name);
	if (this.subnavElement){
			this.subnavElement.show();
	}
	// turn on current nav
	//this.parentNavElement = $("nav_link_" + name);
	this.my_box = $("#nav_" + name);
	//$(this.parentNavElement).style.backgroundImage = 'url("/images/template/nav/' + name + '_on.gif")';
	$(this.my_box).addClass('nav_on');
	
	// 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.hide();
		}
		$("#subnav_parts").hide();
		$("#subnav_models").hide();
		$("#subnav_advantages").hide();
		$("#subnav_about").hide();
		$("#subnav_contact").hide();
		$("#subnav").hide();
		// 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.
	    this.my_box = $("#nav_" + this.current);
	//$(this.parentNavElement).style.backgroundImage = 'url("/images/template/nav/' + name + '_on.gif")';
	    $(this.my_box).removeClass('nav_on');
		// remember none are on
		this.current = null;
	}
}

// preload navigation images




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("'", '\\\'') + "'";
  }
});


// 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");
	}
}




$(document).ready(function() {
	$('a.request_quote').colorbox({ speed:500});
	$('a.colorbox').colorbox({ speed:500, slideshow:true, slideshowAuto:false});
	
	$("#model_nav_selector").change(function(){
	    my_new_thing = $("#model_nav_selector").first().val();
	    if (my_new_thing != ""){
	        document.location.href=my_new_thing;
        }
	});
	
});




