
var scroll_to;
var timeerlen;
var lastxxx=-1;
var stop=false;
/*Застрелиться и не встать*/
$(document).ready(function(){


var control=false;
 $("body").keydown(function (e) {
	  if(e.which==17){
	  control=true;
	  };
	  if(e.which==37){	  
		goPrev();
	  }else if(e.which==39){
		goNext();
	  }
});				   
$("body").keyup(function (e) {
  if(e.which==17){
  control=false;
  };
});	

function anim(nclass){
	//alert(nclass);
	
	//$("."+nclass).animate({opacity:0.3},200);
	//$("."+nclass).animate({opacity:0.8},200);
	//$("."+nclass).animate({opacity:0.1},200);
	//$("."+nclass).animate({opacity:1},200);
	$("."+nclass).animate({opacity:0.1},1000);
	$("."+nclass).animate({opacity:0.9},1000);
	
}
setInterval(function(){
	if($(".left_arrow").css('opacity')==0.9){
		anim('left_arrow');
	}	
},2000)
setInterval(function(){
	if($(".right_arrow").css('opacity')==0.9){
		anim('right_arrow');
	}    
},2000)

$(".left_arrow,.right_arrow").css({opacity:0.9,cursor:'pointer'});

$(".left_arrow, .right_arrow").hover(function(){
if(!stop){											  
$(this).stop(false,true);
$(this).animate({opacity:1},'fast');												  
}
},function(){
	$(this).stop(false,true);
	$(this).animate({opacity:0.9},'fast');												  
})
$.page_scroller=new Object();
$.page_scroller.last=false;
$("#mktomy div").click(function(){
if($(this).find("a").length<=0){return}
//window.location.href="#1";
window.location='#0';
scroll_to(1);
return false;
})
/********************************************/
$("#mgdzapchasti div").click(function(){
if($(this).find("a").length<=0){return}
//$(this).click();
window.location='#1';
scroll_to(2);
return false;
})

$("#mproizvodstvo div").click(function(){
if($(this).find("a").length<=0){return}
window.location='#2';
scroll_to(3);
return false;
})

$("#mgruzoperevozki div").click(function(){
if($(this).find("a").length<=0){return}
window.location='#3';
scroll_to(4);
return false;
})
function goNext(){
//alert(lastxxx);
togo=lastxxx;
if(lastxxx>=4){togo=0}
window.location='#'+togo;

scroll_to(togo+1);
}
function goPrev(){
//alert(lastxxx);
togo=lastxxx;
if(lastxxx<=1){togo=5}
window.location='#'+(togo-2);
scroll_to(togo-1);
}
$(".left_arrow").click(function(){
//alert('vovo');
goPrev();

})
$(".right_arrow").click(function(){
goNext();
})
scroll_to =function(pos){/**************************************************************************/
if(stop){return}
stop=true;
$("#main_menu .menu_item").animate({opacity:0.5});
var pos=window.location.hash;
$.page_scroller=new Object();

$("#container").stop();
var width=$("#main_display").width();
if(width<1000){
width=1000;
}
var to=0;
var xxx=0;
var add_to=0;
$.page_scroller.last=false;
var dv=$("#mktomy div")
var pup=$("#for_pupki td.ktomy div")
$('.left_arrow').fadeIn();
$('.right_arrow').fadeIn();

if(pos=='#0'){
var dv=$("#mktomy div")
var pup=$("#for_pupki td.ktomy div")
to=0;
xxx=1;
$('.left_arrow').fadeOut('slow');
}else if(pos=='#1'){
var dv=$("#mgdzapchasti div")
var pup=$("#for_pupki td.gdzapchasti div")
to=-1000
xxx=2;
}else if(pos=='#2'){
var dv=$("#mproizvodstvo div")
var pup=$("#for_pupki td.proizvodstvo div")
to=-2000
xxx=3;
}else if(pos=='#3'){
var dv=$("#mgruzoperevozki div")
var pup=$("#for_pupki td.gruzoperevozki div")
to=-3000+(width-1000)
var add_to =(width-1000);
$.page_scroller.last=true;
xxx=4;
$('.right_arrow').fadeOut('slow');
}
var add_to_back=0;
if((lastxxx==3)&&(xxx==4)){
add_to_back=add_to;

}
if(xxx-lastxxx>0){
var pered=true;

}else{
var pered=false;
}
lastxxx=xxx;
var after=false;
//alert(dv.html())
$("#main_menu .menu_item div").each(function(){
if(!after){
if($(this).text()!=dv.text()){
$(this).css({background:'url(/images/menu_left_pointer.png) no-repeat left center'});
}else{
$(this).css({background:'none'});
after=true;
//alert($(this).text());
}
}else{
$(this).css({background:'url(/images/menu_right_pointer.png) no-repeat right center'});
}
//alert($(this).html());
})
//$("#main_menu .menu_item div").html("123");
$("#main_menu .menu_item div").each(function(){
//alert($(this).html());
//alert($(this).find('a').html())
if($(this).find('a').html()){
$(this).html($(this).find('a').html());
}
})
$("#main_menu .menu_item div").wrapInner('<a href="JavaScript:;"></a>');
//$(".menu_marker").remove();
var kakushka=dv.find('a').html()
//alert(kakushka);
//alert(kakushka);
dv.html(kakushka);/************************************************************************************************/
//alert(dv.find('a').html());
$(".menu_marker").remove();
pup.css({position:'relative',border:'0px solid red'});
pup.append("<img class='menu_marker' src='/images/menu_marker.png'>");
//alert(to)
//$(".fact,.fact_text").css({opacity:0});
$(".fact,.fact_text").animate({opacity:'hide'},0);
$(".fact1").stop();
$("#poezd").animate({"left":'+=100px'},{'duration':900,'easing':'swing'});
	
	//window.location='#3';
	setTimeout(function(){$("#poezd").stop(false,false);
	if(pered==true){
	$("#poezd").animate({left:add_to_back-700+'px','duration':500,'easing':'swing'});
	}else{
	//alert(pered);
	$("#poezd").animate({left:width+10+'px','duration':500,'easing':'swing'});
	}

	},500)
	//$("#anim_block").css({opacity:'1'});
	setTimeout(function(){
	//$("#anim_block").stop();
	
$("#container").animate({marginLeft:to+'px'},500,function(){
timeerlen=500;
	anim_blicks()
	
	$("#poezd").css({left:add_to_back+20-700+'px'});
	//alert(add_to);
	$("#poezd").animate({left:add_to+10+'px'},{'duration':4000,'easing':'swing'});	
	setTimeout('animate_poezd(1)',500)
	setTimeout('animate_poezd(4)',1000)
	setTimeout('animate_poezd(3)',2000)
	setTimeout('animate_poezd(2)',2500)
	setTimeout('animate_poezd(1)',3000)
	setTimeout('animate_poezd(0)',3800)
	
	setTimeout(function(){timeerlen=-1;$(".fact"+xxx).animate({opacity:'show'},'slow');  stop=false;$("#main_menu .menu_item").animate({opacity:1});
	/*anim('left_arrow');*/
	},4000)


})
},500)
$(".menu_marker").css({position:'absolute',top:'-5px',left:'50%',marginLeft:'-13px'});
//$("#main_menu td.menu_item.activ").css({opacity:'1'});
//$("#main_menu td.menu_item.activ").animate({opacity:'0.5'},400);
//$("#main_menu img").css({opacity:'1'});
//$("#main_menu img").animate({opacity:'0,5'},400);
//$("#main_menu td.menu_item.activ a").css({position:'absolute',top:0,opacity:'1 !important'});
/*
$("#main_menu td.menu_item.activ").queue(function () {
		$(this).removeClass("activ");
		$(this).animate({opacity:'1'},1000);
		//$(this).css({opacity:'1'});
		$(this).dequeue();
	  });
	  */
/*$("#main_menu td.menu_item").removeClass("activ");*/
$("#main_menu td.menu_item.activ").removeClass("activ");
dv.parent().css({opacity:'0.5'});
dv.parent().animate({opacity:'1'},500);

$("#main_menu img").css({opacity:'0.5'});
$("#main_menu img").animate({opacity:'1'},500);
//$(".menu_marker").css({opacity:'0.5'});
//$(".menu_marker").animate({opacity:'1'});
dv.parent().addClass("activ");

}
/*
$("#main_display").click(function(){
alert("Да!");
})
*/
$(".fact .closer").click(function(){
	var mid=$(this).parents(".fact").attr('id');
	//alert(mid);
	$("."+mid).animate({opacity:'hide'},'fast');
})
var block_old_width=0;
$(window).resize(function(){
						 // alert('');
var width=0;
var to=0;
width=$("#main_display").width();
if(block_old_width!=width){
block_old_width=width;
//alert(width);
if(width<1000){
width=1000;
}
if($.page_scroller.last){
to=-3000+(width-1000);
$("#container").css({marginLeft:to+'px'})
$("#poezd").css({left:(width-1000)+10+'px'});
}
$(".right_arrow").css({left:width-78+'px'})
}

})
/****************************************/
/*
.hover(function(){
$(this).css('backgroundImage','url(/images/big_orange_tire.jpg)')
},function(){
$(this).css('backgroundImage','url(/images/big_blue_tire.jpg)')
});
*/
$(".megablok .body_hrefs").each(function(){
var th=$(this);
$(this).find("a:first").hover(function(){
th.addClass("active");
},
function(){
th.removeClass("active");

})
})
if(window.location.hash==""){
window.location="#0";
}
scroll_to(1);

/*******кликер для маркеров**********/


$(".marker.noactive").animate({'opacity': '0.5'},1)
$.markers=new Object();
$.markers.mayHide=true;
$(".marker .clicker .content").animate({'opacity': 'hide'},1);
$(".marker .clicker").mouseover(function(){
	/*Выбираем направление выпадения*/
	//$(".marker .clicker").mouseout();
	var thmarker=$(this).parent(".marker");
	var wwidth=$(window).width();
	var wheight=450;
	var dwidth=thmarker.find(".content").width();
	var dheight=thmarker.find(".content").height();
	//alert(dheight);
	if(thmarker.offset().top+dheight+10>wheight){
	  thmarker.find(".content").css('bottom','10px'); 
	  thmarker.find(".content").css('top','auto'); 
	} else{
	  thmarker.find(".content").css('top','10px'); 
	  thmarker.find(".content").css('bottom','auto'); 
		
	}
	var to=(wwidth);
	//alert(thmarker.offset().left+'+++'+to+'---'+lastxxx);
	if(thmarker.offset().left+dwidth+100>to){
	  thmarker.find(".content").css('right','10px'); 
	  thmarker.find(".content").css('left','auto'); 
	} else{
	  thmarker.find(".content").css('left','10px'); 
	  thmarker.find(".content").css('right','auto'); 
		
	}
	/**********--выбрали--*****************/
	
	$('.marker').css({zIndex:50002});
	$(this).parent('.marker').css({zIndex:50010});
	
$(this).find(".content").stop(false,true);  
$(this).find(".content").animate({'opacity': 'show'},200);
$.markers.mayHide=false;

});
$(".marker .clicker").mouseout(function(){
$.markers.mayHide=true;
$.markers.hide=function(){
//alert("");
//alert($.markers.mayHide);

if($.markers.mayHide){
	$(".marker .clicker .content").stop(false,true); 
//$(".marker .clicker .content").animate({'opacity': '0.9'},400);
$(".marker .clicker .content").animate({'opacity': 'hide'},200);

}
//alert("");
}
//$.markers.hide=function(){
$.markers.mayHide=true;
setTimeout("$.markers.hide()",10);
//$(".marker .clicker .content").animate({'opacity': '0.9'},200);


//$(this).find('.content').animate({'opacity': 'hide'},200)
//}
//$.markers.hide();
//setTimeout("$.markers.hide()",1000);

});
//$(".kontacts .content .contacts").css({display:'block'});
$(".kontacts .content .contacts").css({opacity:0});
$("#main_menu #kontacts,#for_pupki .contacts").click(function(){
	$(".kontacts .content .contacts").animate({opacity:'hide'},0);
});
$("#main_menu #kontacts,#for_pupki .contacts").hover(function(){
//$(".kontacts .content .contacts").stop();
$(".kontacts .content .contacts").stop(true,false);
if($(".kontacts .content .contacts").css('display')=='none'){
	$(".kontacts .content .contacts").css({display:'block'});
}
$(".kontacts .content .contacts").animate({opacity:1},200);
},function(){
//$(".kontacts .content .contacts").stop();
$(".kontacts .content .contacts").stop(true,true);
$(".kontacts .content .contacts").animate({opacity:'hide'},200);
});
$("#nextZapchasti").click(function(){
$("#mgdzapchasti div").click();
//alert();
})
$("#nextProizvodstvo").click(function(){
$("#mproizvodstvo div").click();
//alert();
})
$("#prevKtomy").click(function(){
$("#mktomy div").click();
//alert();
})
$("#nextPerevozki").click(function(){
$("#mgruzoperevozki div").click();
//alert();
})
$("#prevGdzapchasti").click(function(){
$("#mgdzapchasti div").click();
//alert();
})
$("#prevProizvodstvo").click(function(){
$("#mproizvodstvo div").click();
//alert();
})
});
	
$(document).ready(function(){
$(window).resize();
//var timeerlen=100;
anim_blicks=function(stopit){
	var blicks=Array();
	$("#poezd .blick").each(function(){
									
		if(Math.random()>0.5){
			$(this).toggle('fast');	
		}
		
	})
	//alert(timeerlen);
	if(timeerlen>0){
			setTimeout(anim_blicks,timeerlen);
		
		
	}else{
		//alert();
		$("#poezd .blick").stop();
		$("#poezd .blick").hide();
	}
}
/*anim_blicks();*/
animate_poezd=function(score){
if(score==0){
	timeerlen=500;
	op=0;
} else if(score==1){
	timeerlen=400;
	op=0.4;
} else if(score==2){
	timeerlen=300;
	op=0.6;
} else if(score==3){
	timeerlen=200;
	op=0.9;
} else if(score==4){
	timeerlen=100;
	op=1;
}

$("#poezd .blur").animate({'opacity':op},'fast');
}
animate_poezd(2);
var act=0;



/*$("#poezd").animate({left:'520px'},{'duration':300,'easing':'linear'});	
$("#poezd").animate({left:'530px'},{'duration':100,'easing':'linear'});	
*/
//$("#poezd").animate({top:'100px'},{'duration':3000,'queue':true});	
	$("#opros_form").submit(function(){
		if($.opacity){
			$("#opros").animate({'opacity':"0.0"},"slow");
		}else{
			$("#opros").hide();  
		}
		var select=$("#opros input:radio:checked").val();
		var qid=$("#opros #qid").val();
		//alert(select);
		var data={'answer':select,'question':qid};
		$.post("/golos",data,function($data){
			if($.opacity){
		$("#opros").stop(false,true);
		$("#opros").animate({'opacity':"1"},"slow");
			}else{
				$("#opros").show(); 
			}
		$("#opros").html($data);    
		//alert('1');    
		});
		
		return false;
	});		   
})

