$('.ballon, .ballon_arr').css('display','none');
$(function(){
	$('#show_map').bind('click', function(){
		if ($('.ymap_box').height() == 0){
			$('.ymap_box, .heighter').animate({height: 371},300,function(){vAlign();});
		}else{
			$('.ymap_box, .heighter').animate({height: 0},300,function(){vAlign();});
		}
	});
	vAlign();
	$(window).resize(function() {
		vAlign();
	});
	$('.clients_line_hh a').bind('mousemove',function(e){
		$('.ballon_text').html('<nobr>'+$(this).attr('btitle')+'</nobr>');
		var fullW = $(document).width();
		var ballonW = $('.ballon').width();
		var curBallonRPos = e.clientX+ballonW+20;
		$('.ballon_rline').css('width', ballonW-13);
		if (curBallonRPos>fullW){var newBalPos = fullW-(ballonW+15);}else{var newBalPos = e.clientX-27;}
		$('.ballon').css('left',newBalPos);
		$('.ballon_arr').css('left',e.clientX);
		$('.ballon, .ballon_arr').css('display','block');
	}).bind('mouseleave',function(){
		$('.ballon_rline').css('width', 'auto');
		$('.ballon, .ballon_arr').css('display','none');
	}).bind('click', function(){return false;})
});
function vAlign(){
	var genHeight = $(document).height();
	var boxHeight = $('.whitebox_top').height();
	var Vmargin = (genHeight-boxHeight)/2;
	$('.whitebox_top').css('margin-top',Vmargin+'px');
}
YMaps.jQuery(window).load(function () {
	var map = new YMaps.Map(YMaps.jQuery("#YMapsID-056")[0]);
	map.setCenter(new YMaps.GeoPoint(37.730127,55.783293), 16, YMaps.MapType.MAP);
	map.addControl(new YMaps.Zoom());
	map.addControl(new YMaps.ToolBar());
	YMaps.MapType.PMAP.getName = function () { return "Народная"; };
	map.addControl(new YMaps.TypeControl([
		YMaps.MapType.MAP,
		YMaps.MapType.SATELLITE,
		YMaps.MapType.HYBRID,
		YMaps.MapType.PMAP
	], [0, 1, 2, 3]));

	YMaps.Styles.add("constructor#pmgnmPlacemark", {
		iconStyle : {
			href : "http://api-maps.yandex.ru/i/0.3/placemarks/pmgnm.png",
			size : new YMaps.Point(28,29),
			offset: new YMaps.Point(-8,-27)
		}
	});

   map.addOverlay(createObject("Placemark", new YMaps.GeoPoint(37.730985,55.783499), "constructor#pmgnmPlacemark", "Интерактивное агентство «Это Легко»"));
	
	function createObject (type, point, style, description) {
		var allowObjects = ["Placemark", "Polyline", "Polygon"],
			index = YMaps.jQuery.inArray( type, allowObjects),
			constructor = allowObjects[(index == -1) ? 0 : index];
			description = description || "";
		
		var object = new YMaps[constructor](point, {style: style, hasBalloon : !!description});
		object.description = description;
		
		return object;
	}
});
