paramJSON.ajax = 'on';
paramJSON.type = 'filter'

/*
function calculatePriceMax(pricemax)
{
	var interval = Math.floor(pricemax/4);
	paramJSON['priceRange1']=interval;
	paramJSON['priceRange2']=interval*2;
	paramJSON['priceRange3']=interval*3;
}
*/

function product(id,lev){
	window.open('/cart/add/'+lev+'/'+id+'/');
}

function filter()
{
	var type= $(this).attr("id");
	
	if(typeof(type) == "undefined" || type=="zoekImage")
		type = "filterInputField"; 
	
	if($(this).hasClass('star-rating'))
		type = "stars";
	else if($(this).hasClass('rating-cancel'))
		type = "removeStars";
	
	switch(type)
	{
		case 'priceAsc':
			paramJSON['sortPrice'] ='asc';
			paramJSON['sortName']='';

			$("span.selected").removeClass('selected');
			$(this).children("input").attr("checked","checked");
		break;

		case 'priceDesc':
			paramJSON['sortPrice']='desc';
			paramJSON['sortName']='';

			$("span.selected").removeClass('selected');
			$(this).children("input").attr("checked","checked");
		break;
		 
		case 'nameAsc':
			paramJSON['sortName']='asc';
			paramJSON['sortPrice']='';

			$("span.selected").removeClass('selected');
			$(this).children("input").attr("checked","checked");
		break;
		
		case 'nameDesc':
			paramJSON['sortName']='desc';
			paramJSON['sortPrice']='';

			$("span.selected").removeClass('selected');
			$(this).children("input").attr("checked","checked");
		break;
	
		case 'priceRange1':
			paramJSON['priceMin'] = 0;
			paramJSON['priceMax'] = paramJSON['priceRange1'];
			$("#column2 .selected").removeClass('selected');
		break;
		
		case 'priceRange2':
			paramJSON['priceMin'] = paramJSON['priceRange1'];
			paramJSON['priceMax'] = paramJSON['priceRange2'];
			$("#column2 .selected").removeClass('selected');
		break;
		
		case 'priceRange3':
			paramJSON['priceMin'] = paramJSON['priceRange2'];
			paramJSON['priceMax'] = paramJSON['priceRange3'];
			$("#column2 .selected").removeClass('selected');
		break;
		
		case 'priceRange4':
			paramJSON['priceMin'] = paramJSON['priceRange3'];
			paramJSON['priceMax'] = 9999999;
			$("#column2 .selected").removeClass('selected');
		break;
		
		case 'leveranciersFilter':
			paramJSON['leveranciers'] = $("#leveranciersFilter").val();
		break;
		
		case 'filterInputField':
			paramJSON['nameString'] = $("#filterInputField").val();
		break;
		
		case 'stars':
			paramJSON['stars'] = $(".star-rating-on").size();
		break;
		
		case 'removeStars':
			paramJSON['stars'] = 0;
		break;
		
		case 'clearFilter':
			paramJSON.sortName = '';
			paramJSON.sortPrice = '';
			paramJSON.stars = '';
			paramJSON.nameString = '';
			paramJSON.priceMin = '';
			paramJSON.priceMax = '';
			paramJSON.leveranciers = '';
			
			$("#filterInputField").val("");
			$("#leveranciersFilter").val("").change();
			$("#advanceFilter .selected").removeClass('selected');
			$(".star-rating").removeClass("star-rating-on");
			$("input:radio").attr("checked","");
		break;
		
		default:
		 	// nothing to be executed if there is no match
	}
	
	$(this).addClass('selected');
	paramJSON['active']= 1; //set the active page to page 1 after sorting
	
	$.ajax({
   		type: "POST",
   		url: "ajax.php?url=http://www.%systemdomain%/php/ajax/ajax_handler.php",
   		dataType: "json",
		data: paramJSON,
   		cache: false,
   		beforeSend: function(){$("#overzichtContent").stop(true,true).html("<div style=\"background: url('../images/wait.gif') no-repeat;z-index:3;position:relative;top:100px;left:300px;height:100px;width:100px;\">&nbsp;</div>");} ,
   		success: function(json)
			{ 
				$("#overzichtContent").hide().html(json.html).stop(true,true).fadeIn();
				$("#paginering .link_actief").removeClass("link_actief").addClass("link");
				$("#paginering > a[title=1]").removeClass("link").addClass("link_actief");
				initiateButtonPaginering();
				
				if(productWeergave=='lijst')
					$("#lijst").click();
				
				
				if(getInternetExplorerVersion()>-1)
				{
					$(" .product .image, .product .naar_shop ").css("cursor","pointer").click(function(){
						window.open($(this).siblings("a").attr("href"));
					});
				}
			}
		});
}

function movePage()
{	
	($(this).attr("title")=='') ? ($(this).parents().attr("id")=='vorige') ? paramJSON['active']-- : paramJSON['active']++ : paramJSON['active'] = $(this).attr("title");
	
	//alert(paramJSON['active']);
	$.ajax({
   		type: "POST",
   		url: "ajax.php?url=http://www.%systemdomain%/php/ajax/ajax_handler.php",
   		dataType: "json",
		data: paramJSON,
   		cache: false,
   		beforeSend: function(){$("#overzichtContent").stop(true,true).html("<div style=\"background: url('../images/wait.gif') no-repeat;z-index:3;position:relative;top:100px;left:300px;height:100px;width:100px;\">&nbsp;</div>")} ,
   		success: function(json)
			{ 
				$("#overzichtContent").hide().html(json.html).stop(true,true).fadeIn();
				initiateButtonPaginering();
				
				if(productWeergave=='lijst')
					$("#lijst").click();
				
			}
		});
}


function initiateButtonPaginering()
{
	$("#paginering .link").unbind("click").click(movePage);
   	$("#volgende a").unbind("click").click(movePage);
	$("#vorige a").unbind("click").click(movePage);
	
	var lastPage = $("#paginering a:last-child").text();
	
	if(paramJSON['active'] == lastPage)
		$("#volgende a").unbind("click");
	if(paramJSON['active'] == 1)
		$("#vorige a").unbind("click");
	
	$(".product_links_midden:eq(2)").css("border-right","solid 1px white");
 	$(".product_links_midden:eq(5)").css("border-right","solid 1px white");
 	$(".product_links_midden:eq(8)").css("border-right","solid 1px white");
 	$(".product_links_midden:eq(11)").css("border-right","solid 1px white");
}

$(document).ready(function() {
	/* initiate the functions in paginering*/
    initiateButtonPaginering();
    
    /* set the behavior for filter buttons*/
   	$("#advanceFilterButton").toggle(
	function(){
   		$("#advanceFilter").stop(true,true).slideUp();
   		$("#advanceFilterButton").css("background","url('../images/plus.png') no-repeat");
   		$("#advanceFilterButton").text("Verfijn je keuze");
   		},
   	function(){
   		$("#advanceFilter").stop(true,true).slideDown();
   		$("#advanceFilterButton").css("background","url('../images/minus.png') no-repeat");
   		$("#advanceFilterButton").text("Filter opties inklappen");
   		});
	
	/* standaard bij openen pagina */
	$("#advanceFilter").stop(true,true).slideDown();
	$("#advanceFilterButton").css("background","url('../images/minus.png') no-repeat");
	$("#advanceFilterButton").text("Filter opties inklappen");
	/* einde standaard bij openen pagina */
	
	$(".filterButtons").click(filter);
	$("#leveranciersFilter").change(filter);
	$("#filterInputField").keydown(function(event) 
	{
		if (event.keyCode == '13') filter();
	});
	$('.star-rating-live').click(filter);
	$('.rating-cancel').click(filter);
	$("#clearFilter").click(filter);
 	$("#zoekImage").click(filter);
 	
 	//filter();
	//alert(paramJSON.pricemax);
});
