$(function () {
			var tabContainers = $('div#tabs > div');
			tabContainers.hide().filter(':first').show();

			$('div#tabs ul#toggle a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('div#tabs ul#toggle a').removeClass('selected');
				$(this).addClass('selected');
				return false;
			}).filter(':first').click();
		});

$(function(){
    $("#CarBrand").change(function(){
        $.get("/bitrix/templates/main/select.php", {id: $(this).val()},
            function(data){
                var j = jQuery.parseJSON(data);
                var options = '';
                for (var i = 0; i < j.length; i++) {
                    options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
                }
                $("#CarModel").html(options);
            }
        )
    })
});

function slideSwitch() {
    var $active = $('#menu-l IMG.active');
    if ( $active.length == 0 ) $active = $('#menu-l IMG:last');
    var $next =  $active.next().length ? $active.next()
        : $('#menu-l IMG:first');
     var $sibs  = $active.siblings();
     var rndNum = Math.floor(Math.random() * $sibs.length );
     var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

	var scrollSpeed = 7000;
	var step = 280;
	var current = 0;
	var imageWidth = 560;
	var headerWidth = 0;		

	var restartPosition = -(imageWidth - headerWidth);

	function scrollBg(){
		current -= step;
		if (current == restartPosition){
			current = 0;
		}

		$('#phone').css("background-position",current+"px 0");
	}

	var init = setInterval("scrollBg()", scrollSpeed);



$(function() {
    setInterval( "slideSwitch()", 5000 );
    
});

