function showBioImage(id)
{
	// swap the displayed large bio image
	for (var x=0; x < document.images.length;x++)
	{
		if (document.images[x].parentNode.className != 'largeImages')
			continue;
		document.images[x].className = 'hide';
	}
	
	document.getElementById('medImg_'+id).className = '';
	
	return false;
}

function fixFindAStoreResults()
{
	var map = document.getElementById('usmap');
	var mapBottom = map.offsetTop+map.offsetHeight;
	
	var stores = document.getElementsByTagName('address');
	for (var x=0, foundFirstLeft=false,lastCleared=0; x < stores.length; x++)
	{
		if (stores[x].offsetTop < mapBottom)
			continue;

		stores[x].style['cssFloat'] = stores[x].style['styleFloat'] = 'left';

		if (!foundFirstLeft)
		{
			lastCleared = x;
			foundFirstLeft = (stores.length - x >= 3);
		}
		
		if (foundFirstLeft && ((x - lastCleared) % 3) == 0)
		{
			stores[x].style['clear'] = 'both';
		}
	}
}

function updateTeamQuickbladeThumbs()
{
	// add mouseover/out listeners to the thumbnails on Team Quickblade
	for (var x=0; x < document.images.length; x++)
	{
		if (document.images[x].parentNode.parentNode.tagName.toUpperCase() != 'P')
			continue;
		
		document.images[x].onmouseover = function () {
			this.parentNode.parentNode.childNodes[0].innerHTML = this.alt;
		};
		document.images[x].onmouseout = function () {
			this.parentNode.parentNode.childNodes[0].innerHTML = this.alt.match(/[a-zA-Z]+/);
		};
	}
}

function fixOurPaddlesVertCenter()
{
	// vertically center the paddles on our-paddles.html
	for (var x=0, spans=document.getElementsByTagName('span'); x< spans.length;x++)
	{
		var offset = 0;
		for (var childNodes=spans[x].childNodes, y=childNodes.length-1; y >= 0; y--)
		{
			// careful about getting text nodes
			if (!childNodes[y].tagName)
				continue;
			offset = ((spans[x].offsetHeight+spans[x].offsetTop)-childNodes[y].offsetTop-childNodes[y].offsetHeight)/2;
			break;
		}

		spans[x].style['minHeight'] = (spans[x].offsetHeight - offset) + 'px';
		spans[x].style['paddingTop'] = offset + 'px';
	}
}

function fixOurFriendsContainers()
{
	var objs = ['paddles','content','logos'];
	for (var x=0, maxHeight = 0; x < objs.length;x++)
		objs[x] = document.getElementById(objs[x]), maxHeight = Math.max(maxHeight, objs[x].offsetHeight);
	for (var x=0; x < objs.length;x++)
		objs[x].style['height'] = maxHeight + 'px';
}

// from oscommerce
function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

// for oscommerce view product page
function reorderDetails()
{
	// find the div with pricing info
	var pricingDiv=document.getElementById('price'), moreinfo = document.getElementById('moreinfo');
	
	// this shouldn't happen, but just in case...
	if (!pricingDiv || !moreinfo)
		return false;
	
	// find the next node (skip over text nodes)
	for (next=pricingDiv.nextSibling; next!=null && next.tagName==undefined;next=next.nextSibling) {};
	
	// if the div#moreinfo is before the pricing, swap them
	if (next != moreinfo)
		moreinfo.parentNode.insertBefore(pricingDiv, moreinfo);
	
	return true;
}

// for oscommerce view product page - show/hide the extended information
function toggleMoreInfo()
{
	if (!reorderDetails())
	{
		setTimeout(toggleMoreInfo, 100);
		return;
	}

	if (document.body.className.match('hide-moreinfo'))
		document.body.className = document.body.className.replace(/[ ]?hide-moreinfo/, '')
	else
		document.body.className = document.body.className += ' hide-moreinfo';
		
	return false;
}

// bring up the policies popup
function policiesPopup(obj)
{
	window.open(obj.href, 'policies', 'width=500, height=300, directories=no, location=no, menubar=no, resizable=no, scrollbars=1, status=no, toolbar=no');
	return false;
}

// sizing charts
function sizingPopup(obj)
{
	window.open(obj.href, 'sizing', 'width=480, height=650, directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no');
	return false;
}

// team quickblade detail view
function teamQBPopup(obj)
{
	window.open(obj.href, 'teamQB', 'width=940, height=350, directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no');
	return false;
}

// control sliding paddle display on homepage
function paddleSliderChange(displayPaddle)
{
	var	offsets = {'sup': '228px', 'outrigger': '-666px', 'kayak': '-1560px'},
		highlightOffsets = {'sup': '30px', 'outrigger': '415px', 'kayak': '784px'};

	var paddles = $$('#paddle_slider a').slice(0, 3);

	// already displaying this paddle? quit. in mid-animation? quit.
	if (paddles[0].getStyle('margin-left') == offsets[displayPaddle] ||
		paddles.pluck('animating').any()  )
		return false;

	// start the animation. make sure we set the "in mid-animation?" flag properly before we start and after we finish.
	paddles.invoke('morph', 'margin-left:'+offsets[displayPaddle]+';', {
		beforeSetup: function (effect) {
			effect.element.animating = true;
		},
		afterFinish: function (effect) {
			effect.element.animating = false;
		},
		duration: 1
	});
	
	$$('div.paddles-menu b')[0].morph('left:'+highlightOffsets[displayPaddle], {duration: 1});
	
	return false;
}

function initPaddleSlider()
{
	// IE8 was throwing fits, so I had to hardcode the styles here
	try {
		//$$('#paddle_slider a').shift().setStyle({'top':'180px'}).morph('top:25px', {transition: Effect.Transitions.spring, duration: 1});
		$$('#paddle_slider a').shift().setStyle({'top':'0px'}).hide().appear({duration: .5});
	} catch (err) {};
	//$('showall-icon').setStyle({'right':'-50px'}).show().morph('right: 10px', {duration: .5});
}

function fixProductView()
{
	/*
	try {
		var specs = document.getElementById('moreinfo');
		for(var obj = specs.nextSibling; obj != null; obj = specs.nextSibling)
			specs.parentNode.insertBefore(obj, specs);
		
		with (specs.style)
		{
			clear = 'both';
			cssFloat = 'none';
			margin = '0';
			paddingTop = '10px';
		}
	} catch (err) {};

	var	productDetails = $('cart_quantity').down('div.product-details'),
		productOptions = $('cart_quantity').down('div.options'),
		containerDiv = new Element('div', {'class':'productinfo-container'});
	
	containerDiv.insert($('features'));
	containerDiv.insert($('moreinfo'));
	containerDiv.insert(productOptions.previous('hr'));
	containerDiv.insert(productOptions);
	
	productDetails.insert(containerDiv);
	*/
}

function initOurPaddleScroll()
{	
/*
	for (var divs = $$('div.paddles > div'), x=0; x < divs.length; x++)
	{
		divs[x].setStyle({'top': (x*315)+'px', 'position':'absolute'});
		for (var lis = divs[x].select('li'), y=0; y < lis.length; y++)
		{
			//lis[y].setStyle({'position':'absolute', 'top':'0', 'left':(187*y)+'px'}).observe('mouseover', ourPaddlesMouseOver);
			
			var models = divs[x].select('dl dt:first-child');
			var theMax = models.pluck('offsetTop').max();
			
			models.each(function (obj) {
				obj.setStyle({'position':'relative', 'paddingTop':(theMax-obj.offsetTop)+'px'});
			});
			
			
			
			var	overviews = divs[x].select('dt ~ dt');
				theMax = overviews.pluck('offsetTop').max();
			
			overviews.each(function (obj) {
				obj.setStyle({'position':'relative', 'paddingTop':(theMax-obj.offsetTop)+'px'});
			});
		}
	}
*/
	for (var divs = $$('div.paddles > ul'), x=0; x < divs.length; x++)
		divs[x].setStyle({'top': (x*315)+'px'});



	var scrollToPaddles = unescape(location.href).replace(/^[^#]*(#([a-z]+)#)?$/,'$2');
	
	if (scrollToPaddles == 'outrigger')
		ourPaddlesScroll.defer(1, true);
	else if (scrollToPaddles == 'kayak')
		ourPaddlesScroll.defer(2, true);
	else
		ourPaddlesScroll.defer(0, true);
}

function ourPaddlesScroll(showRow, skipAnimation)
{
	// the offsets are for the animated highlighter thing that slides behind the currently showing section
	var	effects = [],
		highlightOffsets = [30, 415, 784],
		divs = $$('div.paddles > ul'),
		slider = $$('div.paddles-menu b').pop();
	

	if (skipAnimation == true)
	{
		slider.setStyle({'left':highlightOffsets[showRow]+'px'});
		
		for (x=0; x < divs.length; x++)	
			divs[x].setStyle({'top': (315 * (x-showRow))+'px'});
		return;
	}
	
	
	// we have a couple container divs that need to be moved in unison,
	// making sure the newly selected section is what's visible
	for (x=0; x < divs.length; x++)
	{
		effects.push(
			new Effect.Morph(divs[x], {
				style: 'top: '+(315 * (x-showRow))+'px;',	// the "magic" 315px here is the height of each paddle section's div, set in the styles.css
				sync: true
			})
		);
	}

	// add the highlighter's sliding animation to the stack
	effects.push(
		new Effect.Morph(slider, {
			style: 'left: '+highlightOffsets[showRow]+'px',
			sync: true,
			afterFinish: function () {
				if (slider.offsetLeft != highlightOffsets[showRow])
					slider.setStyle({'left: ': highlightOffsets[showRow]+'px'});
			}
		})
	);
	
	// animate!
	new Effect.Parallel(effects, {duration: 1.0});
	
	return false;
}

function ourPaddlesMouseOver(ev)
{
	var theDL = $$('.paddles-more-info')[0], currentlyMousedOverObject = Event.element(ev), theDD = theDL.down('dd');
	
	if (currentlyMousedOverObject.tagName.toUpperCase() != 'LI')
		currentlyMousedOverObject = currentlyMousedOverObject.up('li');
	
	try {
		// if this throws an error, then we haven't set	the property yet, continue
		if (theDL.previouslyShown == currentlyMousedOverObject)
			return;

	} catch (err) {};
	
	if (theDL.animating)
		theDL.effect.cancel();
	
	theDL.animating = true;
	theDL.previouslyShown = currentlyMousedOverObject;	
	theDL.setOpacity(0).show();

	theDL.select('dt *, dd *').invoke('remove');

	theDD.update(currentlyMousedOverObject.down('p').innerHTML).setStyle({
		'position':'absolute',
		'left':'440px',
		'top':'10px'
	});
	
	theDL.down('dt').setStyle({
		'height':(theDD.offsetHeight-20) + 'px'
	}).insert(
		currentlyMousedOverObject.select('div img').pop().clone()
	);
	
	theDL.setStyle({'position':'relative'});

	theDL.effect = new Effect.Appear(theDL, {
		duration: .5,
		afterFinish: function () {
			theDL.animating = false;
		}
	});
}


function showTeamList(category)
{
	$$('.teamlist').each(Element.hide);
	$("teamlist-" + category).show();

	return false;
}











/*
	They want the "Dealer Login" and "Contact" links in the upper right to line up with the logo...
	However, Macs are dealing with font sizes differently than PC-based browsers, and that's throwing
	things off.  Since there's no way to target Safari without also targeting both Chrome, and no
	way to target macs only, I'm left with few options.  So, we'll do a js detect for OS and
	add a class to the body if they're on a Mac.
	
	js c&p'd from Peter-Paul Koch's Quirksmode: http://www.quirksmode.org/js/detect.html
*/
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
window.onload = function () {
	if (BrowserDetect.OS == 'Mac')
		document.body.className += ' mac-os';
}