$(document).ready(function() {

	// check element ID exists before creating the slideshow
	if ($("#slideshow").length) {
		$('#slideshow').cycle({
			fx: 'fade',
			timeout: 5000,
			speed: 500
		});
	}

	// not sure why.... but this is required in both the template and functions-checkout.js :S
	function clearConsole() {
		if (window.console && window.console.firebug) {
			console.clear()
		}
	}
	
	// styling for the menu hover
	$('#product-menu ul li').hover(
		function() {
			var id = $(this).attr('id').replace('category-','')
			$('#subcatcontainer-'+id).fadeIn(300);
			$(this).css({"border-left":"solid 2px #ddd","border-right":"solid 2px #ddd","margin":"0","z-index":"1000"});
		},
		function() {
			var id = $(this).attr('id').replace('category-','')
			$('#subcatcontainer-'+id).fadeOut(150);
			$(this).css({"border-left":"solid 2px #fff","border-right":"solid 2px #fff"});
		}
	);

	// based upon the element number show the subcategories drop either left or right
	$(".subprods").parent().each(function(){
		// get container element
		var me = $(this).attr('class').replace('subcat drop','');
		if (me >= 5) {
			$(this).addClass('drop-right');
		} else {
			$(this).addClass('drop-left');
		}
		// get # of ul elements within subprods
		var w = $(this).find('ul').length
		// apply class to specify widths based on # of ul elements
		if (w > 1) {
			$(this).addClass('double');
		} else {
			$(this).addClass('single');
		}
	});

	// sets focus to the first product quantity element
	//$(".product-options input:text:visible:first").focus();

	// add item to basket
	$('.button-add').click(function(e){
		e.preventDefault();
		id = $(this).attr('id').replace('prodId-','');
		q = $('#quantity-'+id);
		qv = q.val();
		if (qv != '') {
			$.post('/resources/vb/post-basket-item.asp',{
			id:id,
			quantity:qv
			},function(response){
				if (response != '') {
					q.val('');
					q.removeClass('error');
					$('#basket').fadeOut(20);
					$('#basket').animate({opacity: 1.0}, 300)
					$('#basket').load('/resources/vb/post-get-basket.asp',{basket:response});
					$('#basket').fadeIn(150);
				}
			});
		} else {
			q.addClass('error');
		}
	});

	// getbasket function, loads the basket count/price in the footer
	function getbasket(basket) {
		$('#basket').empty();
		$('#basket').load('/resources/vb/post-get-basket.asp',{basket:basket});
		clearConsole();
	}
	getbasket('');

});

//Cufon.replace('h1')('h2')('#options, #related');