$(window).load(function() {
	$('div[widget="carousel"] .gallery').attr('ml', function() {
		return ($(this).width() - $(this).children().width());
	});
	$('div[widget="carousel"] .left_arrow').mouseover(function() {
		var left = -parseInt($(this).parent().find('.carousel').css('left'));
		$(this).parent().find('.carousel').animate({'left': 0}, left * 5, 'linear');
	});
	$('div[widget="carousel"] .left_arrow').mouseout(function() {
		$(this).parent().find('.carousel').stop();
	});
	$('div[widget="carousel"] .right_arrow').mouseover(function() {
		var left = parseInt($(this).parent().find('.carousel').width()) - parseInt($(this).parent().find('.gallery').width()) + parseInt($(this).parent().find('.carousel').css('left'));
		$(this).parent().find('.carousel').animate({'left': $(this).parent().find('.gallery').attr('ml') + 'px'}, left * 5, 'linear');
	});
	$('div[widget="carousel"] .right_arrow').mouseout(function() {
		$(this).parent().find('.carousel').stop();
	});

	// ------ Устаревшее.
	$("#gallery").attr("ml", $("#gallery").width()-$("#gallery").children().width());
	$("#pointL").mouseover(function(){
		var l=-parseInt($(".carousel", "#gallery").css("left"));
		$(".carousel", "#gallery").animate({"left": 0}, l*5, "linear");
	});
	$("#pointL").mouseout(function(){
		$(".carousel", "#gallery").stop();
	});
	$("#pointR").mouseover(function(){
		var l=$(".carousel", "#gallery").width()-$("#gallery").width()+parseInt($(".carousel", "#gallery").css("left"));
		$(".carousel", "#gallery").animate({"left": $("#gallery").attr("ml")+"px"}, l*5, "linear");
	});
	$("#pointR").mouseout(function(){
		$(".carousel", "#gallery").stop();
	});
	/*$("img",".carousel").click(function(){
	    var src = $(this).attr("src");
	    src = src.replace('/120/','/800/');
		$("img", ".nedv_photo").attr("src", src);
	});*/
	// ------------ Устаревшее.

	// ------ На рефакторинг.
    var banners = '';
    $('.bannerPlace').each(function(){banners += $(this).attr('id').replace('banner', '')+'|';});
    $.ajax({
        type: "post",
        data: "url="+location.href+"&banners="+banners,
        url: 'http://'+location.host+'/banner/getBanners/',
        dataType:"json",
        cache:true,
        success: function(data){$('.bannerPlace').each(function(){
            var obj = data[$(this).attr('id').replace('banner','')];
            if(obj) {
                if(obj['src'].indexOf('swf') > 0) {
                    var width = obj['width']*1 > 0 ? obj['width'] : 170;
                    var height = obj['height']*1 > 0 ? obj['height'] : 170;
                    swfobject.embedSWF(obj['src'], $(this).attr('id'), width, height, "9.0.0");
                }
                else $(this).html(obj['src']);
            }
        });}
    });
	divideClientsIntoTwoColumns();
	setClickOnClient();
	$('a.client_paginator').click(function() {
		$.ajax({
			url: '/client/getclients/' + $(this).attr('section') + '/page' + $(this).attr('value') + '/ajax/',
			dataType : 'html',
			success: function(data, textStatus) {
				$('.clients').html(data);
				divideClientsIntoTwoColumns();
				setClickOnClient();
			}
		});
	});
	// ------------ На рефакторинг.
});
