var bol_select_scroll = false;
var current_select = null;
var radio_selected = -1;
var silver_checkbox_checked;
var front_checked;

var large_select = [];
	large_select['name'] = "large_select";
	large_select['width'] = 150;
	large_select['height'] = 28;
	large_select['padding'] = new Array(0, 0, 0, 15);
	large_select['imgs'] = new Array("/files/images/layout/search_select_bg_w150.png", "/files/images/layout/search_select_bg_w150_hover.png", "/files/images/layout/search_select_bg_w150.png"); // default, hover, click
	large_select['options_bg'] = "";
	large_select['options_border_size'] = 1;
	large_select['options_border_color'] = "#555"; // always solid
	large_select['options_padding'] = new Array(0, 20, 0, 0);
	large_select['option_bg'] = new Array("#000", "#333", "#000"); // default, hover, click
	large_select['option_text_color'] = new Array("#fff", "#f00", "#fff"); // default, hover, click
	large_select['selected_option_bg'] = new Array("#333", "#555", "#333"); // default, hover, click
	large_select['option_border_size'] = 0;
	large_select['option_border_color'] = ""; // always solid
	large_select['option_height'] = 20;
	large_select['option_line_height'] = large_select['option_height'];
	large_select['option_padding'] = new Array(2, 0, 2, 15);
	large_select['show_time'] = 200;
	large_select['hide_time'] = 500;
	large_select['hide_delay_time'] = 500;
	large_select['max_options'] = 10;
	large_select['onclick_function'] = "do_selection";

var large_silver_select = [];
	large_silver_select['name'] = "large_silver_select";
	large_silver_select['width'] = 180;
	large_silver_select['height'] = 29;
	large_silver_select['padding'] = new Array(0, 0, 0, 15);
	large_silver_select['imgs'] = new Array("/files/images/layout/search_silver_select_bg_w180.png", "/files/images/layout/search_silver_select_bg_w180_hover.png", "/files/images/layout/search_silver_select_bg_w180.png"); // default, hover, click
	large_silver_select['options_bg'] = "";
	large_silver_select['options_border_size'] = 1;
	large_silver_select['options_border_color'] = "#bfbfbf"; // always solid
	large_silver_select['options_padding'] = new Array(0, 0, 0, 0);
	large_silver_select['option_bg'] = new Array("#ccc", "#999", "#ccc"); // default, hover, click
	large_silver_select['option_text_color'] = new Array("#fff", "#f00", "#fff"); // default, hover, click
	large_silver_select['selected_option_bg'] = new Array("#999", "#777", "#999"); // default, hover, click
	large_silver_select['option_border_size'] = 0;
	large_silver_select['option_border_color'] = ""; // always solid
	large_silver_select['option_height'] = 20;
	large_silver_select['option_line_height'] = large_silver_select['option_height'];
	large_silver_select['option_padding'] = new Array(2, 0, 2, 15);
	large_silver_select['show_time'] = 200;
	large_silver_select['hide_time'] = 500;
	large_silver_select['hide_delay_time'] = 500;
	large_silver_select['max_options'] = 10;

var small_silver_select = [];
	small_silver_select['name'] = "small_silver_select";
	small_silver_select['width'] = 87;
	small_silver_select['height'] = 29;
	small_silver_select['padding'] = new Array(0, 0, 0, 10);
	small_silver_select['imgs'] = new Array("/files/images/layout/search_silver_select_bg_w87.png", "/files/images/layout/search_silver_select_bg_w87_hover.png", "/files/images/layout/search_silver_select_bg_w87.png"); // default, hover, click
	small_silver_select['options_bg'] = "";
	small_silver_select['options_border_size'] = 1;
	small_silver_select['options_border_color'] = "#bfbfbf"; // always solid
	small_silver_select['options_padding'] = new Array(0, 0, 0, 0);
	small_silver_select['option_bg'] = new Array("#ccc", "#999", "#ccc"); // default, hover, click
	small_silver_select['option_text_color'] = new Array("#fff", "#f00", "#fff"); // default, hover, click
	small_silver_select['selected_option_bg'] = new Array("#999", "#777", "#999"); // default, hover, click
	small_silver_select['option_border_size'] = 0;
	small_silver_select['option_border_color'] = ""; // always solid
	small_silver_select['option_height'] = 20;
	small_silver_select['option_line_height'] = small_silver_select['option_height'];
	small_silver_select['option_padding'] = new Array(2, 0, 2, 10);
	small_silver_select['show_time'] = 200;
	small_silver_select['hide_time']= 500;
	small_silver_select['hide_delay_time'] = 500;
	small_silver_select['max_options'] = 10;

var tiny_silver_select = [];
	tiny_silver_select['name'] = "tiny_silver_select";
	tiny_silver_select['width'] = 40;
	tiny_silver_select['height'] = 21;
	tiny_silver_select['padding'] = new Array(0, 0, 0, 5);
	tiny_silver_select['imgs'] = new Array("/files/images/layout/search_silver_select_bg_w40.png", "/files/images/layout/search_silver_select_bg_w40_hover.png", "/files/images/layout/search_silver_select_bg_w40.png"); // default, hover, click
	tiny_silver_select['options_bg'] = "";
	tiny_silver_select['options_border_size'] = 1;
	tiny_silver_select['options_border_color'] = "#bfbfbf"; // always solid
	tiny_silver_select['options_padding'] = new Array(0, 0, 0, 0);
	tiny_silver_select['option_bg'] = new Array("#ccc", "#999", "#ccc"); // default, hover, click
	tiny_silver_select['option_text_color'] = new Array("#fff", "#f00", "#fff"); // default, hover, click
	tiny_silver_select['selected_option_bg'] = new Array("#999", "#777", "#999"); // default, hover, click
	tiny_silver_select['option_border_size'] = 0;
	tiny_silver_select['option_border_color'] = ""; // always solid
	tiny_silver_select['option_height'] = 20;
	tiny_silver_select['option_line_height'] = tiny_silver_select['option_height'];
	tiny_silver_select['option_padding'] = new Array(2, 0, 2, 5);
	tiny_silver_select['show_time'] = 200;
	tiny_silver_select['hide_time'] = 500;
	tiny_silver_select['hide_delay_time'] = 500;
	tiny_silver_select['max_options'] = 100;

var small_select = [];
	small_select['name'] = "small_select";
	small_select['width'] = 72;
	small_select['height'] = 28;
	small_select['padding'] = new Array(0, 0, 0, 8);
	small_select['imgs'] = new Array("/files/images/layout/search_select_bg_w72.png", "/files/images/layout/search_select_bg_w72_hover.png", "/files/images/layout/search_select_bg_w72.png"); // default, hover, click
	small_select['options_bg'] = "";
	small_select['options_border_size'] = 1;
	small_select['options_border_color'] = "#555"; // always solid
	small_select['options_padding'] = new Array(0, 0, 0, 0);
	small_select['option_bg'] = new Array("#000", "#333", "#000"); // default, hover, click
	small_select['option_text_color']= new Array("#fff", "#f00", "#fff"); // default, hover, click
	small_select['selected_option_bg'] = new Array("#333", "#555", "#333"); // default, hover, click
	small_select['option_border_size'] = 0;
	small_select['option_border_color'] = ""; // always solid
	small_select['option_height'] = 20;
	small_select['option_line_height'] = small_select['option_height'];
	small_select['option_padding'] = new Array(2, 0, 2, 8);
	small_select['show_time'] = large_select['show_time'];
	small_select['hide_time'] = large_select['hide_time'];
	small_select['hide_delay_time'] = large_select['hide_delay_time'];
	small_select['max_options'] = 11;

// Preload all images
var preload = [];
preload.concat(large_select['imgs']);
preload.concat(small_select['imgs']);
preload.concat(large_silver_select['imgs']);
preload.concat(small_silver_select['imgs']);
preload.concat(tiny_silver_select['imgs']);
if(document.images){
	for(var preload_j = 0; preload_j < preload.length; preload_j++){
		var img = new Image();
		img.src = preload[preload_j];
	}
}
var silver_checkbox_checked = false;
function close_popup(){
	$("#overlay_con").animate({
			"opacity" : 0
		}, 500,	function(){}
	);
	$("#overlay_bg").animate({
			"opacity" : 0
		}, 500,	function(){
			$("#overlay_bg").css("display", "none");
			$("#overlay_con").css("display", "none");
		}
	);
}
function handle_quicksearch(data){
	var html = "";
	var counter = 0;
	var count_cars = 0;
	$("#search_suggestions").css("display", "block");
	if(data.length != 0){
		$.each(data, function(key, value){
			if(counter < 8){
				html += '<div class="result_item" rel="'+value.car_manufacture+':'+value.car_model+':'+value.engine_volume+':'+value.model_variant+'" style="padding: 0 3px; background-color: #fff; color: #333;">';
					html += '<div style="padding: 3px 0;min-height: 16px;line-height: 16px;"> '+ value.car_manufacture +' '+ value.car_model +' '+ value.engine_volume +' '+ value.model_variant +' ('+value.count+')</div>';
				html += '</div>';
			}
			count_cars += (value.count * 1);
			counter++;
		});
	}
	$("#search_suggestions #results_con").html(html);
		$(".result_item").bind({
			click : function(e){
				e.preventDefault();
				var rel_split = $(this).attr("rel").split(":");
				$("#ff_maerke").val(rel_split[0]);
				$("#ff_model").val(rel_split[1]);
				$("#ff_engine_volume").val(rel_split[2]);
				$("#ff_variant").val(rel_split[3]);
				var s = make_search_string();
				window.location = "/list?s=" + s;
			},
			mouseenter : function(){
				$(this).css({"cursor": "pointer", "background-color": "#ccc"});
			},
			mouseleave : function(){
				$(this).css({"background-color": "#fff"});
			}
		});
	if(data.length > 1){
		$("#search_suggestions #results_count").html(count_cars + ' resultater - <a href="#" id="view_all_qs_results" style="color: #fff; text-decoration: underline;">Se alle resultater</a>');
		$("#view_all_qs_results").bind({
			click : function(e){
				e.preventDefault();
				var s = make_search_string();
				window.location = "/list?s=" + s;
			}
		});
	} else {
		$("#search_suggestions #results_count").text(count_cars + " resultater");
	}
	$("html").bind("click", function(){
		$("#search_suggestions").css({
			display: "none"
		});
		$("html").unbind();
	});
}

$(window).load( function() {
    if(window.addEventListener) {
        document.addEventListener('DOMMouseScroll', pageScroll, false);
    }
    document.onmousewheel = pageScroll;
});

function pageScroll(event) {
	if (bol_select_scroll) {
		var delta = 0;
	    if (!event) event = window.event;
	    if (event.wheelDelta) {
	        delta = event.wheelDelta / 60;
	    } else if (event.detail) {
	        delta = -event.detail / 2;
	    }
	    if (!current_select.attr("rel")) {
	    	current_select.attr("rel", 0);
	    }
	    if (current_select.attr("rel")*1 < 0) {
	    	current_select.attr("rel", 0);
	    }
	    if (current_select.attr("rel")*1 > (current_select.find(".option").length*37)-current_select.height()) {
	    	current_select.attr("rel", (current_select.find(".option").length*37)-current_select.height());
	    }
	    if (delta > 0) {
	    	current_select.attr("rel", (current_select.attr("rel")*1)-37);
			current_select.stop(true, false).animate({scrollTop: current_select.attr("rel")}, 300);
		} else {
			current_select.attr("rel", (current_select.attr("rel")*1)+37);
			current_select.stop(true, false).animate({scrollTop: current_select.attr("rel")}, 300);
		}
    }

    return !bol_select_scroll;
}

$(document).ready(function(){
	$("#ff_type").siblings(".value").removeClass("disabled"); // -------------------------------------------------------- dev thingy d. 03-02-2012
	
	$(".search_reset").bind({
		click : function(e){
			e.preventDefault();
			var type = $(this).attr("rel");
			reset_search(type);
		}
	});
	$(".minebiler_remove_from_list").bind({
		click : function(e){
			e.preventDefault();
			remove_car($(this).attr("rel"));
		}
	});
	$(".minebiler_add_to_agent").bind({
		click : function(e){
			e.preventDefault();
			add_to_agent($(this).attr("rel"));
		}
	});
	$("#form_quick_search").submit(function(e){
		e.preventDefault();
		var s = make_search_string();
		window.location = "/list?s=" + s;
	});
	$("#product_list_con .headings_con a").bind({
		click : function(e){
			e.preventDefault();
			var this_rel = $(this).attr("rel");
			this_rel = this_rel.split(":");
			var order = this_rel[0];
			var order_dir = this_rel[1];
			switch(order){
				case "price" :
					order = "detailprice";
					break;
				case "manufacture" :
					order = "car_manufacture,car_model,model_variant";
					break;
				case "year" :
					order = "model_year";
					break;
				case "distance" :
					order = "driven_distance_per_1000";
					break;
				default:
					order = ((getParameterByName("s")!="" && getParameterByName("s") != undefined)?'car_manufacture,car_model,model_variant':'detailprice');
					break;
			}
			var new_rel = "";
			if(order_dir == "asc"){
				new_rel = this_rel[0] + ":desc";
			} else {
				new_rel = this_rel[0] + ":asc";
			}
			$(this).attr("rel", new_rel);
			if(this_rel[0] == "manufacture"){
				$("#product_list_con .headings_con a").parent().removeClass("sort_selected");
				$(this).parent().parent().addClass("sort_selected");
			} else {
				$("#product_list_con .headings_con a").parent().removeClass("sort_selected");
				$("#product_list_con .headings_con a").parent().parent().removeClass("sort_selected");
				$(this).parent().addClass("sort_selected");
			}
			populate_list(false, 0, $("#ff_grid_antal").val(), order, order_dir);
			make_paging("1", $("#ff_grid_antal").val(), $(".car_count_list").attr("rel"), order, order_dir);
		}
	});
	$("#product_grid_con .headings_con a").bind({
		click : function(e){
			e.preventDefault();
			var this_rel = $(this).attr("rel");
			this_rel = this_rel.split(":");
			var order = this_rel[0];
			var order_dir = this_rel[1];
			switch(order){
				case "price" :
					order = "detailprice";
					break;
				case "manufacture" :
					order = "car_manufacture,car_model,model_variant";
					break;
				case "year" :
					order = "model_year";
					break;
				case "distance" :
					order = "driven_distance_per_1000";
					break;
				default:
					order = ((getParameterByName("s")!="" && getParameterByName("s") != undefined)?'car_manufacture,car_model,model_variant':'detailprice');
					break;
			}
			var new_rel = "";
			if(order_dir == "asc"){
				new_rel = this_rel[0] + ":desc";
			} else {
				new_rel = this_rel[0] + ":asc";
			}
			$(this).attr("rel", new_rel);
			$("#product_grid_con .headings_con a").removeClass("sort_selected");
			$(this).addClass("sort_selected");
			
			populate_list(false, 0, $("#ff_grid_antal").val(), order, order_dir);
			make_paging("1", $("#ff_grid_antal").val(), $(".car_count_list").attr("rel"), order, order_dir);
		}
	});
	$("#footer_tilmeld_submit").bind({
		click : function(e){
			e.preventDefault();
			var email = $("#footer_tilmeld_ff").val();
			var link = "/starmark/tilmeld_nyhedsbrev";
			if(email != "Indtast din e-mail" && email != ""){
				link += "?email=" + email;
			}
			window.location = link;
		}
	});
	$("#ff_search").keyup(function(){
		if($(this).val().length > 1){
			$.ajax({
				dataType:"jsonp",
				url:"http://mycar.accedo.dk/search/quick_search/typeahead/633/key:4752363d1f11340ba8f844cf082c46ec/results:handle_quicksearch/string:"+ $(this).val() +"/"
			});
		}
	});
	

	if ($(".print_list_btn").length != 0) {
		$(".print_list_btn").bind({
			click : function (){
				$("#product_list_con").printElement({
					printBodyOptions:{
						styleToAdd:'display:block;',
						classNameToAdd : 'print_body'
					},
					pageTitle:'STARMARK bils&oslash;gning'
				});
			}
		});
	}

	if ($(".print_grid_btn").length != 0) {
		$(".print_grid_btn").bind({
			click : function (){
				$("#product_grid_con").printElement({
					printBodyOptions:{
						styleToAdd:'display:block;',
						classNameToAdd : 'print_body'
					},
					pageTitle:'STARMARK bils&oslash;gning'
				});
			}
		});
	}
	$(".blue_btn_con").bind({
		click : function(e){
			e.preventDefault();
			var this_rel = $(this).attr("rel");
			if(this_rel.search("kontakt_starmark_") != -1){
				var sted = this_rel.split("_");
				window.location = "/starmark/afdelinger/"+sted[2]+".htm";
			} else if(this_rel == "bestil"){
				validate_bestilling();
			}
		},
		mouseenter : function(){
			$(this).children(".left").css({"background-image": "url(/files/images/layout/blue_btn_left_bg_hover.png)"});
			$(this).children(".mid").css({"background-image": "url(/files/images/layout/blue_btn_mid_rep_hover.png)"});
			$(this).children(".right").css({"background-image": "url(/files/images/layout/blue_btn_right_bg_hover.png)"});
		},
		mouseleave : function(){
			$(this).children(".left").css({"background-image": "url(/files/images/layout/blue_btn_left_bg.png)"});
			$(this).children(".mid").css({"background-image": "url(/files/images/layout/blue_btn_mid_rep.png)"});
			$(this).children(".right").css({"background-image": "url(/files/images/layout/blue_btn_right_bg.png)"});
		}
	});
	
	if ($(".do_order_popup").length != 0) {
		$(".do_order_popup").bind({
			click : function(e){
				e.preventDefault();
				$("#overlay_con").css({height: ($(".overlay_con_inner .proevetur_description").height() + 295) + 'px',width: '350px'});
				$(".overlay_con_inner").css({padding: "20px", height : ($("#overlay_con").height() - 40 - 4)});
				$("#overlay_bg").css({"opacity": 0, "display": "block", height : $(document).height()});
				$("#overlay_con").css({"opacity": 0, "display": "block", top : (($(window).height() / 2) - ($("#overlay_con").height() / 2)) + "px", left : (($(window).width() / 2) - ($("#overlay_con").width() / 2)) + "px"});
				$.scrollTo( $("#site_con"), 800);
				$("#overlay_bg").animate({
						"opacity" : .45
					}, 500,	function(){
						$(".overlay_con_inner").css({"display": "block"});
						$("#overlay_con").animate({
								"opacity" : 1
							}, 500,	function(){
								$(".close_btn a").bind({
									click : function(){
										close_popup();
									}
								});
							}
						);
					}
				);
				$("#overlay_bg").bind({
					click : function(){
						close_popup();
					}
				});
				$("#overlay_close").bind({
					click : function(){
						close_popup();
					}
				});
			}
		});
	}
	
	var more_details_shown = false;
	var knap_tekst = $(".product_facts .more_details a").text();
	var knap_tekst_rel = $(".product_facts .more_details a").attr("rel");
	var first_facts_height = $(".product_facts").outerHeight();
	$(".product_facts .more_details a").bind({
		click : function(e){
			e.preventDefault();
			var more_height = $(".product_facts .product_facts_more").outerHeight();
			if(more_details_shown == false){
				$(".product_facts .product_facts_more").css({"display": "block", opacity: 0});
				$(".product_facts .more_details a").text(knap_tekst_rel);
				$(".product_facts .product_facts_more").animate({
						opacity : 1
					},1200,function(){
						$(this).css('filter','');
					}
				);
				$(".product_facts").animate({
						height : (first_facts_height + more_height) + "px"
					},1200,function(){}
				);
				more_details_shown = true;
			} else {
				$(".product_facts .product_facts_more").css({"display": "block", opacity: 1});
				$(".product_facts .more_details a").text(knap_tekst);
				$(".product_facts .product_facts_more").animate({
						opacity : 0
					},1200,function(){
						$(this).css('filter','');
						//$(".product_facts .product_facts_more").css("display", "none");
					}
				);
				$(".product_facts").animate({
						height : first_facts_height
					},1200,function(){}
				);
				more_details_shown = false;
			}
		}
	});
	
	$("#advanced_search").submit(function(e){
		e.preventDefault();
		var s = make_search_string();
		window.location = "/list?s=" + s;
	});	

	var adv_search_con_expanded = 0,
		site_search_con_inner_height = $("#site_search_con_inner").outerHeight(),
		expand_time = 1000;
	$(".search_collection_border:eq(0)").css("display", "block");
	$("#show_hide_adv_search_btn").bind("click", function(event){
		event.preventDefault();
		if(adv_search_con_expanded == 0){
			$("#site_search_con_inner").css("overflow","hidden");
			$(".search_collection_border").css("display", "block");
			$("#site_search_con_inner").animate({
				height: "660px"
			}, expand_time, function(){
				adv_search_con_expanded = 1;
			$("#site_search_con_inner").css("overflow","visible");
			});
			$("#show_hide_adv_search_btn span.adv_text").hide(500);
			$("#show_hide_adv_search_btn span.simpel_text").show(500).css("overflow", "visible");
		} else {
			$("#site_search_con_inner").css("overflow","hidden");
			$("#site_search_con_inner").animate({
				height: site_search_con_inner_height + "px"
			}, expand_time, function(){
				adv_search_con_expanded = 0;
			});
			$("#show_hide_adv_search_btn span.adv_text").show(500).css("overflow", "visible");
			$("#show_hide_adv_search_btn span.simpel_text").hide(500);
			var hide = setTimeout(function(){$(".search_collection_border").not(":eq(0)").css("display", "none");}, expand_time + 50);
			hide = setTimeout(function(){$("#site_search_con_inner").css("overflow","visible");}, expand_time + 50);
		}
	});
	
	var b = $.browser,
		b_version = b.version.slice(0,1);
		
	$(".accedo_select").each(function(select_idx){
		var options_shown = 0;
		
		$(this).children(".options").css({"opacity": "0",visibility: "hidden", "height": "0px", "z-index": "1","overflowY": "auto!important", "border": "1px solid red"});
		var options_count = $(this).children(".options").children(".option").length;
		
		if($(this).hasClass("large")){
			make_select($(this), large_select, options_count, options_shown);
		} else if($(this).hasClass("small")){
			make_select($(this), small_select, options_count, options_shown);
		} else if($(this).hasClass("large_silver")){
			make_select($(this), large_silver_select, options_count, options_shown);
		} else if($(this).hasClass("small_silver")){
			make_select($(this), small_silver_select, options_count, options_shown);
		} else if($(this).hasClass("tiny_silver")){
			make_select($(this), tiny_silver_select, options_count, options_shown);
		}
	});
	
	$(".accedo_radio_group").each(function(radio_group_idx){
		if($(this).hasClass("front_radio")){
			//var radio_selected = -1;
			$(this).children(".accedo_radio").each(function(radio_idx){
				$(this).bind({
					click : function(){
						if(radio_idx != radio_selected){
							radio_selected = radio_idx;
							$(this).siblings(".accedo_radio").css("background", "url(/files/images/layout/icon_radiobtn_front.png) left center no-repeat");
							$(this).css("background", "url(/files/images/layout/icon_radiobtn_front_selected.png) left center no-repeat");
							$(this).siblings("input").val($(this).attr("rel"));
						} else {
							radio_selected = -1;
							$(this).siblings(".accedo_radio").css("background", "url(/files/images/layout/icon_radiobtn_front.png) left center no-repeat");
							$(this).css({"background": "url(/files/images/layout/icon_radiobtn_front_hover.png) left center no-repeat"});
							$(this).siblings("input").val("");
						}
						
						do_selection($(this).siblings("input").attr("id"),$(this).attr("rel"));
						make_search_string();
						
					},
					mouseenter : function(){
						if(radio_idx != radio_selected){
							$(this).css({
								"background": "url(/files/images/layout/icon_radiobtn_front_hover.png) left center no-repeat"
							});
						}
					},
					mouseleave : function(){
						if(radio_idx != radio_selected){
							$(this).css({
								"background": "url(/files/images/layout/icon_radiobtn_front.png) left center no-repeat"
							});
						}
					}
				});
			});
		} else if($(this).hasClass("silver_radio")){
			//var radio_selected = -1;
			$(this).children(".accedo_radio").each(function(radio_idx){
				$(this).bind({
					click : function(){
						if(radio_idx != radio_selected){
							radio_selected = radio_idx;
							$(this).siblings(".accedo_radio").css("background", "url(/files/images/layout/icon_radiobtn_silver.png) left center no-repeat");
							$(this).css("background", "url(/files/images/layout/icon_radiobtn_silver_selected.png) left center no-repeat");
							$(this).siblings("input").val($(this).attr("rel"));
						} else {
							radio_selected = -1;
							$(this).siblings(".accedo_radio").css("background", "url(/files/images/layout/icon_radiobtn_front.png) left center no-repeat");
							$(this).css({"background": "url(/files/images/layout/icon_radiobtn_front_hover.png) left center no-repeat"});
							$(this).siblings("input").val("");
						 }
						 
						 do_selection($(this).siblings("input").attr("id"),$(this).attr("rel"));
						 make_search_string();
						
					},
					mouseenter : function(){
						if(radio_idx != radio_selected){
							$(this).css({
								"background": "url(/files/images/layout/icon_radiobtn_silver_hover.png) left center no-repeat"
							});
						}
					},
					mouseleave : function(){
						if(radio_idx != radio_selected){
							$(this).css({
								"background": "url(/files/images/layout/icon_radiobtn_silver.png) left center no-repeat"
							});
						}
					}
				});
			});
		}
	});
	$(".accedo_checkbox_group").each(function(chk_group_idx){
			$(this).children(".accedo_checkbox").each(function(chk_idx){
				if($(this).hasClass("silver_checkbox")){
					if($(this).css("background-image") == "/files/images/layout/silver_checkbox_checked.png"){
						silver_checkbox_checked = true;
					} else {
						silver_checkbox_checked = false;
					}
					$(this).bind({
						click : function(){
							//$(this).siblings(".accedo_checkbox").css("background", "url(/files/images/layout/icon_checkbox_front.png) left center no-repeat");
							if(silver_checkbox_checked == false){
								$(this).css("background", "url(/files/images/layout/silver_checkbox_checked.png) left center no-repeat");
								$(this).siblings("input").val("true");
								silver_checkbox_checked = true;
							} else {
								$(this).css("background", "url(/files/images/layout/silver_checkbox.png) left center no-repeat");
								$(this).siblings("input").val("false");
								silver_checkbox_checked = false;
							}
							do_selection($(this).siblings("input").attr("id"),$(this).siblings("input").val());
							make_search_string();
						},
						mouseenter : function(){
							//if(checked == false){
							//	$(this).css({"background": "url(/files/images/layout/icon_checkbox_front_hover.png) left center no-repeat"});
							//}
						},
						mouseleave : function(){
							if(silver_checkbox_checked == false){
								$(this).css({"background": "url(/files/images/layout/silver_checkbox.png) left center no-repeat"});
							}
						}
					});
				} else {
					front_checked = false;
					$(this).bind({
						click : function(){
							//$(this).siblings(".accedo_checkbox").css("background", "url(/files/images/layout/icon_checkbox_front.png) left center no-repeat");
							if(front_checked == false){
								$(this).css("background", "url(/files/images/layout/icon_checkbox_front_selected.png) left center no-repeat");
								$(this).siblings("input").val("true");
								front_checked = true;
							} else {
								$(this).css("background", "url(/files/images/layout/icon_checkbox_front.png) left center no-repeat");
								$(this).siblings("input").val("false");
								front_checked = false;
							}
							do_selection($(this).siblings("input").attr("id"),$(this).siblings("input").val());
							make_search_string();
						},
						mouseenter : function(){
							//if(front_checked == false){
							//	$(this).css({"background": "url(/files/images/layout/icon_checkbox_front_hover.png) left center no-repeat"});
							//}
						},
						mouseleave : function(){
							if(front_checked == false){
								$(this).css({"background": "url(/files/images/layout/icon_checkbox_front.png) left center no-repeat"});
							}
						}
					});
				}
		});
	});
});
function make_select(this_select, a, options_count, options_shown){
			var to_height = 0,
				srcoll_width = 0;
			this_select.css({
				position:"relative",
				background: "url(" + a['imgs'][0] + ") left top no-repeat"
			});
			
				this_select.bind({
					click: function(event) {
						if(!this_select.children(".value").hasClass("disabled")){
							$(".options").css({
								opacity: 0,
								height: "0px",
								visibility: "hidden",
								"z-index": "1"
							});
							event.stopPropagation(); // disable the html.click(outside click) function
							
							if(options_shown == 1){
								this_select.children(".options").css({
									opacity: 0,
									height: "0px",
									visibility: "hidden",
									"z-index": "1"
								});
								
								this_select.find(".option").css({
									"z-index": "0"
								});
								
								this_select.parent().css({
									"z-index": "0"
								});
								
								this_select.parent().parent().css({
									"z-index": "0"
								});
								
								this_select.parent().parent().parent().css({
									"z-index": "0"
								});
								
								options_shown = 0;
							} else {
								$(".accedo_select, .option, .adv_search_formfield_con, .small_select").css({
									"z-index": "0"
								});
								
								this_select.children(".options").css({
									visibility: "visible",
									height: to_height + "px",
									"z-index": "100",
									position: "absolute",
									top: "0px",
									"margin-top": a['height'] + "px", // Position fix
									left: "0px",
									"overflowY" : "auto",
									border : (a['options_border_size'] != 0 ?  a['options_border_size'] + "px solid " + a['options_border_color'] : "none")
								});
								
								this_select.find(".option").css({
									"z-index": "101"
								});
								
								this_select.parent().css({
									"z-index": "101"
								});
								
								this_select.parent().parent().css({
									"z-index": "100"
								});
								
								this_select.parent().parent().parent().css({
									"z-index": "99"
								});
								
								options_shown = 1;
								
								$("html, body").bind("click", function(){
									$(".options").css({
										opacity: 0,
										height: "0px",
										visibility: "hidden",
										"z-index": "1",
										"overflowY": "auto"
									});
									
									$(".accedo_select, .option, .adv_search_formfield_con, .small_select").css({
										"z-index": "0"
									});
									
									$("html, body").bind();
									options_shown = 0;
								});
							}
							
							this_select.children(".options").mouseenter( function() {
								bol_select_scroll = true;
								current_select = this_select.children(".options");
							}).mouseleave( function() {
								bol_select_scroll = false;
								current_select = false;
							});
							
							this_select.children(".options").children(".option").each(function(option_idx){
								$(this).parent().css("overflowY", "auto");
								$(this).parent().stop(true).animate({
									opacity: 1,
									height: to_height + "px"
								}, a['show_time'], function(){
									$(this).css("overflowY", "auto");
								});
								$(this).unbind("click");
								$(this).bind({
									click: function(e) {
										e.stopPropagation();
										$(this).parent().siblings(".value").text($(this).text());
										$(this).parent().siblings("input").val($(this).attr("rel"));
										$(this).parent().css({
											opacity: 0,
											height: "0px",
											visibility: "hidden",
											"z-index": "1"
										});
										if(a['name'] == "tiny_silver_select"){
											do_selection_list_perpage(0, $(this).text());
										} else {
											do_selection($(this).parent().siblings("input").attr("id"), $(this).text());
										}
										make_search_string();
										options_shown = 0;
									},
									mouseenter: function() {
										$(this).css({
											"padding" : a['option_padding'][0] + "px " + a['option_padding'][1] + "px " + a['option_padding'][2] + "px " + a['option_padding'][3] + "px",
											width: (a['width'] - a['option_padding'][1] - a['option_padding'][3]) + "px",
											height : a['option_height'] + "px",
											"line-height" : a['option_line_height'] + "px",
											"background-color" : ($(this).text() == $(this).parent().siblings(".value").text() ? a['selected_option_bg'][1] : a['option_bg'][1])
										});
									},
									mouseleave: function() {
										$(this).css({
											"padding" : a['option_padding'][0] + "px " + a['option_padding'][1] + "px " + a['option_padding'][2] + "px " + a['option_padding'][3] + "px",
											width: (a['width'] - a['option_padding'][1] - a['option_padding'][3]) + "px",
											height : a['option_height'] + "px",
											"line-height" : a['option_line_height'] + "px",
											"background-color" : ($(this).text() == $(this).parent().siblings(".value").text() ? a['selected_option_bg'][0] : a['option_bg'][0])
										});
									}
								});
								$(this).css({
									"padding" : a['option_padding'][0] + "px " + a['option_padding'][1] + "px " + a['option_padding'][2] + "px " + a['option_padding'][3] + "px",
									width: (a['width'] - a['option_padding'][1] - a['option_padding'][3]) + "px",
									height : a['option_height'] + "px",
									"line-height" : a['option_line_height'] + "px",
									"background-color" : ($(this).text() == $(this).parent().siblings(".value").text() ? a['selected_option_bg'][0] : a['option_bg'][0]),
									border : (a['option_border_size'] != 0 ?  a['option_border_size'] + "px solid " + a['option_border_color'] : "none")
								});
							});
						}
					},
					mouseenter: function() {
						if(!this_select.children(".value").hasClass("disabled")){
							options_count = this_select.children(".options").children(".option").length;
							to_height = (a['option_height'] + (a['option_border_size'] * 2) + a['option_padding'][0] + a['option_padding'][2]);
							if(options_count > a['max_options']){
								to_height = to_height * a['max_options'];
								scroll_width = 30;
							} else {
								to_height = to_height * options_count;
							}
								to_height = to_height + (a['options_border_size'] * 2) + a['options_padding'][0] + a['options_padding'][2];
							this_select.css({
								background: "url(" + a['imgs'][1] + ") left top no-repeat"
							});
							if(this_select.children(".options").css("opacity") != 0){
								this_select.children(".options").stop(true).animate({
									opacity: 1,
									height : to_height + "px",
									visibility: "visible",
									"overflowY" : "auto"
								}, a['show_time'], function(){
									$(this).css("overflowY", "auto");
								});
							}
						}
					},
					mouseleave: function() {
						//var this_select = this_select;
						if(options_shown == 1){
							var switch_bg = setTimeout(function(){
								this_select.css("background", "url(" + a['imgs'][0] + ") left top no-repeat");
							}, a['hide_delay_time'] + 300);
						} else {
							this_select.css("background", "url(" + a['imgs'][0] + ") left top no-repeat");
						}
						this_select.children(".options").delay(a['hide_delay_time']).animate({
							opacity: 0,
							height: "0px",
							visibility: "hidden",
							"z-index": "1"
						}, a['hide_time'], function(){
						});
						options_shown = 0;
					}
				});
}
function do_selection(select, value){
	var maerke = ($("#ff_maerke").val() != "" ? $("#ff_maerke").val() : ""),
		model = ($("#ff_model").val() != "" ? $("#ff_model").val() : ""),
		type = ($("#ff_type").val() != "" ? $("#ff_type").val() : ""),
		colors = ($("#ff_nuance").val() != "" ? $("#ff_nuance").val() : ""),
		gastype = ($("#ff_braendstof").val() != "" ? $("#ff_braendstof").val() : ""),
		geartype = ($("#ff_gear").val() != "" ? $("#ff_gear").val() : ""),
		year_from = ($("#ff_aar_fra").val() != "" ? $("#ff_aar_fra").val() : ""),
		year_to = ($("#ff_aar_til").val() != "" ? $("#ff_aar_til").val() : ""),
		distance_from = ($("#ff_km_fra").val() != "" ? $("#ff_km_fra").val() : ""),
		distance_to = ($("#ff_km_til").val() != "" ? $("#ff_km_til").val() : ""),
		price_from = ($("#ff_pris_fra").val() != "" ? $("#ff_pris_fra").val() : ""),
		price_to = ($("#ff_pris_til").val() != "" ? $("#ff_pris_til").val() : ""),
		engine_volume = ($("#ff_engine_volume").val() != "" ? $("#ff_engine_volume").val() : ""),
		model_variant = ($("#ff_model_variant").val() != "" && $("#ff_model_variant").val() != undefined ? $("#ff_model_variant").val() : ""),
		free_text = ($("#ff_search").val() == $("#ff_search").attr("rel") ? "" : $("#ff_search").val()),
		afhentningstilbud = ($("#ff_afhentningstilbud").val() != "false" ? $("#ff_afhentningstilbud").val() : "false");
	
	var arr = [];
		arr['manufacture'] = maerke;
		arr['model'] = model;
		arr['type'] = type;
		arr['colors'] = colors;
		arr['gastype'] = gastype;
		arr['geartype'] = geartype;
		//arr['grid_antal'] = grid_antal;
		arr['year_from'] = year_from;
		arr['year_to'] = year_to;
		arr['distance_from'] = distance_from;
		arr['distance_to'] = distance_to;
		arr['price_from'] = price_from;
		arr['price_to'] = price_to;
		arr['model_variant'] = model_variant;
		arr['engine_volume'] = engine_volume;
		arr['free_text'] = free_text;
		arr['afhentningstilbud'] = afhentningstilbud;
	if(select == "ff_maerke"){
		//$("#ff_model").siblings(".value").removeClass("disabled");
		if(value == "Alle"){
			if(!$("#ff_model").siblings(".value").hasClass("disabled")){
				$("#ff_model").siblings(".value").addClass("disabled");
			}
			$("#ff_model").siblings(".value").text("Vælg model");
		} else {
			$("#ff_model").siblings(".value").text("Henter...");
		}
		$("#ff_model").siblings(".options").html('<div class="option" rel="">Alle</div>');
		if(!$("#ff_type").siblings(".value").hasClass("disabled")){
			//$("#ff_type").siblings(".value").addClass("disabled");
		}
		$("#ff_type").siblings(".value").text("Vælg type");
		$("#ff_type").val("");
		get_models(value);
		get_types(value, "");
		get_years(maerke, model,type);
		get_distance(maerke, model, type);
		get_price(maerke, model, type);
		get_colors(maerke, model, type);
		get_search_car_count(arr);
	} else if(select == "ff_model"){
		var manufacture = $("#ff_maerke").val();
		//$("#ff_type").siblings(".value").removeClass("disabled");
		$("#ff_type").siblings(".value").text("Vælg type");
		$("#ff_type").val("");
		get_types(manufacture, value);
		get_years(maerke, model, type);
		get_distance(maerke, model, type);
		get_price(maerke, model, type);
		get_colors(maerke, model, type);
		get_search_car_count(arr);
	} else if(select == "ff_type"){
		get_years(maerke, model, type);
		get_distance(maerke, model, type);
		get_price(maerke, model, type);
		get_colors(maerke, model, type);
		get_search_car_count(arr);
	} else {
		get_search_car_count(arr);
	}
}
function make_search_string(){
	var maerke = ($("#ff_maerke").val() != "" ? $("#ff_maerke").val() : ""),
		model = ($("#ff_model").val() != "" ? $("#ff_model").val() : ""),
		type = ($("#ff_type").val() != "" ? $("#ff_type").val() : ""),
		model_variant = ($("#ff_variant").val() != "" ? $("#ff_variant").val() : ""),
		engine_volume = ($("#ff_engine_volume").val() != "" ? $("#ff_engine_volume").val() : ""),
		gastype = ($("#ff_braendstof").val() != "" ? $("#ff_braendstof").val() : ""),
		geartype = ($("#ff_gear").val() != "" ? $("#ff_gear").val() : ""),
		year_from = ($("#ff_aar_fra").val() != "" ? $("#ff_aar_fra").val() : ""),
		year_to = ($("#ff_aar_til").val() != "" ? $("#ff_aar_til").val() : ""),
		distance_from = ($("#ff_km_fra").val() != "" ? $("#ff_km_fra").val() : ""),
		distance_to = ($("#ff_km_til").val() != "" ? $("#ff_km_til").val() : ""),
		price_from = ($("#ff_pris_fra").val() != "" ? $("#ff_pris_fra").val() : ""),
		price_to = ($("#ff_pris_til").val() != "" ? $("#ff_pris_til").val() : ""),
		free_text = ($("#ff_search").val() == $("#ff_search").attr("rel") ? "" : $("#ff_search").val()),
		colors = ($("#ff_nuance").val() == "" ? "" : $("#ff_nuance").val()),
		afhentningstilbud = ($("#ff_afhentningstilbud").val() != "" ? $("#ff_afhentningstilbud").val() : "");
		
		var price = "";
		if(price_to != "" && price_from != ""){
			price = price_from + "-" + price_to;
		} else if(price_from != "" && price_to == ""){
			price_to = "0";
		} else if(price_from == "" && price_to != ""){
			price_from = "1";
		} else {
			price = "";
		}
		var distance = "";
		if(distance_to != "" && distance_from != ""){
			distance = distance_from + "-" + distance_to;
		} else if(distance_from != "" && distance_to == ""){
			distance_to = "0";
		} else if(distance_from == "" && distance_to != ""){
			distance_from = "1";
		} else {
			distance = "";
		}
		var year = "";
		if(year_to != "" && year_from != ""){
			year = year_from + "-" + year_to;
		} else if(year_from != "" && year_to == ""){
			year_to = "0";
		} else if(year_from == "" && year_to != ""){
			year_from = "1";
		} else {
			year = "";
		}
		
	var get_string = "maerke=" + maerke
		+ "&model=" + model
		+ "&type=" + type
		+ "&gastype=" + gastype
		+ "&geartype=" + geartype
		+ "&year_from=" + year_from
		+ "&year_to=" + year_to
		+ "&distance_from=" + distance_from
		+ "&distance_to=" + distance_to
		+ "&price_from=" + price_from
		+ "&price_to=" + price_to
		+ "&model_variant=" + model_variant
		+ "&engine_volume=" + engine_volume
		+ "&free_text=" + free_text
		+ "&colors=" + colors
		+ "&afhentningstilbud=" + afhentningstilbud;
	
	var return_value = base64_encode(get_string);
	$("#search_string").val(return_value);
	return return_value;
}
function url_b64decode(b64){
	var s = base64_decode(b64);
	var get_string_array = s.split("&");
	var virtual_get = [];
	for (var i = 0; i<get_string_array.length;i++) {
		var item = get_string_array[i].split("=");
		virtual_get[item[0]] = item[1];
	}
	return virtual_get;
}
function do_selection_list_perpage(start, amount){
	if($("#product_list_con .headings_con div.sort_selected a").length != 0){
		var sort_rel = $("#product_list_con .headings_con div.sort_selected a").attr("rel");
	} else if($("#product_grid_con .headings_con a.sort_selected").length != 0){
		var sort_rel = $("#product_grid_con .headings_con a.sort_selected").attr("rel");
	}
	//var sort_rel = $("#product_list_con .headings_con div.sort_selected a").attr("rel");
	
	if(sort_rel != ""){
		sort_rel = sort_rel.split(":");
		var order = sort_rel[0];
		var order_dir = (sort_rel[1] == "asc" ? "desc" : "asc");
		switch(order){
			case "price" :
				order = "detailprice";
				break;
			case "manufacture" :
				order = "car_manufacture,car_model,model_variant";
				break;
			case "year" :
				order = "model_year";
				break;
			case "distance" :
				order = "driven_distance_per_1000";
				break;
			default:
				order = ((getParameterByName("s")!="" && getParameterByName("s") != undefined)?'car_manufacture,car_model,model_variant':'detailprice');
				break;
		}
	} else {
		var order = 'detailprice';
		var order_dir = 'asc';
	}
	setCookie("list_antal", $("#ff_grid_antal").val());
	populate_list(false, start, amount, order, order_dir);
	make_search_string();
	make_paging("1", amount, $(".car_count_list").attr("rel"), order, order_dir);
}

function make_paging(active_page, page_amount, total_amount, order, order_dir){
	
	//console.log("Active page: " + active_page);
	//console.log("page amount: " + page_amount);
	//console.log("total amount: " + total_amount);
	//console.log("order: " + order);
	//console.log("order dir: " + order_dir);
	
	var max_antal_sider = 8; // ALTID LIGE TAL - halvdelen paa hver side af den aktive
	var antal_sider = Math.ceil(total_amount / page_amount);
	var html = '';
	if(total_amount > page_amount){
		if(active_page != "1"){
			html += '<a href="#'+((active_page * 1) - 1)+'" class="first" rel="'+((active_page * 1) - 1)+'">&laquo; Forrige</a>';
		}
		if(antal_sider > max_antal_sider){
			var start_var = (active_page * 1) - (max_antal_sider / 2);
			var first = (start_var < 1 ? 1 : start_var);
			var ny_max = first + max_antal_sider;
			if(ny_max > antal_sider){
				first = antal_sider - ((ny_max - antal_sider) + max_antal_sider);
				ny_max = antal_sider;
			}
			for(var i = first; i <= ny_max; i++){
				html += '<a href="#'+ i +'"';
				if(i == active_page){
					html += ' class="_selected"';
				}
				html += ' rel="'+i+'">'+i+'</a>';
			}
			if(ny_max != antal_sider){
				html += ' &nbsp; af<a href="#'+(antal_sider)+'" rel="'+antal_sider+'">' + antal_sider + '</a>';
			}
		} else {
			for(var i = 1; i <= antal_sider; i++){
				html += '<a href="#'+(active_page * 1 + (i-1))+'"';
				if(i == active_page){
					html += ' class="_selected"';
				}
				html += ' rel="'+i+'">'+i+'</a>';
			}
		}
		if(active_page != antal_sider){
			html += '<a href="#'+((active_page * 1) + 1)+'" rel="'+((active_page * 1) + 1)+'">N&aelig;ste &raquo;</a>';
		}
		$(".product_paging_con").html(html);
		$(".product_paging_con a").bind({
			click : function(e){
				//e.preventDefault();
				$.scrollTo( $("#site_con"), 800);
				var new_start = ($(this).attr("rel") * (page_amount)) - page_amount;
				//console.log("new_start: " + new_start);
				populate_list(false, new_start, page_amount, order, order_dir);
				$(".product_paging_con a").removeClass("_selected");
				$(this).addClass("_selected");
				make_paging($(this).attr("rel"), page_amount, total_amount, order, order_dir);
				//console.log("make_paging onclick: " + order + " - " + order_dir);
				//alert($(this).attr("rel"));
			}
		});
	}
}
function reset_search(color_scheme){
	$("#ff_maerke").val("");
	$("#ff_maerke").siblings(".value").text("Alle");
	$("#ff_model").val("");
	$("#ff_model").siblings(".value").text("Vælg model");
	$("#ff_model").siblings(".value").addClass("disabled");
	if($("#ff_type").val() != ""){
		get_types("", "");
	}
	$("#ff_type").val("");
	$("#ff_type").siblings(".value").text("Vælg type");
	$("#ff_aar_fra").val("");
	$("#ff_aar_fra").siblings(".value").text("Fra");
	$("#ff_aar_til").val("");
	$("#ff_aar_til").siblings(".value").text("Til");
	$("#ff_km_fra").val("");
	$("#ff_km_fra").siblings(".value").text("Fra");
	$("#ff_km_til").val("");
	$("#ff_km_til").siblings(".value").text("Til");
	if($("#ff_nuance")){
		$("#ff_nuance").siblings(".value").text("Alle");
	}
	$("#ff_nuance").val("");
	if($("#ff_pris_fra")){
		$("#ff_pris_fra").siblings(".value").text("Fra");
	}
	$("#ff_pris_fra").val("");
	if($("#ff_pris_til")){
		$("#ff_pris_til").siblings(".value").text("Til");
	}
	$("#ff_pris_til").val("");
	
	$("#ff_gear").val("");
	$("#ff_braendstof").val("");
	$("#ff_afhentningstilbud").val("false");
	
	if(color_scheme == "front"){
		$("#ff_search").val($("#ff_search").attr("rel"));
	} else {
		$("#ff_search").val("");
	}
	$("#ff_model_variant").val("");
	$("#ff_engine_volume").val("");
	
	silver_checkbox_checked = false;
	front_checked = false;
	radio_selected = -1;
	
	if(color_scheme == "front"){
		$("#ff_gear").siblings("div.accedo_radio").css("background-image", "url(/files/images/layout/icon_radiobtn_front.png)");
		$("#ff_braendstof").siblings("div.accedo_radio").css("background-image", "url(/files/images/layout/icon_radiobtn_front.png)");
		$("#ff_afhentningstilbud").siblings("div.accedo_checkbox").css("background-image", "url(/files/images/layout/icon_checkbox_front.png)");
	} else if(color_scheme == "subpage"){
		$("#ff_gear").siblings("div.accedo_radio").css("background-image", "url(/files/images/layout/icon_radiobtn_silver.png)");
		$("#ff_braendstof").siblings("div.accedo_radio").css("background-image", "url(/files/images/layout/icon_radiobtn_silver.png)");
		$("#ff_afhentningstilbud").siblings("div.accedo_checkbox").css("background-image", "url(/files/images/layout/silver_checkbox.png)");
	}
	
	var maerke = ($("#ff_maerke").val() != "" ? $("#ff_maerke").val() : ""),
		model = ($("#ff_model").val() != "" ? $("#ff_model").val() : ""),
		type = ($("#ff_type").val() != "" ? $("#ff_type").val() : ""),
		colors = ($("#ff_nuance").val() != "" ? $("#ff_nuance").val() : ""),
		gastype = ($("#ff_braendstof").val() != "" ? $("#ff_braendstof").val() : ""),
		geartype = ($("#ff_gear").val() != "" ? $("#ff_gear").val() : ""),
		year_from = ($("#ff_aar_fra").val() != "" ? $("#ff_aar_fra").val() : ""),
		year_to = ($("#ff_aar_til").val() != "" ? $("#ff_aar_til").val() : ""),
		distance_from = ($("#ff_km_fra").val() != "" ? $("#ff_km_fra").val() : ""),
		distance_to = ($("#ff_km_til").val() != "" ? $("#ff_km_til").val() : ""),
		price_from = ($("#ff_pris_fra").val() != "" ? $("#ff_pris_fra").val() : ""),
		price_to = ($("#ff_pris_til").val() != "" ? $("#ff_pris_til").val() : ""),
		engine_volume = ($("#ff_engine_volume").val() != "" ? $("#ff_engine_volume").val() : ""),
		model_variant = ($("#ff_model_variant").val() != "" && $("#ff_model_variant").val() != undefined ? $("#ff_model_variant").val() : ""),
		free_text = ($("#ff_search").val() == $("#ff_search").attr("rel") ? "" : $("#ff_search").val()),
		afhentningstilbud = ($("#ff_afhentningstilbud").val() != "false" ? $("#ff_afhentningstilbud").val() : "false");
	var arr = [];
		arr['manufacture'] = maerke;
		arr['model'] = model;
		arr['type'] = type;
		arr['colors'] = colors;
		arr['gastype'] = gastype;
		arr['geartype'] = geartype;
		//arr['grid_antal'] = grid_antal;
		arr['year_from'] = year_from;
		arr['year_to'] = year_to;
		arr['distance_from'] = distance_from;
		arr['distance_to'] = distance_to;
		arr['price_from'] = price_from;
		arr['price_to'] = price_to;
		arr['model_variant'] = model_variant;
		arr['engine_volume'] = engine_volume;
		arr['free_text'] = free_text;
		arr['afhentningstilbud'] = afhentningstilbud;
		
	get_search_car_count(arr);
}
