jQuery(document).ready(function() {
	initMap();
});

function titleview(id, count){
	
	for (var i=1; i<=count; i++) {
		jQuery('#title_name_'+i).removeClass('active');
		jQuery('#title_content_'+i).removeClass('active');
	}
	
	jQuery('#title_name_'+id).addClass('active');
	jQuery('#title_content_'+id).addClass('active');
	
}

var mainGMapMarker;
var smallGMapMarker;

function initMap() {

	var map = new GMap2(document.getElementById('map'));
	map.setUIToDefault();
	
	map.setCenter(new GLatLng(55.776647,37.650704), 16);
//	map.setCenter(new GLatLng(55.775747,37.650704), 16);
	
//	if ( typeof(smallGMapMarker)=="undefined" ) {
//		new Infowin(new GLatLng(55.775312,37.645276)).initialize(map);
//	} else {
//		new Infowin2(new GLatLng(55.775312,37.645176)).initialize(map);
//	}
	mainGMapMarker=new Infowin(new GLatLng(55.775312,37.645276));
	smallGMapMarker=new Infowin2(new GLatLng(55.775312,37.645176));
	map.addOverlay( mainGMapMarker );
	map.addOverlay( smallGMapMarker );
	
	smallGMapMarker.hide();
	
	
//	marker = new GMarker( new GLatLng(55.775312,37.645276));
//	map.addOverlay(marker);
	
}




function Infowin(latlng, html) {
     this.latlng_ = latlng;
     this.html_ = html;
     this.prototype = new GOverlay();

     this.initialize = function(map) {

             var div = $('<div />');

             div.css({
            	 position : 'absolute',	
                     'width'     : '295px',  
                     'height'    : '248px'  
             }).appendTo(map.getPane(G_MAP_FLOAT_PANE));

             this.map_ = map;
             this.div_ = div;

             this.update(html);
     };

     this.update = function(html){
             this.html_ = html;

             this.div_.empty();

         //"<div style='width:184px;height:161px;background: url(images/infobox.png) no-repeat;'></div>")
             
             var content = $('<div></div>').addClass('infowin-content').css({
                     'position'  : 'relative',
                     'width'     : '295px',  
                     'height'    : '248px',  
                     'overflow'  : 'hidden',
                     'background-image': 'url('+contextPath+'/images/infobox.png)'
             });

             content.appendTo(this.div_);

             this.redraw(true);

     };

     this.remove = function() {
       this.div_.remove();
     };

     this.copy = function() {
       return new Infowin(this.latlng_, this.html_);
     };

     this.redraw = function(force) {
             if (!force) return;
             var point = this.map_.fromLatLngToDivPixel(this.latlng_);
             this.div_.css({
                     left : point.x- this.div_.width()/2+8,
                     top : point.y - this.div_.height()+12
             });
     };

     this.hide = function() {
     	this.div_.css({'display' : 'none'});
     };
     
     this.show = function() {
     	this.div_.css({'display' : ''});
     };
}

function Infowin2(latlng, html) {
    this.latlng_ = latlng;
    this.html_ = html;
    this.prototype = new GOverlay();

    this.initialize = function(map) {

            var div = $('<div />');

            div.css({
           	 position : 'absolute',	
                    'width'     : '44px',  
                    'height'    : '33px'  
            }).appendTo(map.getPane(G_MAP_FLOAT_PANE));

            this.map_ = map;
            this.div_ = div;

            this.update(html);
    };

    this.update = function(html){
            this.html_ = html;

            this.div_.empty();

        //"<div style='width:184px;height:161px;background: url(images/infobox.png) no-repeat;'></div>")
            
  
            
            var content = $('<div></div>').addClass('infowin-content').css({
                    'position'  : 'relative',
                    'width'     : '44px',  
                    'height'    : '33px',  
                    'overflow'  : 'hidden',
                    'background-image': 'url('+contextPath+'/images/365-minimarker.png)'
            });

            content.appendTo(this.div_);

            this.redraw(true);

    };

    this.remove = function() {
      this.div_.remove();
    };

    this.copy = function() {
      return new Infowin(this.latlng_, this.html_);
    };

    this.redraw = function(force) {
            if (!force) return;
            var point = this.map_.fromLatLngToDivPixel(this.latlng_);
            this.div_.css({
                    left : point.x- this.div_.width()/2+8,
                    top : point.y - this.div_.height()+12
            });
    };

    this.hide = function() {
    	this.div_.css({'display' : 'none'});
    };
    
    this.show = function() {
    	this.div_.css({'display' : ''});
    };
    
}
