function add_bookmark(vehicle_id){
    $.getJSON(
            "/vehicle/bookmark",
            {'vehicle_id': vehicle_id},
            function(data){
              if (data == true){
                alert('Закладка добавлена');
              }
              else {
                alert('Такая закладка уже есть');
              }         
            }
        );	
}

function set_filter(form, a_id){
	if (a_id == null) {
		a_id = "set_filter_local";
	}
	var label = document.getElementById( a_id ).childNodes[0].nodeValue;	
	if (label == "отфильтровать"){
		document.getElementById( a_id ).childNodes[0].nodeValue="показать все";
		if (form == null) {
			form = "list_form";
		}
		$("#" + form + " :checkbox").each(function() {
			if (! this.checked){
				var id = $(this).attr("id");
				var code = id.slice(8,id.length);
				$("#tr"+code).hide();
			}
		});
	}
	else {
		document.getElementById( a_id ).childNodes[0].nodeValue="отфильтровать";
		$('tr').show();
	}
}

function add_bookmarks(){
    $("#list_form :checkbox").each(function() {
      if ( this.checked){
        var id = $(this).attr("id");
        var code = id.slice(8,id.length);
        $.getJSON(
                "/vehicle/bookmark",
                {'vehicle_id': code}
            );  
      }
    });
    alert('Закладки успешно добавлены');
}


function recount(price, money){
	if (money == 'RUR'){
		$('#eur').show();
		$('#usd').show();
		$('#rur').hide();
		$('#cprice').html('<strong>Цена: </strong><b>'+price+'</b> рублей');
	}
	if (money == 'USD'){
		$('#eur').show();
		$('#usd').hide();
		$('#rur').show();
		
		$.getJSON(
				"/vehicle/newprice/",
				{'price': price, 'money': money},
				function(data){
					$('#cprice').html('<strong>Цена: </strong><b>'+data+'</b> долларов');
				}
		);		
	}
	if (money == 'EUR'){
		$('#eur').hide();
		$('#usd').show();
		$('#rur').show();
		$.getJSON(
				"/vehicle/newprice/",
				{'price': price, 'money': money},
				function(data){
					$('#cprice').html('<strong>Цена: </strong><b>'+data+'</b> евро');
				}
		);		
	}	
	
}

// индекс последнего выбранного изображения авто (нужно для fancybox-a)
var vehicleImageIndex = 0;

function show_images(index) {
    big0 = $('#big_image').attr('src');	
    small0 = $('#small_image_' + index).attr('src');
    big = small0.replace('thumbs/small', 'thumbs/big');

    $('#big_image').attr('src', big);
    for (i = 0; i < 7; i++){
    	$('#image_link_' + i).removeClass('selected_image');
    }

    $('#image_link_' + index).addClass('selected_image');
    link = big.replace('thumbs/big', 'finish');
    $('#big_image_preview').attr('src', link);
    
    vehicleImageIndex = index;

    return false;
}

