var c1x=0,c2x=0,bI=200,bS=292,bY=200,bH=0,bAway=0,sX,sY,pa,w=$(window);

$(function(){
	$("div#menu>ul strong>a").mouseenter(function(){
		var t=$(this),p=t.parent().parent();
		p.find("ul.submenu").animate({'opacity':'1'},{queue:false,duration:300}).slideDown(300);

		p.hover(function(){
			t.addClass("menuh");
			t.animate({backgroundPosition:'250px 0'},{queue:false,duration:500});
		},function(){
			p.find("ul.submenu").animate({'opacity':'0'},{queue:false,duration:600}).slideUp(600);
			t.removeClass("menuh");
			t.css({backgroundPosition:'-85px 0'});
		});

	});
});

function c1(){
	c1x--;
	$("#c1").css({backgroundPosition:c1x+'px 0'});
	c1t=setTimeout("c1()",130);
}

function c2(){
	c2x--;
	$("#c2").css({backgroundPosition:c2x+'px 0'});
	c2t=setTimeout("c2()",40);
	if(bAway==0){
		bI=$("#balloon").css('top');
		bI=2342-parseInt(parseInt(bI.replace('px',''))/4)+'&nbsp;м';
	}else{
		bI='вне досягаемости';
	}
	$("#binfo").html('Скорость: '+bS+'&nbsp;км/ч<br>Высота: '+bI);
}

function balloon(){
	if(bY==250){bY=200;bS=16}else{bY=250;bS=17}
	$("#balloon").animate({top:(bH+bY)+'px'},2500);
	bt=setTimeout("balloon()",3000);
}

function bmove(){
	$("#sky").mousemove(function(e){
		sX=((e.pageX*50)/w.width()).toFixed(0);
		sY=(190-(e.pageY*5)/650).toFixed(0);
		$("#balloon").css({margin:"0 0 0 -"+sX+"px"});
		$("#c2").css({top:sY+"px"});
	});
}

function hl(){
	$("#hl>a").click(function(){
		$("#hl").html('Задание выполняется...').animate({backgroundPosition:'250px 0'},500,function(){
			$(this).css({backgroundPosition:'-85px 0'});
		});
		$("#bfire").animate({opacity:'1'},600).animate({opacity:'0'},400);
		if(bt){clearTimeout(bt)}
		$("#balloon").stop(true,false);
		if(bY==250){bY=200}else{bY=250}
		bH=bH-50;
		$("#balloon").animate({top:(bH+bY)+'px'},1000,function(){
			if(bH>-500){bAway=0}else{bAway=1}

			if(bAway==0){
				$("#hl").html('<a href="#">Хочу еще выше!</a>');
				hl();
			}else{
				$("#hl").html('Поздравляем,<br>Вы достигли космических высот!<br><br><a href="#" id="hlback">Вернуть шар!</a>');
				$("#hlback").click(function(){
					bH=0;
					bAway=0;
					$("#hl").html('<a href="#">Хочу еще выше!</a>');
					hl();
				});
			}
		});
		balloon();
	});
}

