var Maps = function(map){
	var _ = this;
	this.map = $(map);
    this.layer = null;
    this.infoLayer = null;
	this.pointSrc = '/i/map_img.png';
	this.point = [];
	this.showNow = null;
    this.hideTimer = null;
	this.createLayer = function(){
		var p;
		_.map.insert({before: new Element('div').setStyle({position:'relative',height: '0px'}).insert(
			p = new Element('div').setStyle({position:'absolute',width: _.map.getWidth()+'px' , height: _.map.getHeight()+'px'})
		)});
		_.layer = p;
		_.layer.insert(
			p = new Element('div').setStyle({position:'absolute',zIndex:998,display:'none',width:'257px'}).update('<div style="float: right; font-family: tahoma, sans-serif; font-size: 11px; color: #FFF; background: url(/i/map_alt_arr.png) no-repeat 0 0; padding-left: 37px;"><div style="width: 220px; background: url(/i/map_alt_bg1.png) no-repeat 0 0; behavior: url(/i/iepngfix.htc); height: 16px;">&nbsp;</div><div style="width: 192px; padding: 0 14px; background: url(/i/map_alt_bg2.png) repeat-y 0 0; behavior: url(/i/iepngfix.htc);"><h2 style="font-family: tahoma, sans-serif; font-size: 14px; margin-bottom: 5px;"> </h2><br /><br /><img src="/i/map_ico.gif" style="float: left; margin: 3px 5px 0 0;" /><a style="font-family: tahoma, sans-serif; font-size: 11px; color: #FFF;" href="mag_cart.html">Ñõåìà ïðîåçäà</a></div><div style="width: 220px; background: url(/i/map_alt_bg3.png) no-repeat 0 0; behavior: url(/i/iepngfix.htc); height: 16px;">&nbsp;</div></div>')
		);
		_.infoLayer = {obj:p, title: p.down('h2'), addr: p.down('h2').nextSibling, url: p.down('a')};
		_.infoLayer.title.up()
			.observe('mouseover',function(){if(_.hideTimer) clearTimeout(_.hideTimer);})
            .observe('mouseout',function(){_.hideTimer = setTimeout(function(){_.hide();},2000);})
	}
	this.setPoint = function(p,id){
		var s = p.split(',');if(s.length!=2){return false;}
		_.point[id] = {x:s[0]-12,y:s[1]-13,title:null,descript:null,url:null, dot: null}
		if($('d'+id)){
			_.point[id].title = $('d'+id).previous().innerHTML;
			_.point[id].descript = $('d'+id).firstChild.nodeValue;
			if($('d'+id).down('a')){
							_.point[id].url = $('d'+id).down('a').readAttribute('href');
			}
		}
		var p = new Element('img',{src: _.pointSrc}).setStyle({position:'absolute', left: _.point[id].x+'px', top: _.point[id].y+'px'});
		_.layer.insert(p);
		p.observe('mouseover',function(){_.showInfo(id);});
        p.observe('mouseout', function(){_.hideInfo(id);});
		_.point[id].dot = p;
	}
	this.showInfo = function(id){
		if(_.hideTimer) clearTimeout(_.hideTimer);
		var x = _.point[id].dot;x.setStyle({'zIndex':999});
		_.infoLayer.title.update(_.point[id].title);
        _.infoLayer.addr.nodeValue =_.point[id].descript;
        _.infoLayer.url.href  = _.point[id].url;

		_.infoLayer.obj.setStyle({left: (_.point[id].x+12)+'px', top: (_.point[id].y-30)+'px',display:'block'});
	}
	this.hideInfo = function(id){
		var x = _.point[id].dot; x.setStyle({'zIndex':2});
		_.hideTimer = setTimeout(function(){_.hide();},2000);
	}
	this.hide = function(){
		_.infoLayer.obj.setStyle({display:'none'});
	}
	_.createLayer();
}
