$(function(){
	// text switch
	$('.text_switch a').click(function(){
		if($(this).attr('class')!='open'){
			$('.text_switch a.open').attr('class','');
			$(this).attr('class','open');
			$('#'+$(this).parent('.text_switch').attr('name')).find('.sitem').hide();
			$('#'+$(this).parent('.text_switch').attr('name')).find('.sitem[name='+$(this).attr('name')+']').show();
		}
		return false;
	});

// красные переключатели
// add tlt  top 12
$('.switch').each(function(){
		if($(this).find('div').size()>1){
			$(this).append("<span class='tlt db pr'></span>"); 
		}
});
setTimeout(function(){
	// показываем подсказки
	$('.switch .tlt').animate({
		top:'12px',
		opacity:1.0
	},600);
},3000);
//
$('.switch div').mouseover(function(){
	if($(this).attr('class')!='open'){
		$(this).css({backgroundPosition:"-265px -30px"});
	}
}).mouseleave(function(){ 
	if($(this).attr('class')!='open'){
		$(this).css({backgroundPosition:"-280px -30px"});
	}
}).mousedown(function(){
	if($(this).attr('class')!='open'){
		$(this).css({backgroundPosition:"-295px -30px"});
	}
}).click(function(){
	if($(this).attr('class')!='open'){
		$(this).parent('.switch').find('.open').attr('class','').css({backgroundPosition:"-280px -30px"});
		$(this).css({backgroundPosition:"-250px -30px"});
		$(this).attr('class','open');
		my_switch($(this));
	}
	// прячем tlt
	$('.switch .tlt').animate({
		top:'8px',
		opacity:0.0
	},300,function(){$(this).hide();});
});
function my_switch(el){
	$(el).parent('.switch').parent('.block ').find('.item').animate({opacity:0.0},200);
	setTimeout(function(){
		$(el).parent('.switch').parent('.block ').find('.item').hide();
		$(el).parent('.switch').parent('.block ').find('.item[name='+$(el).attr('name')+']').show().animate({opacity:1.0},200);
	},200);
}
    $('.menutop .item').mouseenter(function(){
		if($(this).attr('class')!='item open fl'){
			$(this).css(
				{
					border:"1px solid #818896",
					background:"#969fb3"
				}
			).animate({opacity:1.0},200);
		}
	}).mouseleave(function(){
		if($(this).attr('class')!='item open fl'){
			$(this).css(
				{
					border:"1px solid #969fb3",
					background:"none"
				}
			).animate({opacity:0.5},100);
		}
	});
    zInd=10;
$('#krowki .item').each(function(){
		$(this).css('zIndex',zInd);
		zInd-=1;
	}).mouseover(function(){
		$(this).css(
			{
				background:"#969fb3",
				border:"1px solid #7a8191"
			}
		);
		$(this).find('.l').css({backgroundPosition:'0px -69px'});
		$(this).find('.r').css({backgroundPosition:'0px -23px'});
	}).mouseleave(function(){
		$(this).css(
			{
				background:"#6c7488",
				border:"1px solid #585e6e"
			}
		);
		$(this).find('.l').css({backgroundPosition:'0px -92px'});
		$(this).find('.r').css({backgroundPosition:'0px 0px'});
	});


// blagodarnosti
$('#blagodarnosti .l,#blagodarnosti .r').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=220;
BCOUNT=$('#blagodarnosti #gm_move img').size();
MAXL=(BCOUNT-1)*BSTEP;
BSPEED=600;
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=='r o5'){
			l=l>-MAXL?'-='+BSTEP+'px':'0px';
		}
		else{
			l=l<=-BSTEP?'+='+BSTEP+'px':'-='+(BSTEP*(BCOUNT-1))+'px';
		}
		if(STOPFLAG==false){
			$('#blagodarnosti #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);




$('#lenta').hide();


BANNER=false;
	//
	var pagehash=window.location.hash;
	if(pagehash=='#show'){
		//http://valentrans.ru/images/_konvert.jpg
		//BANNER=true;
	}

if(!BANNER){
	$('#glr #banner').hide();
}
else{// ADRES BANNERA
	$('#glr #banner').show();
	$('#glr #banner').css({
		backgroundImage:"url('images/banner/tp.jpg')"
	});
	$('#glr #items hr').hide();
	$('#glr #items div').attr('class','');
	
	
}
// opacity тени
$('#glr').mouseenter(function(){
	if($(this).find('.r').css('opacity')!='1.0'){
		$(this).find('.r,.l,.t,.b').animate({opacity:1.0},300);
	}
}).mouseleave(function(){
	if($(this).find('.r').css('opacity')!='0.5'){
		$(this).find('.r,.l,.t,.b').animate({opacity:0.5},300);
	}
});
// hr
hr_start_top=12;
hr_step=65;
data_step=280;
function move_hr(n,speed){
	nt=(n-1)*hr_step+hr_start_top;
	$('#glr #items hr').animate({top:nt+'px'},speed);
}
//
$('#glr #items div').mouseover(function(){
	if($(this).attr('class')!='open'){
		$(this).attr('class','hov');
	}
	else{
		$('#glr #items hr').css({backgroundPosition:"-10px -100px"});
	}
}).mouseleave(function(){
	if($(this).attr('class')!='open'){
		$(this).attr('class','');
	}
	else{
		$('#glr #items hr').css({backgroundPosition:"-10px -163px"});
	}
}).click(function(){
	$('#glr #items div.open').attr('class','');
	$(this).attr('class','open');
	// if BANNER
	if(BANNER){
		$('#glr #banner').animate({opacity:0.0},200,function(){
			$('#glr #banner').hide();
		});
		$('#glr #items hr').show();
	}
	//
	var n=$(this).attr('name');
	move_hr(n,200);
	// перемещаем data-div
	var n=$(this).attr('name');
	var nt=-((n-1)*data_step);
	$('#glr #data #move').animate({top:nt+'px'},200);
});

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

// login
$('#login').click(function(){
	$('#mdiv').show().animate({opacity:1.0},400);
});
$('#mdiv').click(function(){
	$('#mdiv').animate({opacity:0.0},400);
	setTimeout(function(){$('#mdiv').hide();},400);
});
$('#mdiv #mdiv_data').click(function(event){
	event.stopPropagation();
});

// MENU
$('#menu').find('li.item').each(function(){$(this).data('act',0);});
$('#menu').find('li.item').mouseover(function(){
	if($(this).data('act')!=1 ){
		$(this).find('ul').slideDown(200);
		$(this).data('act',1);
	}
}).mouseleave(function(){
	el=$(this);
	$(this).find('ul').slideUp(200,function(){
		$(el).data('act',0);
	});
});

$('.png').live({
	mouseenter: function(){
		$('#menu').find('li.item').each(function(){$(this).show();});
	},
	mousleave: function(){
		$('#menu').find('li.item').each(function(){$(this).show();});
	}
});


	$('#togglemenu').click(function(){
		if($('.left').css('display')=='block'){
			$('.left').slideUp(100);
			$('.right').delay(120).animate({width:'1165px'},300);
			$(this).css({backgroundPosition:'0px -41px'});
		}
		else{
			$('.right').animate({width:'870px'},300);
			$('.left').delay(320).slideDown(100);
			$(this).css({backgroundPosition:'0px 0px'});
		}
	});
    $('ul#menuul li.first').mouseenter(function(){
		if($(this).attr('class')!="item first open"){
			var name=$(this).attr('name');
			if($(this).find('ul').css('display')=='none'){
				$(this).find('ul').slideDown(200);
			}
		}
	}).mouseleave(function(){
		if($(this).attr('class')!="item first open"){
			$(this).find('ul').slideUp(400);
		}
	});

    $('.left ul#menuul hr').hide();
    $('.left ul#menuul li.open ul').show();
});

















