var Mapper = new Class.create({

	initialize: function() {
		$$('.mapa').each(this.initMapa.bind(this));
	},
	
	initMapa: function(element) {
		var address = element.down('.infoer').innerHTML;
		var container = element.down('.mapa-container');
		
		var map = new YMaps.Map(container);
		map.enableScrollZoom();
		var geocoder = new YMaps.Geocoder(address);
		
		var s = new YMaps.Style();
		s.iconStyle = new YMaps.IconStyle();
		s.iconStyle.href = "/cont/img/baloon.png";
		s.iconStyle.size = new YMaps.Point(45, 48);
		
		YMaps.Events.observe(geocoder, geocoder.Events.Load, function () {
			if (this.length()) {
				
				
				geoResult = this.get(0);
				map.setBounds(geoResult.getBounds());
				map.addOverlay(new YMaps.Placemark(
					geoResult.getGeoPoint(),{style: s}
				));
				return;
			}
		});
	}
});


var EgoistJs = new Class.create({
	
	qapage: 2,
	
	initialize: function() {
		
	},
	
	faqpage: function() {
		
		if ($$('.answer-switch').length==0) {
			return false;
		}
		
		document.on('click','.answer-switch',function(ev,element){
			element.up('.answer').addClassName('active');
		});
		
		$('showmoreqa').on('click',this.loadMoreQa.bind(this));
		
		if (m=window.location.hash.match(/#quest_(\d+)/)) {
			$('quest_'+m[1]).down('.answer').addClassName('active');
		}
	},
	
	loadMoreQa: function() {
		new Ajax.Request('/qa/more.jax',{
			method:'get',
			parameters: {p:this.qapage},
			onSuccess: function(t) {
				$('qa-reciever').insert(t.responseText);
				this.qapage++;
			}.bind(this)
		});
	}
});

document.observe('dom:loaded',function(){
	e = new EgoistJs();
	e.faqpage();	
});
