String.prototype.trim = function () {
  return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};

function getEl(id){
	return document.getElementById(id);
}

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';
	document.body.appendChild(thisImage);
	thisImage.onload = function(){showBigImg(this)};
	thisImage.src=thisAnchor.href;
}

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 = '460';
	var pixelsFromLeft = findPosition(thumbImage)[0] + 20 + thumbImage.width;
	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 enablePartNumberGrid(){
	var gridButton = getEl("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 = $("#partNumbersTable").height();
		var tableWidth = $("#partNumbersTable").width();
		// hide the grid
		$("#partTableContainer").hide();
		// 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(){
			$("#partTableContainer").slideToggle(350);
			return false;
		}
		gridButton.replaceChild(newButton, gridButton.firstChild);
		// set some styles on the partTableContainer to make it display pretty
		$("#partTableContainer").css({
								"position": "relative",
								"width": (tableWidth > 450 ? "750px" : "450px"),
								"height": (tableHeight > 400 ? "400px" : tableHeight + "px"),
								"background-color": "#FFF",
								"margin": "0px 0px 10px " + (tableWidth > 450 ? "-270px" : "0px")
							});
	}
}

function enableHiporaDetails(){
	var hiporaButton = getEl("hiporaButton");
	if (hiporaButton){
		// hide the grid
		//Element.hide("hiporaDetails");
		$("#hiporaDetails").hide();
		
		// 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(){
			$("#sizingChart").hide();
			$("#washingInstructions").hide();
			$("#hiporaDetails").slideToggle(350);
			return false;
		}
		hiporaButton.replaceChild(newButton, hiporaButton.firstChild);
	}
}

function enableWashingInstructions(){
	var washingButton = getEl("washingButton");
	if (washingButton){
		// hide the grid
		$("#washingInstructions").hide().addClass('closed');
		
		// 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(){
			$("#sizingChart").hide();
			$("#hiporaDetails").hide();
			$("#washingInstructions").slideToggle(350);
			return false;
		}
		washingButton.replaceChild(newButton, washingButton.firstChild);
	}
}

function enableSizingChart(){
	var sizingButton = getEl("sizingButton");
	if (sizingButton){
		// hide the grid
		$("#sizingChart").hide().addClass('closed');
		// 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(){
			$("#washingInstructions").hide();
			$("#hiporaDetails").hide();
			$("#sizingChart").slideToggle(350);
			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;
}

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 = getEl(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 = getEl(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 = getEl(inputId);
	//alert(inputId + " = " + getEl(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 write a message of no more than 500 characters.";
	if(!validateLength('contactMessage',message,1,500)){errorMessage += message + "\n";}

	if(errorMessage.length > 0){
		alert(errorMessage);
		return false;
	}else{
		return true;
	}
}


function validateNewsletterForm(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 = $('#newsletterForm input.newsletter_type');
		
		var errMsg = getEl('err_message');
		errMsg.style.display = 'none';
		
		if(inputs.length > 0){
			
			var updateMsg = getEl('newsletter_message');
			var contactTextField = getEl('contactEmail').value;
			var spinner = getEl('newsletter_loading');
			var myForm = getEl('newsletterForm');
			
			spinner.style.display = 'inline';
				
			var brandSiteIds = ""; 
			inputs.each(function(){if(this.checked){brandSiteIds += this.value + ',';}});

			jQuery.ajax({
				url:'newsletter_response.jsp',
				type:'post',
				//parameter 'email' sends value of 'contactTextField' as ajax request to newsletter_respose.jsp
				data: {
					bsId: brandSiteIds,
					email: contactTextField
					//fromName: from,
					//sub: subject
				},
				success:function(){
					myForm.style.display = 'none';
					updateMsg.innerHTML = 'Thanks for signing up!';
					updateMsg.style.display = 'block';
					spinner.style.visibility = 'hidden';
					getEl('contactEmail').value = '';
					getEl('moose').checked = false;
					getEl('mudnra').checked = false;
				},
				error:function(){
					errorMsg.innerHTML = 'Error, please try again.';
					errorMsg.style.display = 'block';
					spinner.style.visibility = 'hidden';
				}
			});
		
		}
		
		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;
	}
}

function validSearch() {
	if(getEl("catalogSearchText").value.length>1){ 
		return true;
	}else{
		alert('Search criteria must be at least 2 characters long.');
		getEl("catalogSearchText").focus();
		return false;
	}
}

function pdfDownload(pdf_url) {
	var confirmation = window.confirm("This PDF is about 60 MB in size, do you still wish to download it?")
	if (confirmation)
		window.open("http://assets-static.lemansnet.com/sites/mooseracing/pdf/2012_moose_racing_cat_lowres.pdf");
}


handleSafetyWarning = function(event){
	var xoffset = 0;
	var yoffset = 0;
	var tempX = 0;
	var tempY = 0;
	var div = getEl('warning_block');
	handleSafetyGrab = function(event){
		event.stopPropagation();
		xoffset = event.pageX;
		yoffset = event.pageY;
		$(document).bind('mousemove', handleSafetyDrag);
		$(document).bind('mouseup', handleSafetyStop);
	};
	handleSafetyDrag = function(event){	
		event.stopPropagation();
		tempX = event.pageX;
		tempY = event.pageY;
		div.style.top = div.style.top.replace('px','') - (yoffset - tempY) + 'px';
		div.style.left = div.style.left.replace('px', '') - (xoffset - tempX) + 'px';
		xoffset = tempX;
		yoffset = tempY;
	};
	handleSafetyStop = function(e){
		$(document).unbind('mousemove', handleSafetyDrag);
		$(document).unbind('mouseup', handleSafetyStop);
	};
	handleSafetyClose = function(e){
		$('#safety_close').unbind('click', handleSafetyDrag);
		div.innerHTML = '';
		div.style.display = 'none';
	};

	options = {
		url:'inc/warning.jsp',
		success: function(data){
			var pageWidth = $(document).width();
			div.style.position = 'absolute';
			div.style.zIndex = 100000;
			div.style.width = '500px';
			div.style.left = ((pageWidth / 2) - 250) + 'px';
			div.style.top = '150px';
			div.style.cursor = 'pointer';
			div.style.display = 'block';
			div.innerHTML = data;
			$('#warning_block').bind('mousedown', handleSafetyGrab);
			$('#safety_close').bind('click', handleSafetyClose);
		}
	};
	
	jQuery.ajax(options);
	return false;
};


/*slideshow object will read an array of images and rotate through them - fading from one to another
* the init method should be called after the element is created with the following 3 params
* param1 slideShowEl - DOM element(block) required = the div where the slideshow will be displayed 
* param2 imagePaths - array required = array of file names
* param3 basePath - String optional = can be blank, relative, or absolute
*
*other values that can be changed:
* selectedImg - int = the first image to display;
* timeOutValue - int = the time before the next image starts to load
* fadeInTime - int = the time to fade from one img to the other after a normal timout 
* fadeInTimebyNumber - it = the time to fade when a specific img number is passed 
*/
var SlideShow = {
	slideShowEl: '',
	imagePaths:[],
	basePath: '',
	selectedImg:0,
	timeOutValue:5000,
	fadeInTime: 500,
	fadeInTimeByNumber: 200,
	preLoadImg: document.createElement('img'),
	
	init: function(ssElement, ssImages, ssBasePath){	
		var slideShowObj = this;
		this.slideShowBg = ssElement;
		this.imagePaths = ssImages;
		this.basePath = ssBasePath;
		if(!this.imagePaths){
			alert('imagePaths are not defined!');
			return;
		}
		//if the bg element is an img tag then replace it with a div tag
		if(this.slideShowBg.get(0).src){
			var newBg = $('<div></div>').attr('id', 'slideShowBg');
			newBg.css('height',this.slideShowBg.height());
			newBg.css('width',this.slideShowBg.width());
			newBg.css('background-image','url(' + this.slideShowBg.get(0).src + ')');
			this.slideShowBg.replaceWith(newBg);
			this.slideShowBg = newBg;
		};
		
		//create a new div to fade from -each time we switch images this div is shown in front and the new image fades in
		//after the image is 100% opac the src for ssElement background is changed and this div is hidden. 
		this.slideShowEl = $('<div></div>').attr('id', 'slideShowTmpDiv');
		this.slideShowEl.css('height',this.slideShowBg.height());
		this.slideShowEl.css('width',this.slideShowBg.width());
		this.slideShowEl.css('position','absolute');
		this.slideShowEl.click(function(){
						var selImg = slideShowObj.imagePaths[slideShowObj.selectedImg];
						if(selImg.href){
							if(selImg.newWin){
								window.open(selImg.href);
							}else{
								window.location.href=selImg.href;
							}
						}
					});
		this.slideShowBg.prepend(this.slideShowEl);
		
		$(this.preLoadImg).bind('load',
				function() {
					var ssCursor = "default";
					if(slideShowObj.imagePaths[slideShowObj.selectedImg].href){
						ssCursor = "pointer";
					}					
					slideShowObj.slideShowEl.hide()
						.css('background-image','url(' + this.src + ')')
						.css('cursor',ssCursor)
						.fadeIn(this.timeToFadeIn);

					slideShowObj.onChange();
				});
		
		this.show(this.selectedImg);
	},
	play:function(toggleValue){
		if(toggleValue){
			if(!this.slideShowIsStopped){
				this.stop();
				this.slideShowEl.show(this.selectedImg);
			}else{
				this.slideShowIsStopped = false;
				this.show();
			}
		}else{
			this.show();
		}
	},
	next:function(){
		this.show();
	},
	prev:function(){
		this.selectedImg--;
		if (this.selectedImg  < 0) {
			this.selectedImg  = this.imagePaths.length - 1;
		}
		this.show(this.selectedImg);
	},
	stop:function(){
		window.clearTimeout(this.slideShowTimer);
		this.slideShowIsStopped = true;
	},
	show: function(slideNum) {
		var slideShowObj = this;
		window.clearTimeout(this.slideShowTimer);
		this.preLoadImg.timeToFadeIn = this.fadeInTime;

		if(slideNum != undefined && !isNaN(slideNum)){
			if(slideNum>=0 && slideNum<this.imagePaths.length){
				this.selectedImg = slideNum;
				this.preLoadImg.timeToFadeIn = this.fadeInTimeByNumber;
			}else{
				alert('The requested image number for the slideshow is out of range.');
			}
		}else{
			this.selectedImg++;
			if (this.selectedImg >= this.imagePaths.length) {
				this.selectedImg  = 0;
			}
		}
		
		this.slideShowBg.css('background-image', this.slideShowEl.css('background-image'));
		var path = this.basePath + this.imagePaths[this.selectedImg].img;
		this.preLoadImg.src = path;

		if (!this.slideShowIsStopped) {
			this.slideShowTimer = window.setTimeout(function(){slideShowObj.show();}, slideShowObj.timeOutValue);
		}
	},
	onChange: function(){}
};



function initialize(){
	//bind the events for the menu
	$('#menuDrawerKnob a').click(
			function(){
				var complete = function(){
					var isOpen = ($(this).parent().css('display') != 'none')?1:0;
					setCookie('drawerState',isOpen,'30');
				};
				$('#menuDrawer').animate({height: 'toggle'},350,complete);
				$(this).parent().toggleClass('closed');
			});
	
	//initialize the slideshow and set-up the navigation of the slideshow if the element exists
	var ssElem = $('#slideShowImg');
	if(ssElem.length){
		//add the data
		var ssBasePath = 'http://assets-static.lemansnet.com/sites/mooseracing/images/slideshow/';
		var ssImgs = [
				{img:'2012_M1_SPLASH_PAGE.jpg', href:'catalog.jsp?level1=1749&level2=1762&category_id=1762', newWin:true},
				{img:'2012_XCR_SPLASH_PAGE.jpg',href:'catalog.jsp?level1=1749&level2=1761&category_id=1761', newWin:false},
				{img:'2012_SAHARA_SPLASH_PAGE.jpg',href:'catalog.jsp?level1=1749&level2=1763&category_id=1763', newWin:false},
				{img:'2012_QUALIFIER_SPLASH_PAGE.jpg',href:'catalog.jsp?level1=1749&level2=1764&category_id=1764', newWin:false}
				];
		
		  //add the controls
		  var mediaControl = $('#mediaControl');
		  var mediaBox = [];
		  for(var b=0;b<ssImgs.length;b++){
			mediaBox[b] = $('<div></div>').attr('ssNum', b); //.addClass('ssBox')
			mediaBox[b].html(b+1);
			if(b==0){mediaBox[b].addClass('selectedImg');}
			mediaBox[b].click(function(){SlideShow.show($(this).attr('ssNum'));});
			mediaControl.append(mediaBox[b]);
		}
		
		//set the custom onchange event to update our media control
		SlideShow.onChange = function(){
			for(var e in mediaBox){
				if(this.selectedImg == mediaBox[e].attr('ssNum')){
					mediaBox[e].addClass('selectedImg');		
				}else if(mediaBox[e].className != ''){
					mediaBox[e].removeClass('selectedImg');
				}
			}
		};
		
		//start the slideshow
		SlideShow.init(ssElem, ssImgs, ssBasePath);
	};
	

	if(getEl('requestCatalog')){
		getEl('requestCatalog').onsubmit = validateCatalogForm;
	}
	
	if(getEl('contactForm')){
		getEl('contactForm').onsubmit = validateContactForm;
	}
	
	$('#newsletterForm').bind('submit', validateNewsletterForm);
	
	if(getEl('home_updates')) {
		getEl('contactEmail').onfocus = function() {
			getEl('contactEmail').value = '';
		}
	}
	
	if(getEl('locatorForm')){
		getEl('locatorForm').onsubmit = validateLocatorForm;
	}
	
	if(getEl('home_wheretobuy')) {
		getEl('zipCode').onfocus = function() {
			getEl('zipCode').value = '';
		}
	}
	
	
	// 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 = getEl("showPartsButton");
	if (showPartsButton){
		var partsTable = getEl("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 (getEl("thumbnails")){
		var thumbnails = getEl("thumbnails").getElementsByTagName("li");
		for (var i=0; i<thumbnails.length; i++){
			thisLink = thumbnails[i].getElementsByTagName("a")[0];
			thisLink.onclick = function(){
				var bigImage = getEl("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(getEl('dealerList')){
		var anchors = getEl('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)};
			}
		}
	}
	
	$('#safetywarning').click(handleSafetyWarning);
	
	/*if(getEl('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);
$(document).ready(initialize);
