
$(document).ready(function() {

	// Product Details Tabbed Content - Not working in IE8 :(	
	$('ul.tabs').each(function() {
		$(this).find('li').each(function(i) {
			$(this).click(function(){
				$(this).addClass('current').siblings().removeClass('current')
					.parents('div.product-tabs').find('div.box').hide().end().find('div.box:eq('+i+')').fadeIn(150);
			});
		});
	});
	
	// Category select box in the shop to jump between each.
	$('#category-change select').change(function(){
		document.location = '/shop/category/'+$(this).val();
	});
	
	// change the date on the calendar	
	$('.news-date-links a').click(function() {
		href = $(this).attr('href');
		var parts = href.substr(1,href.length).split('-');
		$('#month').val(parts[0]);
		$('#year').val(parts[1]);
		$('#hidden_form').submit();
		return false;
	});
		
	// Add a rel attribute to image links so they are linked in fancybox
	$('#pages-right-content > img').each(function() { 
		$(this).wrap('<a href="'+$(this).attr('src')+'" />'); 
	});
	$('.imageone,.imagetwo,.imagethree,.imagefour,.imagefive,.imagesix').each(function() {
		$(this).parent('a').attr('rel', 'image');
	});
	
	// Fancybox for images.
	$('.imageone,.imagetwo,.imagethree,.imagefour,.imagefive,.imagesix').parent().fancybox({
		'titlePosition': 'over',
		'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' &ndash; ' + title + '</span>';
		}
	});
	
	$('#checkout-buttons').remove();
	$('#cart-wrap .cart-checkout-login').after('<p id="checkout-buttons"><a href="/shop"><img src="/common/img/btn-continueshopping.png" alt="Continue Shopping" /></a> <span class="or">or</span> <input type="image" src="/common/img/btn-proceed.png" name="checkout" value="Checkout" /></p>');
	$('.button-calculate').attr('src', '/common/img/btn-calculate.png');
	
	$('.lightbox').fancybox({
		overlayOpacity: '0.5',
		overlayColor: '#000'
	});
	
	$('#nav-site li:first-child').addClass('first-child');
	$('#nav-site li:last-child').addClass('last-child');
	
	// Masthead banner rotation
	var nextBanner = function() {
		
		// get the current banner
		$current = $('#masthead-banner img.current');
		
		// get the next banner
		$next = $current.next('img.banner');
		if ($next.length == 0) {
			$next = $('#masthead-banner img.first');
		}
		
		// hide the current
		$current.fadeOut(500);
		$current.removeClass('current');
		
		// show the next
		$next.fadeIn(500);
		$next.addClass('current');
		
	};
	setInterval(nextBanner, 5000);
	
	$('#payment_type_fax').each(function() { $(this).parent().remove(); });
	$('#cart-wrap .radio input').click(function() {
		$('#cart-wrap form .process').toggle( ! $('#payment_type_paypal')[0].checked );
	
	
	
	});
	
});


