$(document).ready(function() {

	$(".slidetabs").tabs(".images > .myshow", {
	
		// enable "cross-fading" effect
		effect: 'fade',
		fadeOutSpeed: 'slow',
	
		// start from the beginning after the last tab
		rotate: true
	
	// use the slideshow plugin. It accepts its own configuration
	}).slideshow({autoplay: true,interval:7000,clickable:false});


	// 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();
		var id = $(this).attr('id').replace('prodId-','');
		var q = $('#quantity-'+id);
		var qv = q.val();
		var min = $('#min-'+id).attr('title');

		if (qv != '') {
			if ( parseInt(qv) == 0 || parseInt(qv) < parseInt(min) ) {
				q.addClass('error');
				if ( parseInt(qv) == 0 ) {
					alert('your quantity must be more than 0!');
				} else {
					alert('minimum order must be more than '+min);
				}
				return false;
			} else {
				$.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('');

	$('#subForm').validate();

	if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
		var isOS5 = navigator.userAgent.match(/OS 5_0/i) != null;
		if (!isOS5) {
			$("#footer").css("position", "static");	
		}
	};


});

//Cufon.replace('h1')('h2')('#options, #related');
