$(function()
{
	if(document.getElementById('view_sel'))
	{
		document.getElementById('view_sel').onchange = function()
		{
			var loc = window.location.toString();

			loc += loc.indexOf('?') != -1 ? (loc.indexOf('per_page=') != -1 ? '' : '&') : '?';
			loc = loc.indexOf('per_page=') != -1 ? loc.replace(/per_page=[\d]+/, 'per_page='+$(this).val()) : loc+'per_page='+$(this).val();
			//go back to the first page always when changing per_page value
			loc = loc.replace(/([\?&])page=[\d]+/,'$1page=1');

			setTimeout(function(){window.location=loc}, 0);
		};
	}

	if(document.getElementById('sort_sel'))
	{
		document.getElementById('sort_sel').onchange = function()
		{
			var loc = window.location.toString();

			loc += loc.indexOf('?') != -1 ? (loc.indexOf('order=') != -1 ? '' : '&') : '?';
			loc = loc.indexOf('order=') != -1 ? loc.replace(/order=(.*)(&|$)/, 'order='+encodeURIComponent($(this).val())+'$2') : loc+'order='+encodeURIComponent($(this).val());
			setTimeout(function(){window.location=loc}, 0);
		};
	}

	if(!IS_MOBILE)//prevent an error in mobile version
	{
		$('.filters form').jqTransform();

		//$('.products_list_category form').jqTransform();
		$('.products_list_category form .product_item .pr_2 ul li:first-child').addClass('red_text');

		//attach the 'add to compare list' function
		$('.products_list_category .go_compare input').click(function(){
			Products.add_or_remove_to_compare(this.id.toString().replace(/[^0-9]+/, ''), this);
		});

		$('#items_to_compare_block li .delete_ico').click(function(){
			Products.add_or_remove_to_compare(this.id.toString().replace(/[^0-9]+/, ''), this);
		});

		/*$('.products_list_category .go_compare input').each(function(index, obj){
			obj.onclick = function(){
				Products.add_or_remove_to_compare(obj.id.replace(/[^\d]+/, ''), this);
			}
		});*/

		if($('#make_the_compare').length)
		{
			//update target url of the COMPARE button
			Products.recreate_compare_link();
			Products.save_back_link_url();
		}
	}

});