String.prototype.trim = function () {
  return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};

function findPosition(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function getWindowHeight(){
	var myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
		myHeight = window.innerHeight;
	}else if( document.documentElement && document.documentElement.clientHeight ) {
	//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	}else if( document.body && document.body.clientHeight ) {
	//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	  
	var scrollOffset = 0;
	if(typeof( window.pageYOffset ) == 'number' ) {
	//Netscape compliant
		scrollOffset = window.pageYOffset;
	}else if( document.body && document.body.scrollTop ) {
	//DOM compliant
		scrollOffset = document.body.scrollTop;
	}else if( document.documentElement && document.documentElement.scrollTop ) {
	//IE6 standards compliant mode
		scrollOffset = document.documentElement.scrollTop;
	}
	return [myHeight + scrollOffset, scrollOffset];
}

function removeBigImg(thisAnchor){
	var thisNode = "";
	for(var n=document.body.childNodes.length - 1;n>=0;n--){
		thisNode = document.body.childNodes[n];
		if(thisNode.className == 'bigImage_popup' || thisNode.className == 'bigImage_shim'){
			document.body.removeChild(thisNode);
		}
	}
}

function createBigImg(thisAnchor){
	var path = thisAnchor.href;
	var thumbImage = thisAnchor.getElementsByTagName("img")[0];
	var thisImage = new Image();
	
	thisAnchor.onclick = function(){return false;}; 
	thisImage.className = "bigImage_popup";
	thisImage.thumbNail = thumbImage;
	thisImage.style.margin = '0px 0px 0px 0px';
	thisImage.style.padding = '0px 0px 0px 0px';
	thisImage.style.position = 'absolute';
	thisImage.style.zIndex = "501";
	thisImage.style.border = '1px solid #000000';
	thisImage.style.display = 'none';
	thisImage.onload = function(){showBigImg(this)};
	thisImage.src=thisAnchor.href;
	document.body.appendChild(thisImage);
}

function showBigImg(thisImage){
	var pageSize = getWindowHeight();
	var pageHeight = pageSize[0];
	var pageOffset = pageSize[1];
	var thumbImage = thisImage.thumbNail;
	var thumbTop = findPosition(thumbImage)[1];
	//var pixelsFromLeft = (findPosition(thumbImage)[0] - 20 - thisImage.width);
	//var pixelsFromLeft = findPosition(thumbImage)[0] + 20 + thumbImage.width;
	var pixelsFromLeft = '460';
	var pixelsFromtop = thumbTop;
	thisImage.style.left = pixelsFromLeft + "px";

	if((pageHeight - thumbTop) < thisImage.height){
		//theres not enough room under the thumbnail - put it on top
		pixelsFromtop = (thumbTop + thumbImage.height - thisImage.height);
		if((pageOffset + 15) > pixelsFromtop){
			//there is not enough room on top so move it down 15 px from the top
			pixelsFromtop = (pageOffset + 15);
		}
	}
	thisImage.style.top = pixelsFromtop + "px";
	
	//this adds an Iframe shim under the image so it goes over dropdown menus 
	if (document.all){
		var iframeShim = document.createElement("IFRAME");
		thumbImage.parentNode.focus();
		iframeShim.className = "bigImage_shim";
		iframeShim.style.position = 'absolute';
		iframeShim.style.left = pixelsFromLeft + "px";
		iframeShim.style.height = thisImage.height;
		iframeShim.style.width = thisImage.width;
		iframeShim.style.zIndex = "500";
		iframeShim.style.top = pixelsFromtop + "px";
		document.body.appendChild(iframeShim);
	}
	thisImage.style.display = '';
}


function showFlash(){
	if (document.getElementById){
		if (hasFlash8){
			var baseFlashTag = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' align='middle' ";
			if($("racewear_flash")) {
				// determine the category (from the url) and pass it in the flashvars
				var category = "";
				if (document.location.href.indexOf("category=") != -1){
					category = document.location.href.substring(document.location.href.indexOf("category=") + 9, document.location.href.length);
					if (category.indexOf("#") != -1){
						category = category.substring(0, category.indexOf("#"));
					}
				}
				// add the object/embed tags to the HTML
				var flashTags = baseFlashTag;
				flashTags += "width='710' height='600' id='featureFlash'>";
				flashTags += "<param name='allowScriptAccess' value='sameDomain' />";
				flashTags += "<param name='movie' value='flash/racewear.swf' /><param name='flashvars' value='category=" + category + "' /><param name='base' value='.' /><param name='quality' value='high' /><param name='bgcolor' value='#000000' /><embed src='flash/racewear.swf' flashvars='category=" + category + "' base='.' quality='high' bgcolor='#000000' width='710' height='600' name='featureFlash' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
				flashTags += "</object>";
				$('racewear_flash').innerHTML = flashTags;
			}
			
			if($("feature")) {
				// add the object/embed tags to the HTML
				var flashTags = baseFlashTag;
				flashTags += "width='710' height='319' id='featureFlash'>";
				flashTags += "<param name='allowScriptAccess' value='sameDomain' />";
				flashTags += "<param name='movie' value='flash/feature_navigation.swf' /><param name='flashvars' value='imagePath=' /><param name='base' value='.' /><param name='quality' value='high' /><param name='bgcolor' value='#000' /><embed src='flash/feature_navigation.swf' flashvars='imagePath=' base='.' quality='high' bgcolor='#000' width='710' height='319' name='featureFlash' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
				flashTags += "</object>";
				$('feature').innerHTML = flashTags;
			}
			
			if($("holiday")) {
				// add the object/embed tags to the HTML
				var flashTags = baseFlashTag;
				flashTags += "width='710' height='362' id='featureFlash'>";
				flashTags += "<param name='allowScriptAccess' value='sameDomain' />";
				flashTags += "<param name='movie' value='flash/holiday/main.swf' /><param name='flashvars' value='imagePath=' /><param name='base' value='.' /><param name='quality' value='high' /><param name='bgcolor' value='#000' /><embed src='flash/holiday/main.swf' flashvars='imagePath=' base='.' quality='high' bgcolor='#000' width='710' height='362' name='featureFlash' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
				flashTags += "</object>";
				$('holiday').innerHTML = flashTags;
			}			

			if($("flashContent")) {
				// add the object/embed tags to the HTML
				var flashTags = baseFlashTag;
				flashTags += "width='332' height='246' id='splashFlash'>";
				flashTags += "<param name='allowScriptAccess' value='sameDomain' />";
				flashTags += "<param name='videoPath' value='06commercial.flv' />";
				flashTags += "<param name='movie' value='flash/videoplayer.swf' /><param name='base' value='.' /><param name='quality' value='high' /><param name='bgcolor' value='#000000' /><embed src='flash/videoplayer.swf' base='.' quality='high' bgcolor='#000000' width='332' height='246' name='splashFlash' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
				flashTags += "</object>";
				$('flashContent').innerHTML = flashTags;
			}
		}
	}
}

function enablePartNumberGrid(){
	var gridButton = $("partGridButton");
	if (gridButton){
		// get the height of the table before we hide is so that later on we know how tall to make the div
		// this isn't super-exact because this table height will be taller than later because it's not as
		// wide and therefore wraps more, but it's close enough.
		var tableHeight = Element.getHeight("partNumbersTable");
		var tableWidth = Element.getDimensions("partNumbersTable").width;
		// hide the grid
		Element.hide("partTableContainer");
		// enable the button by replacing the old text with a new button
		var buttonLabel = gridButton.innerHTML;
		var newButton = document.createElement("a");
		var newButtonLabel = document.createTextNode(gridButton.firstChild.nodeValue);
		newButton.appendChild(newButtonLabel);
		newButton.setAttribute("href", "#");
		newButton.onclick = function(){
			//alert(tableHeight);
			new Effect.toggle("partTableContainer", "blind", {duration: .7});
			return false;
		}
		gridButton.replaceChild(newButton, gridButton.firstChild);
		// set some styles on the partTableContainer to make it display pretty
		//var container = $("partTableContainer");
		Element.setStyle("partTableContainer", {
												"position": "relative",
												"width": (tableWidth > 450 ? "750px" : "450px"),
												"height": (tableHeight > 400 ? "400px" : tableHeight + "px"),
												"background-color": "#FFF",
												"margin": "0px 0px 10px " + (tableWidth > 450 ? "-270px" : "0px")
												});
		Element.setStyle("partNumbersTable", {	});
	}
}

function enableHiporaDetails(){
	var hiporaButton = $("hiporaButton");
	if (hiporaButton){
		// hide the grid
		Element.hide("hiporaDetails");
		// enable the button by replacing the old text with a new button
		var buttonLabel = hiporaButton.innerHTML;
		var newButton = document.createElement("a");
		var newButtonImage = document.createElement("img");
		newButtonImage.src = hiporaButton.firstChild.src;
		newButton.appendChild(newButtonImage);
		newButton.setAttribute("href", "#");
		newButton.onclick = function(){
		    if ($("washingInstructions") && $("washingInstructions").style.display != 'none'){
		      new Effect.toggle("washingInstructions", "blind", {duration: .3});
		    }
		    if ($("sizingChart") && $("sizingChart").style.display != 'none'){
		      new Effect.toggle("sizingChart", "blind", {duration: .3});
		    }
			new Effect.toggle("hiporaDetails", "blind", {duration: .7});
			return false;
		}
		hiporaButton.replaceChild(newButton, hiporaButton.firstChild);
	}
}

function enableWashingInstructions(){
	var washingButton = $("washingButton");
	if (washingButton){
		// hide the grid
		Element.hide("washingInstructions");
		// enable the button by replacing the old text with a new button
		var buttonLabel = washingButton.innerHTML;
		var newButton = document.createElement("a");
		var newButtonImage = document.createElement("img");
		newButtonImage.src = washingButton.firstChild.src;
		newButton.appendChild(newButtonImage);
		newButton.setAttribute("href", "#");
		newButton.onclick = function(){
		    if ($("hiporaDetails") && $("hiporaDetails").style.display != 'none'){
		      new Effect.toggle("hiporaDetails", "blind", {duration: .3});
		    }
		    if ($("sizingChart") && $("sizingChart").style.display != 'none'){
		      new Effect.toggle("sizingChart", "blind", {duration: .3});
		    }
			new Effect.toggle("washingInstructions", "blind", {duration: .7});
			return false;
		}
		washingButton.replaceChild(newButton, washingButton.firstChild);
	}
}

function enableSizingChart(){
	var sizingButton = $("sizingButton");
	if (sizingButton){
		// hide the grid
		Element.hide("sizingChart");
		// enable the button by replacing the old text with a new button
		var buttonLabel = sizingButton.innerHTML;
		var newButton = document.createElement("a");
		var newButtonImage = document.createElement("img");
		newButtonImage.src = sizingButton.firstChild.src;
		newButton.appendChild(newButtonImage);
		newButton.setAttribute("href", "#");
		newButton.onclick = function(){
		    if ($("hiporaDetails") && $("hiporaDetails").style.display != 'none'){
		      new Effect.toggle("hiporaDetails", "blind", {duration: .3});
		    }
		    if ($("washingInstructions") && $("washingInstructions").style.display != 'none'){
		      new Effect.toggle("washingInstructions", "blind", {duration: .3});
		    }
			new Effect.toggle("sizingChart", "blind", {duration: .7});
			return false;
		}
		sizingButton.replaceChild(newButton, sizingButton.firstChild);
	}
}

function setCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/**
 * EquipmentGuide class
 *
 * This class encapsulates the functionality of the equipment guide and controls
 * the opening and closing of the drawer
 * 
 */
var EquipmentGuide = Class.create();
EquipmentGuide.prototype = Object.extend(new Observer(), {
	
	CLOSED: 0,
	OPEN: 1,
	ANIMATING: 3,
	
	initialize: function(model) {
		this.drawer = $("menuDrawer");
		this.knob = $("menuDrawerKnob").getElementsByTagName("a")[0];
		// Check for saved state of drawer, default state(s)
		if (getCookie('drawerState') == '0') { 
			this.state = this.CLOSED;
			Element.hide(this.drawer);
		} else if (getCookie('drawerState') == '1') {
			this.state = this.OPEN;
		} else {
	  		this.state = this.CLOSED;
	  		Element.hide(this.drawer);
	    }
		// Toggle icon
		this.updateKnobIcon();
		document.getElementById('loadingHide').style.display='block';
	  	// Set drawer knob action
	  	if (this.drawer){
			this.knob.onclick = function(){
				// Toggle drawer THEN toggle icon
				this.toggleState();
				// Prevent hash in URL
				return false;
			}.bind(this);
		}
	},
	
	toggleState: function() {
		switch (this.state){
			case this.ANIMATING:
				return;
				break;
			case this.CLOSED:
				// Pass this.OPEN state as argument of updateKnobIcon()
				// Use string 'open' for readbility.
				this.updateKnobIcon('open');
				this.state = this.ANIMATING;
				setCookie('drawerState','1','30');	
				new Effect.SlideDown(this.drawer, {
												duration: 0.5, 
												afterFinish: function(){
													this.animationComplete(this.OPEN);
												}.bind(this)})
				break;
			case this.OPEN:
				// Pass this.CLOSED state as argument of updateKnobIcon()
				// Use string 'closed' for readbility.
				this.updateKnobIcon('closed');
				this.state = this.ANIMATING;
				setCookie('drawerState','0','30');
				new Effect.SlideUp(this.drawer, {
												duration: 0.5, 
												afterFinish: function(){
													this.animationComplete(this.CLOSED);
												}.bind(this)})
				break;
			default:
				alert("ERROR: unknown state in EquipmentGuide class");
				break;
		}
	},
	
	updateKnobIcon: function(s){
		// Read passed argument from toggleState() and re-establish scope of this.state.
		// Value of 's' will now be either 'open' or 'closed'.
		// Test against 's' and reset value of this.state for use w/n updateKnobIcon().
		if(s === 'open'){
			this.state = this.OPEN;
		} else if (s === 'closed') {
			this.state = this.CLOSED;
		}
		switch (this.state){
			case this.CLOSED:
				this.knob.style.backgroundPosition = "top";
				break;
			case this.OPEN:
				this.knob.style.backgroundPosition = "bottom";
				break;
		}
	},
	
	animationComplete: function(newState){
		this.state = newState;
	}
});

function numbersOnly(myfield, e, dec){
	var key;
	var keychar;
	if (window.event) {
		key = window.event.keyCode;
	} else if (e) {
		key = e.which;
	} else {
		return true;
	}
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) {
		return true;
	} else if ((("0123456789").indexOf(keychar) > -1)) {
		return true;
	} else if (dec && (keychar == ".")) {
		myfield.form.elements[dec].focus();
		return false;
	} else {
		return false;
	}
}

function showError(message, errorDiv){
	errorDiv.className += " validationError";
	var siblings = errorDiv.parentNode.childNodes
	for(var n=siblings.length-1; n >= 0; n--){
		if(siblings[n].className == 'error_line'){
			siblings[n].appendChild(document.createTextNode(message));
			siblings[n].style.display = "block";
		}
	}
}

function resetError(errorDiv){
	errorDiv.className = errorDiv.className.replace("validationError", "");
	var siblings = errorDiv.parentNode.childNodes
	for(var n=siblings.length-1; n >= 0; n--){
		if(siblings[n].className == 'error_line'){
			while(siblings[n].hasChildNodes()){
				siblings[n].removeChild(siblings[n].firstChild);
			}
			siblings[n].style.display = "none";
		}
	}
	return true;
}

function validateZip(inputId, message){
	var inputDiv = $(inputId);
	var inputValue = inputDiv.value.trim();
	resetError(inputDiv);
	inputDiv.errorMessage = message;
	inputDiv.onchange = function(){validateZip(this.id,this.errorMessage)};
	if(isNaN(inputValue) || inputValue.length != 5){
		showError(message,inputDiv);
		return false;
	}
	return true
}

function validateEmail(inputId, message, max){
	var inputDiv = $(inputId);
	var inputValue = inputDiv.value.trim();
	var re = /[a-z_]*[a-z0-9._%-]?[a-z0-9]+@[a-z0-9][a-z0-9._-]+\.[a-z0-9]+/i;
	resetError(inputDiv);
	inputDiv.errorMessage = message; //This statement endded with a double semi-colon, so it was removed
	inputDiv.onchange = function(){validateEmail(this.id,this.errorMessage)};
	if (inputValue.search(re) == -1){
		showError(message,inputDiv);
		return false;
	}
	if(inputValue.length > max){
		showError(message,inputDiv);
		return false;
	}
	return true;
}

function validateLength(inputId, message, min, max){
	var inputDiv = $(inputId);
	//alert(inputId + " = " + $(inputId));
	var inputValue = inputDiv.value.trim();
	resetError(inputDiv);
	inputDiv.errorMessage = message;
	inputDiv.min = min;
	inputDiv.max = max;
	inputDiv.onchange = function(){validateLength(this.id,this.errorMessage,this.min, this.max)};
	if(inputValue.length < min){
		showError(message,inputDiv);
		return false;
	}
	if(inputValue.length > max){
		showError(message,inputDiv);
		return false;
	}
	return true;
}

function validateCatalogForm(){
	var errorMessage = "";
	var message = "Please enter a valid first name.";
	if(!validateLength('catalogFirstName',message,1,50)){errorMessage += message + "\n";}
	message = "Please enter a valid last name.";
	if(!validateLength('catalogLastName',message,1,50)){errorMessage += message + "\n";}
	message = "Please enter a valid address.";
	if(!validateLength('catalogAddress1',message,1,150)){errorMessage += message + "\n";}
	message = "Please enter a valid city.";
	if(!validateLength('catalogCity',message,1,50)){errorMessage += message + "\n";}
	message = "Please select a valid state.";
	if(!validateLength('catalogState',message,2,2)){errorMessage += message + "\n";}
	message = "Please enter a valid zip.";
	if(!validateZip('catalogZip',message)){errorMessage += message + "\n";}
	message = "Please enter a valid email address.";
	if(!validateEmail('catalogEmail',message,50)){errorMessage += message + "\n";}
	
	if(errorMessage.length > 0){
		alert(errorMessage);
		return false;
	}else{
		return true;
	}
}

function validateContactForm(){
	var errorMessage = "";
	var message = "Please enter valid name.";
	if(!validateLength('contactName',message,1,50)){errorMessage += message + "\n";}
	message = "Please enter a valid email address.";
	if(!validateEmail('contactEmail',message,50)){errorMessage += message + "\n";}
	message = "Please enter a message.";
	if(!validateLength('contactMessage',message,1,500)){errorMessage += message + "\n";}

	if(errorMessage.length > 0){
		alert(errorMessage);
		return false;
	}else{
		return true;
	}
}

function validateNewsletterForm(e){
	Event.stop(e);
	var errorMessage = "";
	var message = "Please enter a valid email address.";
	if(!validateEmail('contactEmail',message,50)){errorMessage += message + "\n";}
	
	if(errorMessage.length > 0){
		alert(errorMessage);
		return false;
	}else{
		
		var inputs = document.getElementsByTagName("input");
		var boxes = new Array();
		var count = 0;
		var submitSuccess = true;
		
		for(var i in inputs) {
			if(inputs[i].className == 'newsletter_type' && inputs[i].checked == true) {
				boxes[count] = inputs[i].id;
				count++;
			}
		}
		
		var contactTextField = $('contactEmail').value;
		var spinner = $('newsletter_loading');
		var updateMsg = $('newsletter_message');

		for(b=0;b<boxes.length;b++) {
			var brandSiteId = document.getElementById(boxes[b]).value;

			var fromNameList = {
			    "12" : "MUD NRA E-News",
			    "33" : "MUD E-News",
			    "Default" : "Moose Racing E-News"
			}

			var from = fromNameList[brandSiteId] || fromNameList["Default"];
			var subject = "New " + from + " Subscriber";
			
			new Ajax.Request('newsletter_response.jsp',{
				method:'post',
				//parameter 'email' sends value of 'contactTextField' as ajax request to newsletter_respose.jsp
				parameters: {
					bsId: brandSiteId,
					fromName: from,
					email: contactTextField,
					sub: subject
				},
				evalJS: false,
				evalJSON: false,
				onCreate: function(){
					spinner.style.visibility = 'visible';
					updateMsg.style.visibility = 'hidden';
				},
				onSuccess: function(transport){
				},
				//server/network issue
				onFailure: function(transport){
					//Enable below code to send Ajax message into alert();
						//onFailure: function(transport){
							//var mySuccessResponse = transport.responseText || "no response text";
					      	//alert("Success! \n\n" + mySuccessResponse);
					submitSuccess = false;
				}
			});
		}
		
		if(submitSuccess) {
			spinner.style.visibility = 'hidden';
			updateMsg.className = 'success';
			updateMsg.innerHTML = 'Thanks for signing up!';
			updateMsg.style.visibility = 'visible';
		} else {
			spinner.style.visibility = 'hidden';
			updateMsg.className = 'validationError';
			updateMsg.innerHTML = 'Error, please try again.';
			updateMsg.style.visibility = 'visible';
		}
	
		$('contactEmail').value = '';
		$('mud').checked = false;
		$('mudnra').checked = false;
		return false;
	}
}

function validateLocatorForm(){
	var errorMessage = "";
	var message = "Please enter a valid zip code.";
	if(!validateZip('zipCode',message)){errorMessage += message + "\n";}

	if(errorMessage.length > 0){
		alert(errorMessage);
		return false;
	}else{
		return true;
	}
}

handleSafetyWarning = function(e) {
	Event.stop(e);
	var xoffset = 0;
	var yoffset = 0;
	var tempX = 0;
	var tempY = 0;
	handleSafetyGrab = function(e) {
		Event.stop(e);
		xoffset = Event.pointerX(e);
		yoffset = Event.pointerY(e);
		Event.observe(document, 'mousemove', handleSafetyDrag);
		Event.observe(document, 'mouseup', handleSafetyStop);
	}
	handleSafetyDrag = function(e) {
		Event.stop(e);
		tempX = Event.pointerX(e);
		tempY = Event.pointerY(e);
		div = $('warning_block');
		div.style.top = div.style.top.gsub('px', '') - (yoffset - tempY) + 'px';
		div.style.left = div.style.left.gsub('px', '') - (xoffset - tempX) + 'px';
		xoffset = tempX;
		yoffset = tempY;
	}
	handleSafetyStop = function(e) {
		Event.stopObserving(document, 'mousemove', handleSafetyDrag);
		Event.stopObserving(document, 'mouseup', handleSafetyStop);
	}
	handleSafetyClose = function(e) {
		Event.stopObserving('safety_close', 'click', handleSafetyClose);
		div = $('warning_block');
		div.innerHTML = '';
		div.style.display = 'none';
	}
	options = {
		onSuccess: function(o) {
			div = $('warning_block');
			vp = document.viewport.getDimensions();
			div.style.position = 'absolute';
			div.style.zIndex = 100000;
			div.style.width = '500px';
			div.style.left = ((vp.width / 2) - 250) + 'px';
			div.style.top = '150px';
			div.style.cursor = 'pointer';
			div.style.display = 'block';
			div.innerHTML = o.responseText;
			Event.observe('warning_block', 'mousedown', this.handleSafetyGrab);
			Event.observe('safety_close', 'click', this.handleSafetyClose);
		}
	}
	new Ajax.Request('inc/warning.jsp', options);
}

function initialize(){
	hasFlash7 = DetectFlashVer(7,0,0); //MajorVersion, MinorVersion, Revision
	hasFlash8 = DetectFlashVer(8,0,0); //MajorVersion, MinorVersion, Revision
	showFlash();

	if($('requestCatalog')){
		$('requestCatalog').onsubmit = validateCatalogForm;
	}
	
	if($('contactForm')){
		$('contactForm').onsubmit = validateContactForm;
	}
	
	if($('newsletterForm')){
		Event.observe('newsletterForm','submit', validateNewsletterForm);
	}
	
	if($('home_updates')) {
		$('contactEmail').onfocus = function() {
			$('contactEmail').value = '';
		}
	}
	
	if($('locatorForm')){
		$('locatorForm').onsubmit = validateLocatorForm;
	}
	
	if($('home_wheretobuy')) {
		$('zipCode').onfocus = function() {
			$('zipCode').value = '';
		}
	}
	
	// create an instance of the class that handles the top drawer
	var equipmentGuide = new EquipmentGuide();
	
	// hide and show the part number grid
	enablePartNumberGrid();
	enableWashingInstructions();
	enableSizingChart();
	enableHiporaDetails();
	
	// if we're viewing a part in the catalog, enable the "show part numbers" button
	/*
	var showPartsButton = $("showPartsButton");
	if (showPartsButton){
		var partsTable = $("partTableContainer");
		showPartsButton.style.display = "block";
		partsTable.style.display = "none";
		var link = showPartsButton.getElementsByTagName("a")[0];
		link.onclick = function(){
			//Element.toggle(partsTable); //  partsTable.style.display = "block";
			Effect.toggle("partTableContainer", "blind", {duration: 0.5});
			return false;
		}
	}
	*/
	// enable the thumbnail links (if js is enabled, simply swap out the images as opposed to refreshing the entire page
	if ($("thumbnails")){
		var thumbnails = $("thumbnails").getElementsByTagName("li");
		for (var i=0; i<thumbnails.length; i++){
			thisLink = thumbnails[i].getElementsByTagName("a")[0];
			thisLink.onclick = function(){
				var bigImage = $("bigImage").getElementsByTagName("img")[0];
				bigImage.src = bigImage.src.substr(0, bigImage.src.indexOf('rank=')) + "rank=" + this.id;
				//bigImage.src = "<core:getINIValue iniFile="brandSite.ini" name="Global_catalogImage_URL"/>?class_id=<core:parameter name="product_group_id"/>&image_type=fullsize&rank=" + this.id;
				return false;
			}
		}
	}
	
	// This fixes the IE6 flicker problem for background images!  Whoo hoo!
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(e) {}
	
	if($('dealerList')){
		var anchors = $('dealerList').getElementsByTagName('a');
		for(var i = 0; i<anchors.length; i++ ){
			if(anchors[i].className == 'dealerImg'){
				anchors[i].onmouseover = function(){createBigImg(this)};
				anchors[i].onmouseout = function(){removeBigImg(this)};
			}
		}
	}
	
	if($('safetywarning')) {
		Event.observe('safetywarning', 'click', handleSafetyWarning);
	}
}

// Observe the onload event rather than attaching a function to it
// this is much more flexible 
Event.observe(window, "load", initialize, false);