	$(document).ready(function(){
	
		// remove link background images since we're re-doing the hover interaction below 
		// (doing it this way retains the CSS default hover states for non-javascript-enabled browsers)
		// we also want to only remove the image on non-selected nav items, so this is a bit more complicated
		$(".nav").children("li").each(function() {
			var current = "nav current-" + ($(this).attr("class"));
			var parentClass = $(".nav").attr("class");
			if (parentClass != current) {
				$(this).children("a").css({backgroundImage:"none"});
			}
		});	


		// create events for each nav item
		attachNavEvents(".nav", "home");
		attachNavEvents(".nav", "company");
		attachNavEvents(".nav", "services");
		attachNavEvents(".nav", "fleet");
		attachNavEvents(".nav", "specials");
		attachNavEvents(".nav", "quote");
		attachNavEvents(".nav", "news");
	

		function attachNavEvents(parent, myClass) {
			$(parent + " ." + myClass).mouseover(function() {
				$(this).append('<div class="nav-' + myClass + '"></div>');
				$("div.nav-" + myClass).css({display:"none"}).fadeIn(200);
			}).mouseout(function() {
				$("div.nav-" + myClass).fadeOut(200, function() {
					$(this).remove();
				});
			}).mousedown(function() {
				$("div.nav-" + myClass).attr("class", "nav-" + myClass + "-click");
			}).mouseup(function() {
				$("div.nav-" + myClass + "-click").attr("class", "nav-" + myClass);
			});
		}



	});



window.onload = pageInit;
//window.onload = Custom.init;
function pageInit() {
	rolloversInit();
	Custom.init();
}

function rolloversInit() {
	if (!document.getElementById) return;
	
	var arrPreload = new Array();
	var strSrcTmp;
	var arrImages = document.getElementsByTagName('img');
	
	for (var i=0; i<arrImages.length; i++) {
		if (arrImages[i].className == "rollover") {
			var src = arrImages[i].src;
			var imgtype = src.substring(src.lastIndexOf("."), src.length);
			var altsrc = src.replace(imgtype, "_over" + imgtype);

			arrImages[i].setAttribute('altsrc', altsrc);
			arrPreload[i] = new Image();
			arrPreload[i].src = altsrc;
			
			arrImages[i].onmouseover = function() {
				strSrcTmp = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('altsrc'));
			}

			arrImages[i].onmouseout = function() {
				if (!strSrcTmp) strSrcTmp = this.getAttribute('src').replace("_over" + imgtype, imgtype);
				this.setAttribute('src', strSrcTmp);
			}

		}
	}
}

