$(document).ready(function() {
	
	
	/* -----  Preload CSS images via http://www.filamentgroup.com/lab/update_automatically_preload_images_from_css_with_jquery/   ----- */
	 //$.preloadCssImages();
	
	/* -----  Start select replacment based on http://plugins.jquery.com/project/jquery-sb   ----- */
	$(".s_content select").sb();
	
	$("#choose_state2 select").sb();
	$("select.val").sb({
		selectboxClass: 'selectbox1'
				       
	}
	);
	
	
	
	$(".fancy").fancybox();
	$(".product-photo a").fancybox();
	
	
	
	$(".thumbs-area").cycle({
        fx:      'scrollHorz',
        timeout:  0,
        prev:    '#prev',
        next:    '#next'
        });
	
	var ileile2 = $(".thumbs-area .thumb-pack ul  li > a").length;
	$(".countus b").html(ileile2);
	
	$(".thumbs-area .thumb-pack ul li a").click(function() {
	var ileile = $(".thumbs-area .thumb-pack ul  li > a").index(this);
	var ileile2 = $(".thumbs-area .thumb-pack ul  li > a").length;
	var ileile1 = ileile+1
	$(".countus em").html(ileile1);
	$(".countus b").html(ileile2);
	$(".thumbs-area .thumb-pack ul li a img").removeClass('active');
	$(this).children('img').addClass('active');
	$(".product-photo a").hide();
	$(".product-photo > a").eq(ileile).show();

	});
	
	var iletych = $(".thumbs-area > .thumb-pack").length;
		var iletam = iletych - 1;
		var ileindex = iletych + 1;
	
	if ($(".thumbs-area .thumb-pack").eq(0).css('z-index') == (ileindex))
		{
			$("#prev").hide();
			$("#prev-off").show();
		}
		else {
			$("#prev").show();
			$("#prev-off").hide();
		}
		
	
       $(".navi-btn").click(function() {
		

		if ($(".thumbs-area .thumb-pack").eq(0).css('z-index') == (ileindex))
		{
			$("#prev").hide();
			$("#prev-off").show();
		}
		else {
			$("#prev").show();
			$("#prev-off").hide();
		}
	
	
		if ($(".thumbs-area .thumb-pack").eq(iletam).css('z-index') == (ileindex))
		{
			$("#next").hide();
			$("#next-off").show();
		}
		else {
			$("#next").show();
			$("#next-off").hide();
		}			
	});



	
	$('.cvp_menu li a').click(function() {
		$('.cvp_menu li').removeClass('active');
		$(this).parent().addClass('active');
		$('.cvp_bg').hide();
		var tabname = $(this).attr('rel');
		$(tabname).show();
	});

	$("#filtr").change(function() {
	    $("#form_car_list").submit();
	});

	$("#filtr2").change(function() {
	    $("#form_car_list").submit();
	})

	
});



