var Map = {};
Map._officies = new  Array();
Map._apiKey = 'AJKYfEsBAAAAHsvDGwIAy_IFOrNN3TSUf-z3TtxmpBQPue8AAAAAAAAAAADlXuawFI6Pblo-tVzRQIpv57vI_Q==';//evgesha.me
Map._documentObject = 'YMapsID';
Map._defaultIcon = '//www.stildv.ru/sites/all/themes/tvoistil_theme/favicon.png';

Map._init =function()
{
    this._mapObject = new YMaps.Map(document.getElementById(Map._documentObject));
    this._mapObject.setType(YMaps.MapType.MAP);
    
    this._objManager = new YMaps.ObjectManager();
    this._mapObject.addOverlay(this._objManager);
    
    this._defaultMap();
    this._Toolbars();
}

Map._loadAPI =function()
{
    document.write('<script src="http://api-maps.yandex.ru/1.1/index.xml?key='+Map._apiKey+'" type="text/javascript"></script>');
}

Map._listOfficies =function()
{
    $('#office-list').text('');
}
Map._styleObject = function()
{

    var s = new YMaps.Style();
    s.iconStyle = new YMaps.IconStyle();
    s.iconStyle.href = "//www.oknarostadv.ru/images/favicon.ico";
    s.iconStyle.size = new YMaps.Point(16,16);
    s.iconStyle.offset = new YMaps.Point(-20, -15);
    s.balloonContentStyle = new YMaps.BalloonContentStyle(new YMaps.Template("<div class=\"office-mark\"><div class='title'>$[name]</div><div class='phone'>$[description]</div></div>"));
    return s;
}


Map._addOffice = function(options)
{
    s = Map._styleObject();
    s.iconStyle.href = (options.icon) ? options.icon : this._defaultIcon;
    var op = {draggable: false, style : s,hintOptions: {maxWidth: 100,offset: new YMaps.Point(5, 5)}};
 
    options._placemark = new YMaps.Placemark(options.point, op);
    options._placemark.description = options.address+"<br><b>тел.: </b>"+options.phone;
    options._placemark.name = options.name;
    this._mapObject.addOverlay(options._placemark); 
    
    this._officies.push(options);
}

Map._defaultMap =function()
{
    this._mapObject.setCenter(new YMaps.GeoPoint(135.075916,48.483007), 12);

}

Map._showOffice = function(num)
{
    //alert(this._officies[num].point);
    this._mapObject.setCenter(this._officies[num].point, this._officies[num].zoom);
    this._officies[num]._placemark.openBalloon();
}

Map._Toolbars =function()
{
    this._mapObject.addControl(new YMaps.Zoom());
    this._mapObject.addControl(new YMaps.ScaleLine());
    this._mapObject.addControl(new YMaps.ToolBar());
    this._mapObject.enableScrollZoom();

}

Map._loadAPI();
