$(document).ready(function(){
	$(".i-block_l_i a img:first").addClass("activeslide").show();
	mailForm();
	size();
	sizeCatalog();
});

$(window).load(function(){
	$(".i-block_l_i a img").hover(
		function() {
			$(this).fadeTo(0, 0.7);
		},
		function() {
			$(this).fadeTo(0, 1);
		}
	);
			
	if ($(".i-block_l_i a img").length > 1) {
		$(".i-block_l_i a img:first").addClass("activeslide").next().css("display","none");
		setInterval(function() {
			theslideshow1();
		}, 4000);
	}
	if ($(".newPribor ul li").length > 1) {
		vis();
		$(".newPribor ul li").hide();
		$(".newPribor ul li:first").show().addClass("active");
		setInterval(function() {
			newPribor();
		}, 4000);
	}
});

function theslideshow1() {
	var currentslide = $(".i-block_l_i a .activeslide");
	if ( currentslide.length == 0 ) currentslide = $(".i-block_l_i a img:last");
	var nextslide =  currentslide.next().length ? currentslide.next() : $(".i-block_l_i a img:first");
	nextslide.fadeIn(1000).addClass("activeslide");
	currentslide.fadeOut(1000).removeClass("activeslide");
}

function mailForm() {
	$(".newPribor .n_pr .mailList").hover(
		function() {
			$(this).addClass("active");
		},
		function() {
			$(this).removeClass("active");
		}
	);
}

function newPribor() {
	var currentslide = $(".newPribor ul li.active");
	if ( currentslide.length == 0 ) currentslide = $(".newPribor ul li:last");
	var nextslide =  currentslide.next().length ? currentslide.next() : $(".newPribor ul li:first");
	nextslide.fadeIn(1000).addClass("active");
	currentslide.insertAfter(".newPribor ul li:last").hide().removeClass("active");
	
	var currentsVis = $(".newPribor .vis .active");
	if ( currentsVis.length == 0 ) currentsVis = $(".newPribor .vis div:last");
	var nextslideVis =  currentsVis.next().length ? currentsVis.next() : $(".newPribor .vis div:first");
	nextslideVis.addClass("active");
	currentsVis.removeClass("active");
}

function vis() {
	var a = $(".newPribor ul li");
	$(".newPribor .vis").css("width",(a.size())*10);
	for (var i = 0; i < a.length; i++) {
		a[i] = $(".newPribor .vis").append('<div class="visSize"><img src="/img/vis.gif" /></div>');
	}
	$(".newPribor .vis .visSize:first").addClass("active");
}

$(window).bind("resize", function(){
	sizeCatalog();
});

function size() {
	if($(document).width()<1100) {
		$(".newsMain .newsTxt ul").css("width","100%");
	} else {
		if($(".newsMain .newsTxt ul").size()<=2) {
		
		} else {
			menu();
		}
	}
}

function sizeCatalog() {
	var c = $(".catalogMain li");
	var e = $(".rightBlockC .wrap .wrap-catalog li");
	
	if($(document).width()<=1619) {
		c.css("width","29%");
	} else {
		c.attr("style","");
	}
	if($(document).width()<=1279) {
		e.css("width","29%");
	} else {
		e.attr("style","");
	}
}

function menu() {
	$(".newsMain .newsTxt").find("li").each_slice(5, function() {
		$('<ul />').append(this).appendTo(".newsMain .newsTxt");
	}).end().find("ul:first").remove();
	$(this).remove();
	$(".newsMain .newsTxt ul:first").addClass("fUl");
}

$.fn.each_slice = function(num, fn) {
    for ( var i=0,l=this.length,count=0,slice=[]; i<=l; i++ ) {
        if ( count >= num ) {
            fn.apply( jQuery( slice ) );
            count=0, slice=[];
        }
        slice.push( this[i] );
        count++;
    }
    return this;
};
