var volusionHacks = {
	init: function() {
		volusionHacks.disableProductSort();
		volusionHacks.hideBreadcrumb();
		volusionHacks.tagMainNav();
		volusionHacks.urlRewrites();
		volusionHacks.fixColors();
		volusionHacks.enableSlideshows();
	},
	disableProductSort: function() {
		$('#MainForm table:first').hide();
	},
	hideBreadcrumb: function() {
		// hide breadcrumb when not on homepage and shopping cart
		//if( ($(location).attr('href').indexOf('default.asp') < 0) && ($(location).attr('href').indexOf('shoppingcart.asp') < 0) ) $('#content_area table:first').hide();
	},
	tagMainNav: function() {
		var subCatRaw=$(location).attr('href').split('?')[1];
		if(subCatRaw) {
			// subcategories
			var subCat=subCatRaw.split('=')[0];
			if (subCat=='ID') {
				var subCatPer=subCatRaw.split('=')[1];
				switch(subCatPer) {
					case "1":
					$('#horznav-about').addClass('active');
					break;
					
					case "238": case "239":
					$('#horznav-interact').addClass('active');
					break;
				}
			// subcategory items
			} else {
				var subCatItem=subCatRaw.split('=')[1];
				switch(subCatItem) {
					case "12": case "13": case "14": case "20": case "21": case "22": case "23": case "24": case "25": case "26": case "43": case "42": case "46": case "51":
					$('#horznav-about').addClass('active');
					break;
				
					case "8": case "3": case "47":
					$('#horznav-purchase').addClass('active');
					break;
				
					case "7": case "48": case "49": case "50":
					$('#horznav-interact').addClass('active');
					break;
				
					case "29": case "30": case "31": case "36": case "37": case "38": case "39": case "44":
					$('#horznav-trade').addClass('active');
					break;
				}
			}
		// shopping cart
		} else if($(location).attr('href').indexOf('shoppingcart.asp') >= 0) {
			$('#horznav-purchase').addClass('active');
		// gift message
		} else if($(location).attr('href').indexOf('GiftOptions.asp') >= 0) {
			$('#horznav-purchase').addClass('active');
		// one page checkout
		} else if($(location).attr('href').indexOf('one-page-checkout.asp') >= 0) {
			$('#horznav-purchase').addClass('active');
		// order finished
		} else if($(location).attr('href').indexOf('OrderFinished.asp') >= 0) {
			$('#horznav-purchase').addClass('active');
		// otherwise, highlight the "home" item
		} else {
			$('#horznav-home').addClass('active');
		}
	},
	urlRewrites: function() {
		$('a').attr('href',function(){
			return this.href.replace('ProductDetails','ShoppingCart');
		});
		$('img').attr('src', function() {
			if (this.src.indexOf('btn_continueshopping.gif') >=0 ) {
				$(this).parent().attr('href',function(){
				return this.href.replace('default.asp','SearchResults.asp?Cat=3');
				});
			}
		});
	},
	fixColors: function() {
		$('#table_checkout_cart0').attr('bgcolor', '');
		$('#table_checkout_cart2').attr('bgcolor', '');
		$('#table_checkout_cart3').attr('bgcolor', '');
		$('#font_checkout_cart').attr('color', '');
		$('a').each(function(){
			if(this.style.color) this.style.color='';
		});
		$('td').each(function(){
			if(this.style.color) this.style.color='';
		});
	},
	enableSlideshows: function() {
		$('.slideshow').cycle({
			speed: 750,
			random: 1,
			timeout: 2000
		});
	}
}

$(document).ready(function () {
	volusionHacks.init();
});
