$(function(){
setTimeout(function(){$('.complectation').show();},400);
// nav
$('header nav a').mouseover(function(){
	if($(this).attr('class')!='open'){$(this).animate({backgroundPosition:"50% -71px"},200);}
}).mouseleave(function(){
	if($(this).attr('class')!='open'){$(this).animate({backgroundPosition:"50% -142px"},10);}
});


 
// slider
SLIDER_SPEED=400;
MENU_SPEED=400;
SLIDER_FLAG=false;
AUTO_SLIDE_SPEED=5000;
function slideIt(n){
		// ïðîâåðÿåì, íå âûøëî ëè n çà ðàìêè
		n=$('#g .v li[name='+n+']').size()>0?n:1;
		//var l=(n-1)*1050;
		var l=(n-1)*710;
		SLIDER_FLAG=true;
		// ïîäæèãàåì ñëåäóþùóþ (èëè ïåðâóþ) âêëàäêó
		$('#g .v li.open').attr('class','');
		$('#g .v a.open').attr('class','');
		$('#g .v li[name='+n+']').attr('class','open');
		$('#g .v li[name='+n+']').parent('a').attr('class','open');
		$('#g div.move').animate({
			left:'-'+l+'px'
		},SLIDER_SPEED,'easeOutExpo',function(){
			SLIDER_FLAG=false;
		});
		$('#g #tlt').html($('.slide[name='+n+']').attr('data-text'));
		// äëÿ àâòîïðîêðóòêè
		AUTO_SLIDE_TIMEOUT=setTimeout(function(){
			if(!SLIDER_FLAG){
				slideIt(parseInt(n)+1);
			}
		},AUTO_SLIDE_SPEED);
		// ïðîêðó÷èâàåì v
		slide_v(n);
}
slideIt(0);
//
$('#g .v li').click(function(){
	if(!SLIDER_FLAG){
		// óäàëÿåì òàéìàóò
		if(typeof AUTO_SLIDE_TIMEOUT!='undefined'){clearTimeout(AUTO_SLIDE_TIMEOUT);}
		//
		$('#g .v li.open').attr('class','');
		$('#g .v a.open').attr('class','');
		$(this).attr('class','open');
		$(this).parent('a').attr('class','open');
		var n=$(this).attr('name');
		slideIt(n);
	}
});
// slide_v
function slide_v(n){
	var MAXN=4;// êîë-âî âêëàäîê, êîòîðûå ïîìåùàþòñÿ â âèäèìóþ îáëàñòü
	var CONTV=$('#g .v li').size();
	var WV=$('#g .v li.open').outerWidth(true); // øèðèíà 1 v
	//var MAXH=WV*MAXN;
	var L=parseInt($('#g .vmove').css('left'));
	var newLeft=0;
	if(n!=1 && n<CONTV-2){
		newLeft=WV*((n-2));
	}
	else{
		if(n!=1){
			newLeft=WV*((CONTV-4));
		}
	}
	
	$('#g .vmove').animate(
			{left:"-"+newLeft+"px"},
			200
	);
}


// menu
$('.nav ul li').each(function(){$(this).data('act',0);});
$('.nav ul li').mouseenter(function(){
	if($(this).attr('class')!='open'){
		$(this).attr('class','hover');
	}
	if($(this).data('act')!=1){
		$(this).find('ul').slideDown(MENU_SPEED);
		$(this).data('act',1);
	}
}).mouseleave(function(){
	var el=$(this);
	if($(this).attr('class')!='open'){
		$(this).attr('class','');
	}
	$(this).find('ul').slideUp(MENU_SPEED,function(){
		$(el).data('act',0);
	});
});


//
$('.o5').mouseover(function(){
	$(this).animate({opacity:1.0},200);
}).mouseleave(function(){
	$(this).animate({opacity:0.5},200);
});

// partners
$('#partners .left_arr,#partners .right_arr').click(function(){
	if($('#gm_move').attr('name')=='off'){
		clearTimeout(BTO);gm_move($(this).attr('class'));
	}
});
$('#gm_move img').mouseover(function(){STOPFLAG=true;})
.mouseleave(function(){STOPFLAG=false;});


STOPFLAG=false;
BSTEP=200;
BCOUNT=$('#partners #gm_move img').size();
MAXL=(BCOUNT-1)*BSTEP;
BSPEED=1100;
BPAUSE=10000;
//
function gm_move(dir){
	if($('#gm_move').attr('name')=='off'){
		$('#gm_move').attr('name','on');
		var l=parseInt($('#gm_move').css('left'));
		if(dir=='right_arr'){
			l=l>-MAXL?'-='+BSTEP+'px':'0px';
		}
		else{
			l=l<=-BSTEP?'+='+BSTEP+'px':'-='+(BSTEP*(BCOUNT-1))+'px';
		}
		if(STOPFLAG==false){
			$('#partners #gm_move').animate({left:l},BSPEED,'easeOutElastic');
		}
		setTimeout(function(){$('#gm_move').attr('name','off');BTO=setTimeout(function(){gm_move('r')},BPAUSE);},BSPEED);
	}
}
BTO=setTimeout(function(){gm_move('r')},BPAUSE);

//
});











