var aPreloadImages = new Array();

$(function (){
	
	aPreloadImages[0] = '/images/chevrolet_fon.jpg';
	aPreloadImages[1] = '/images/daewoo_fon.jpg';
	aPreloadImages[2] = '/images/default_fon.jpg';
	aPreloadImages[3] = '/images/kia_fon.jpg';
	aPreloadImages[4] = '/images/lada_fon.jpg';
	aPreloadImages[5] = '/images/nissan_fon.jpg';
	aPreloadImages[6] = '/images/opel_fon.jpg';
	aPreloadImages[7] = '/images/tagaz_fon.jpg';
	aPreloadImages[8] = '/images/volkswagen_fon.jpg';
	preload(aPreloadImages);
	
	var jMainCarsContainer = $("div#main_car");
	if ($.browser.opera) {
		$.support.opacity = true;
	}
	var aMainCars = new Array();
	$("div.ddheader").each(function () {
		var fName = $(this).attr("id");
		jMainCarsContainer.prepend('<div></div>');
		aMainCars[fName] = jMainCarsContainer.children(':first');
		aMainCars[fName].css({'opacity': 0, 'background-image' : 'url(/images/' + fName + '_fon.jpg)'});
	});
	
	$("div.ddheader").hover(
		function () {
			var jDdcontent = $('div.ddcontent', this);
			jDdcontent.stop();
			var fName = $(this).attr("id");
			aMainCars[fName].stop();
			//$('div.ddcontent').stop();
//			$('div.ddcontent', this).show();
			$(this).css({'background-image' : 'url(/images/menu_arr.gif)'});
//			$("div#main_car").css({'background-image' : 'url(/images/preloader.gif)'});
			//jMain_car.css({'background-image' : 'url(/images/' + fName + '_fon.jpg)'});
			var iTime = 6 * ( 76 - jDdcontent.height() );
			aMainCars[fName].animate({'opacity': '1'}, iTime, 'linear');
			jDdcontent.animate({'height': '76px'}, iTime, 'linear');
		}, 
		function () {
			var jDdcontent = $('div.ddcontent', this);
			jDdcontent.stop();
			var fName = $(this).attr("id");
			aMainCars[fName].stop();
//			$('div.ddcontent', this).hide();
			$(this).css({'background-image' : 'none'});
			//jMain_car.css({'background-image' : 'url(/images/default_fon.jpg)'});
			var iTime = 6 * jDdcontent.height();
			aMainCars[fName].animate({'opacity': '0'}, iTime, 'linear');
			jDdcontent.animate({'height': '0px'}, iTime, 'linear');
		}
	);
	
//$('div.ddcontent').hover(function() {
//        var fName = $(this).prev('div.ddheader').attr("id")
//        $(this).next('div.ddcontent').show();      	
//        $(this).prev('div.ddheader').css({'background-image' : 'url(/images/menu_arr.gif)'});
//        $("div.main_car").css({'background-image' : 'url(/images/preloader.gif)'});
//        $("div.main_car").css({'background-image' : 'url(/images/' + fName + '_fon.jpg)'});
//    }, function() {
//$(this).stop();
//        $(this).next('div.ddcontent').hide();      	
//        $(this).prev('div.ddheader').css({'background-image' : 'none'});
//        $("div.main_car").css({'background-image' : 'url(/images/default_fon.jpg)'});
//    });

})




function preload(images) {
    if (typeof document.body == "undefined") return;
    try {
        var div = document.createElement("div");
        var s = div.style;
        s.position = "absolute";
        s.top = s.left = 0;
        s.height = '10px';
        s.overflow = 'hidden';
        s.visibility = "hidden";
        document.body.appendChild(div);
        div.innerHTML = "<img src=\"" + images.join("\" /><img src=\"") + "\" />";
    } catch(e) {
        // Error. Do nothing.
    }
}


$(function () {
	var jQuote = $('#main_news_quote');
	var iWidthContainerQuote = jQuote.width();
	
	var sTextQuote = jQuote.text();
	jQuote.html('<div style="width:5000px;"><div style="float:left;">' + sTextQuote + '</div></div>');
	var iWidthQuote = jQuote.children('div').children('div').width();
	jQuote.html('<div style="width:' + iWidthQuote + 'px;">' + sTextQuote + '</div>');
	if (iWidthContainerQuote >= iWidthQuote) { return; }
	
	var iMargin = iWidthQuote - iWidthContainerQuote;
	var iTime = iMargin / 50 * 1000;
	var jInnerQuote = jQuote.children('div');

	scrollQuoteToLeft();
	
	function scrollQuoteToLeft () {
		jInnerQuote.animate({'marginLeft': -iMargin}, iTime, 'swing', function () {
			setTimeout(scrollQuoteToRight, 1000);
		});
	}
	function scrollQuoteToRight () {
		jInnerQuote.animate({'marginLeft': 0 }, iTime, 'swing', function () {
			setTimeout(scrollQuoteToLeft, 1000);
		});
	}

})

//$(function (){new Redactor('redactor_content', { focus: true});})
