$(document).ready(function(){
	
	$(".page_number a").click(function(){
		$("#show_all").val("");
		catalog_redirect({'page_number' : $(this).attr("value")});
		return false; //needed to prevent attempt to jump to href="#"
	});
	
	$(".show_all").click(function(){
		$(this).val("show_all");
		catalog_redirect({'show_all' : $(this).attr("value")});
		return false; //needed to prevent attempt to jump to href="#"
	});

	//next arrow in pagination
	$(".right").click(function(){
		$("#show_all").val("");
		catalog_redirect({'page_number' : $(this).attr("value")});
		return false; //needed to prevent attempt to jump to href="#"
	});

	//prev arrow in pagination
	$(".left").click(function(){
		$("#show_all").val("");
		catalog_redirect({'page_number' : $(this).attr("value")});
		return false; //needed to prevent attempt to jump to href="#"
	});

	$("select.sort").change(function(){
		catalog_redirect({'sort' : $(this).val()});
	});

	$("select.metal").change(function(){
		catalog_redirect({'metal' : $(this).val()});
	});

});


function catalog_redirect(options)
{
	
	var current = {
		'base' : $("#pagination_base").val(),
		'page_number' : $(".page_number a").attr("value"),
		'sort_code' : $("select.sort").val(),
		'metal' : $("select.metal").val(),
		'view_type' : $("#view").val(),
		'show_all' : $("#show_all").val()
	};
	var values = {};
	$.extend(values, current, options);
	
	
	if(values.show_all == 'show_all')
	{
		var destination = $.ROOT_URL + values.base + values.page_number + "/" + values.sort_code  + "/" + values.view_type + "/" + values.metal + "/" + values.show_all;		
	}else{
		var destination = $.ROOT_URL + values.base + values.page_number + "/" + values.sort_code  + "/" + values.view_type + "/" + values.metal;
	}
	
	 

	window.location = destination;
}
