jQuery(document).ready(function($) {
	// ---- END FUNCTIONS ---- //
	// expand more products
	function expandProducts() {
		$('#product-list').animate({
			height: $('#product-list img:first').height() + $('#product-list img:last').height() + $('#product-list ul, #product-list ul li:first, #product-list ul li:last').getOffsets()
		}, 500, 'swing', function() {
			$('#product-list li:eq(5)').mouseover();
		});
		return false;
	}
	
	// contract more products
	function contractProducts() {
		var minHeight = $('#product-list img:first').height()
		$('#product-list').animate( {
			height:  $('#product-list img:first').height()
		}, function() {
			// cater to Safari >= 3 Windows
			$(this).height(minHeight).css('overflow', 'hidden');
		});
	}
	
	function swap(obj) {
		var href = $(obj).attr('href');
		// if the tab being moused over is not visible make it visible 
		if ($(href+':hidden').length === 1) {
			$(current).fadeOut(500, function() {
				$(current).hide();
				$(href).fadeIn(500);
				current = href;
			});
		}
	}
	// ---- END FUNCTIONS ---- //
	
	
	// font hack for Safari
	if ($.browser.safari) {
		$('body').css('font-size', '0.65em');
	}
	
	// margin hack for opera
	if ($.browser.opera) {
		$('#products-inline li').css('margin-bottom', '13px');
	}
	
	// ---- TABS ---- //
	var current = '';
	
	// set the initial height for the product list
	$('#product-list').css('overflow', 'hidden').height($('#product-list img:first').height());
	// set the click event for the more button
	$('#product-list a[@href=#more]').toggle(function() {
		swap($('#product-list a:eq(5)').get());
		expandProducts();
		current = $('#product-list a:eq(5)').attr('href');
	}, function() {
		swap($('#product-list a:eq(0)').get());
		contractProducts();
		current = $('#product-list a:eq(0)').attr('href');
	});
	
	$('#product-list a').not('[href=#more]').each(function() {
		var href = $(this).attr('href');
		// hide each one
		$($(this).attr('href')).hide();
		// onmouseover
		$(this).hoverIntent(function() {
			swap(this);
			if ($('#product-list a').not('[href=#more]').index(this) < 4 && $('#product-list a').index($('[href='+current+']').get(0)) > 4) {
				$('#product-list a[href=#more]').click();
			}
			current = href;
		}, function(){return;});
		// prevent the following of the link
		$(this).click(function(){return false;});
	});
	// make the first one active on load
	$($('#product-list a:first').attr('href')).show();
	// set the current active tab
	current = $('#product-list a:first').attr('href');
});