$(document).ready(function(){
	if ($('#car_1').length){
		$("#car_1-R > div").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			visible: 8
		})
	}
	if ($('#car_2').length){
		$("#car_2-R > div").jCarouselLite({
			btnNext: ".next_2",
			btnPrev: ".prev_2",
			visible: 2
		})
	}
	if ($('.car-2-1').length){
		$(".car-2-1").jCarouselLite({
			btnNext: ".next2",
			btnPrev: ".prev2",
			visible: 2
		})
	}
	if ($('#m-t').length){
		$('#m-t li').hover(function(){
			$(this).addClass('a')
		},
		function(){
			$(this).removeClass('a')
		})
	}
	if ($('.forumi').length){
		$('.forumi li').append('<s></s>')
	}
	if ($('.dop-foto ul li').length){
		$('.dop-foto ul li a').click(function(){
			if ($(this).parent().is('.active')){
				return false
			}
			else {
				$('.dop-foto ul li').removeClass('active');
				$(this).parent().addClass('active');
				$('.img-3 a img').attr('src', $(this).attr('href'));
				$('.img-3 a').attr('href', 'http://www.wcg.ru/galery/index.php?ELEMENT_ID=' + $(this).attr('title'));
				return false
			}
		})
	}

	if ($('.p-n').length){
		$('.p-n').find('li:first').addClass('first');
	}
	
	if ($('a.more-show').length){
		$('a.more-show').click(function(){
			$('.more-hide').hide();
			$('.more').show();
			$(this).parents('.member').find('.more-hide').show();
			$(this).parents('.member').find('.more').hide();
			return false
		})
	}
	
	if ($('.table-4').length){
		$('.table-4').each(function(){
			$(this).find('tr:even').addClass('even')
		})
	}
	
	$('.banner .inner').each(function(){
		theRotator(this);
	});
	
	
})

var arImg = new Array();

function rand(n){
	return Math.floor(Math.random()*n);
}
function theRotator(objThis) {

	pos = rand($('.slides img', objThis).length);
	/* console.log(objThis);
	console.log($('.slides img', objThis).length); */
	var i;
	var stop = false;
	
	if (arImg.length >= 4) { arImg = new Array(); }
	
	for ( i = 0; i < arImg.length ; i++)
	{
		if ( arImg[i] == pos) { stop = true; }
	}
	/* console.log(arImg); */
	if (!stop){ 
		arImg[arImg.length] = pos;	
		$('.slides img', objThis).hide().removeClass('show');
		$('.slides img', objThis).eq(pos).fadeIn('slow').addClass('show');
		setPeriod = setInterval(
			function()
			{
				var current = ($('.slides img.show', objThis));
				var next = ((current.next().length) ? (current.next()) : $('.slides img:first', objThis));
				next.addClass('show').fadeIn('slow');
				current.fadeOut('slow').removeClass('show');
			}
		,5000); 
	}
	else{
		theRotator(objThis);
	}
}


