/**
 * @author yetik
 */
var Map = new Class({
	left_offset: 276,
	last_selected: null,
	
	initialize: function () {
		this.circles = new Array();
		$('mapka').getElements('.circle_small, .circle_big').each(function(item, k) {
			var address = $('addresses').getElements('.address')[k]
			this.circles.push(new Circle(item, address));
		}.bind(this))
		
		this.circles[3].light_on();
		this.circles[3].setSelected();
		this.circles[3].address.fade('show');
		this.last_selected = this.circles[3];
		
		this.circles.each(function(item) {
			
			item.item.addEvents({
				'mouseover': function () {
					item.light_on();
				},
				'mouseout': function () {
					item.light_off();
				},
				'click': function () {
					if (this.last_selected && this.last_selected != item) {
						this.last_selected.unSelect();
						this.last_selected.fadeOut();
					}
						
					item.setSelected();
					this.last_selected = item;
					item.fadeIn.delay(200, item);
				}.bind(this)
			})
		}.bind(this))
		
	}
	
})

var Circle = new Class ({
	selected: false,
	
	initialize: function (item, address) {
		this.item = item;
		this.address = address;
		this.address.fade('hide');
	
	},
	
	light_on: function () {
		this.item.addClass('over');
		
	},
	light_off: function () {
		if (!this.selected)
			this.item.removeClass('over')
	},
	setSelected: function () {
		this.selected = true
	},
	unSelect: function () {
		this.selected = false;
		this.light_off();
	},
	fadeIn: function () {
		this.address.fade('in')
	},
	fadeOut: function () {
		this.address.fade('out');
	}
})

window.addEvent ('domready', function () {
	try {
		new Map;
	} catch (e) {}
})