/**** Add application wide javascripts below this point  ******/
$(document).ready(function(){
	pageinit();
});

function pageinit(){
	product_image_switcher();
	colorswitch();
	stockist_switcher();
}
function product_image_switcher(){
	if($('a.product_thumb').length){
		$('a.product_thumb').hover(function(){
			var href = $(this).attr('href');
			$('#product-image-main img').attr('src', href);
			return false;
		}, 
		function(){});
	}
}

function colorswitch(){
	$('#update_product input[type=radio]').click(function(){
		var newproduct = $(this).val().replace(/~/, '/')+".ajaxed";
		$('#content-primary').fadeTo('slow','0.2').css('background', 'url(/images/cms/indicator.gif) no-repeat top center');
		$.post(newproduct, function(response){
			$('#content-primary').replaceWith(response);
			pageinit();
		});
	});
}

function stockist_switcher(){
	if($('select#product_code').length){
		$('select#product_code').change(function(){
			$('#content-primary').fadeTo('slow','0.2').css('background', 'url(/images/cms/indicator.gif) no-repeat top center');
			$.get('/'+langcode+'/where-to-buy/'+$(this).val()+".ajaxed", function(response){
				$('#content-primary').replaceWith(response);
				pageinit();
			});
		});
	}
}