//ensure the url begins with "www" for purposes of SSL certificates/Thawte verification
//URL rewriting for the Apache-deficient
if (location.href.search(/^https?:\/\/www\./i) < 0) {
	location.href = location.href.replace(/^(https?:\/\/)/i, '$1www.');
}

$(function() {	//DOM done loading
	preloadImages();

	//this line just replaces the entire document with the Thawte image (which is why we don't use it):
	//$('div#thawte > script').attr('src', 'https://siteseal.thawte.com/cgi/server/thawte_seal_generator.exe');

	//replacement doc.write() for use on closed doc
	document.write = (function () {
		for (var i = 0; i < arguments.length; i++) {
			$('div#thawte').append(arguments[i]);
		}
	});

	//thawte's script calls doc.write() to do its work; will now append to the
	//appropriate div instead of replacing the document
	$('#thawte > script').attr('src', 'https://siteseal.thawte.com/cgi/server/thawte_seal_generator.exe');
});//DOM done loading

var rolloverImages = [
	strImagePath + 'img/topnav_home_on.gif',
	strImagePath + 'img/topnav_myaccount_on.gif',
	strImagePath + 'img/topnav_mycart_on.gif',
	strImagePath + 'img/topnav_ordertracking_on.gif',
	strImagePath + 'img/topnav_contactus_on.gif'
];
function preloadImages() {
	if (!document.preloaded) {
		document.preloaded = new Array();
	}
	
	var j = document.preloaded.length;
	for (var i = 0; i < rolloverImages.length; i++) {
		document.preloaded[j] = new Image();
		document.preloaded[j++].src = rolloverImages[i];
	}
}//preloadImages()

var out = 'out', over = 'over', follow = 'follow';
function topnav(elem, overOut) {
	var elemid = elem.id;
	var imgid = elemid + 'img';
	var imgelem = document.getElementById(imgid);
	var imgsrc = strImagePath + 'img/' + elemid + '.gif';
	var imgsrc_on = strImagePath + 'img/' + elemid + '_on.gif';
	
	if (overOut === 'out') {
		elem.className = 'topnav_out';
		imgelem.src = imgsrc;
	} else if (overOut === 'over') {
		elem.className = 'topnav_over';
		imgelem.src = imgsrc_on;
	} else if (overOut === 'follow') {
		var linkid = elemid + 'link';
		window.location = document.getElementById(linkid).href;
	}
}//topnav()

