// taylormotorcycles.com.au javascript

var showing;
var order = Array();
order['first'] = 1;
order['second'] = 2;
order['third'] = 3;


function init() {
	//MM_preloadImages('images/go_on.gif','images/addtocart_on.gif','images/more_black_ltgrey.gif','images/more_red_dkgrey.gif','images/more_black_white.gif','images/shoponline_black.gif','images/more_white_dkgrey.gif','images/gotocheckout_on.gif','images/backtoheadlines_black_white.gif','images/vidman_on.gif')

	if(document.getElementById('shopnav')) {
		initShopNavigation();
	}

	if(document.getElementById('standardnav')) {
		var fo2 = new SWFObject("/assets/images/flash/footer_logo2.swf","swffooter","252","145", "6");
		fo2.addParam("wmode", "transparent");
		fo2.write('footerlogo');
	}

	if(document.getElementById('diffshipping')) {
		var s = document.getElementById('diffshipping');
		if(!s.checked)
			document.getElementById('shippingdetailsbox').style.visibility = 'hidden';
		s.onclick = function() {
			if(document.getElementById('shippingdetailsbox').style.visibility != 'hidden')
				document.getElementById('shippingdetailsbox').style.visibility = 'hidden';
			else
				document.getElementById('shippingdetailsbox').style.visibility = 'visible';
		}
	}

	BrowserDetect.init();

	if(BrowserDetect.browser=='Firefox'&&BrowserDetect.version<1.5)
	{
		if(document.getElementById('alert'))
		{
			var alerter = document.getElementById('alert');
			alerter.setAttribute('class','alertme');
			alerter.innerHTML = '<div>Alert - Your Firefox is outdated and this website might not display correctly as a result. Please visit <a href="http://www.mozilla.com/firefox/" target="_blank">http://www.mozilla.com/firefox/</a> and download the latest version. It\'s free and quick to do. Thank you.</div>';
		}
	}
}

function initShopNavigation() {
	var n = document.getElementById('shopnav');
	var lists = n.getElementsByTagName('ul');
	for(var i=0;i<lists.length;i++) {
		// hide all sub levels to start with
//		if(lists[i].className != 'first')
//			lists[i].style.display = 'none';

		// scan the current lists
		var items = lists[i].getElementsByTagName('li');
		for(var j=0;j<items.length;j++) {
			// even listener
			items[j].childNodes[0].onclick = function() {
				var subs = this.parentNode.getElementsByTagName('ul');
				if(subs.length>0) {
					// does for sub menu
						// toggle display or hide
						if(subs[0].style.display == 'none') {
							if(showing)
								showing.className = '';
							// close everything but parents
							for(k=0;k<lists.length;k++) {
								if(order[lists[k].className]>=order[subs[0].className]) {
									if(lists[k]!=subs[0])
										lists[k].style.display = 'none';
								}
							}
							subs[0].style.display = 'block';
							this.className ='active';
							showing = this;
						}
						else {
							subs[0].style.display = 'none';
							this.className = '';
						}

				}
				if (this.title!='active')
					return false;
			}
		}

	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}


MM_reloadPage(true);




function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function validateOrderForm(inp) {
	if(inp.style_id.length) {
		for (var i=0; i < inp.style_id.length; i++)
		{

			if (inp.style_id[i].checked)
			{
				return true;
			}
		}
	}
	else {
		// single radio button
		if(inp.style_id.checked)
			return true;
	}
	document.getElementById('ordermsg').className = 'errornostyle';
	return false;
}

function validOrderForm() {
	document.getElementById('ordermsg').className = 'normalstyle';
}

function validateSpares(inp) {
	if(!inp.name.value) {
		alert('Please enter your name');
		inp.name.focus();
		return false;
	}
	if(!(inp.phone.value||inp.email.value)) {
		alert('Please enter either a phone or an email to reach you on');
		inp.phone.focus();
		return false;
	}
	if(!inp.description.value) {

		alert('Please provide some description of your request!');
		inp.description.focus();
		return false;
	}
	return true;
}

function validateWorkshop(inp) {
	if(!inp.name.value) {
		alert('Please enter your name');
		inp.name.focus();
		return false;
	}
	if(!(inp.phone.value||inp.email.value)) {
		alert('Please enter either a phone or an email to reach you on');
		inp.phone.focus();
		return false;
	}
	if(!inp.description.value) {
		alert('Please provide some description of your request!');
		inp.description.focus();
		return false;
	}
	return true;
}

function openWhichBike(which) {
	var p = window.open(which,'tmcpopup','height=440,width=600,toolbar=no,scrollbars=auto');
	p.focus();
	return false;
}

function openHelpPage(helppage) {
	var p = window.open(helppage,'tmcpopup','height=365,width=573,toolbar=no,scrollbars=yes,resizable=yes');
	p.focus();
	return false;
}

window.onload = init;

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.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			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"
		},
		{	// 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.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
