
Project = {}
Project.activeMarker = null;
Project.icon = null;
Project.gmap = null;
Project.markers = new Array;
//Project.projects = new Array;
Project.googlemapLoaded = false;

Project.loadMap = function () {
	if (GBrowserIsCompatible()) {
     	Project.gmap = new GMap2(document.getElementById("map"));
		Project.gmap.setCenter(new GLatLng(52.31, 4.95), 8);
        Project.gmap.addControl(new GLargeMapControl());
        Project.gmap.addControl(new GMapTypeControl());
        Project.gmap.addControl(new GScaleControl());
      	Project.gmap.setMapType(G_SATELLITE_MAP);
      	
      	Project.icon = new GIcon (G_DEFAULT_ICON);
		Project.icon.image = '/gfx/icons/gm-pointer.png';
		Project.icon.iconSize = new GSize(26, 33);
    }
}

Project.addProjectMarker = function (id, title, lat, lng) {
	var marker = Project.addMarker(id, title, lat, lng, Project.icon);
	Project.markers.push(marker);
}

Project.addMarker = function (id, title, lat, lng, icon) {
    var marker = new GMarker(new GLatLng(lat, lng), icon );
    GEvent.addListener(marker,"click", function () {
      	var el = document.getElementById('project_' + id).getElementsByTagName('a')[0];
      	return hs.htmlExpand(el, { anchor: 'center', contentId: 'projectInfo', outlineType: 'rounded-white', outlineWhileAnimating: true, objectType: 'ajax', preserveContent: true } );
    });
    
    GEvent.addListener(marker, "mouseover", function () {
    	Project.activeMarker = this;
    	this.overlay = new InfoBox(this, 24, -7, 10, title);
    	Project.gmap.addOverlay(this.overlay);
    });
    
    GEvent.addListener(marker, "mouseout", function () {
    	if (Project.activeMarker){
			Project.gmap.removeOverlay(Project.activeMarker.overlay);
		}
    });
    
    Project.gmap.addOverlay(marker);
    return marker;
}

Project.clearMap = function () {
	for (var i = 0; i < Project.markers.length; i++) {
		Project.gmap.removeOverlay(Project.markers[i]);
	}
}

Project.loadImage = function (objEl, project_id) {
    var image = document.getElementById('image'+objEl.id+'_'+project_id);    
    var newsrc = image.getAttribute("largeimage");
    var large_image = document.getElementById('projectVisualLarge1_' + project_id);
    
    large_image.src = newsrc;
    
    var caption = document.getElementById('visualCaption_' + project_id);
    
    //alert(caption);
    //alert(caption.innerHTML);
    //alert(image.getAttribute("desc"));
    
    caption.innerHTML = image.getAttribute("desc");
}

/*
Project.loadProject = function (clickedEl, id) {
	var el = $('projectInfo');
	
    var url = '../getproject.php?id=' + id;
	new Ajax(url, { method: 'get', 
      				update: el,
                 	onComplete: function() {
                        load_fonts();
                        hs.htmlExpand(clickedEl, { anchor: 'center', contentId: 'projectInfo', outlineType: 'rounded-white', outlineWhileAnimating: true, preserveContent: true } );
                        if(expander != null){
                            var expander = hs.getExpander(el);
      					    expander.reflow(); // Reflows and recalculates the size of a HTML expander after the content is changed dynamically. 
                        }else{
                            return false;
                        }						
                      } 
               		}).request();					
}
*/

Project.loadProjectVideo = function (clickedEl, id) {
	var el = $('highslide-html');
    var url = '../getprojectvideo.php?id=' + id;
	new Ajax(url, { method: 'get', 
      				update: el,
                 	onComplete: function() {
                        load_fonts();
         				hs.htmlExpand(clickedEl, { anchor: 'top left', swfObject: so, contentId: 'highslide-html', allowSizeReduction: false, outlineType: 'rounded-white', outlineWhileAnimating: true, preserveContent: true} )
						var expander = hs.getExpander(el);
      					expander.reflow(); // Reflows and recalculates the size of a HTML expander after the content is changed dynamically. 
                      } 
               		}).request();	
} 

/*
Project.loadProjectVideoWithId = function (id, video_id) {
	var el = $('projectFlash');
    var url = '../getprojectvideo.php?id=' + id + '&video_id=' + video_id;
	new Ajax(url, { method: 'get', 
      				update: el,
                 	onComplete: function() {
                        load_fonts();
         				hs.htmlExpand(el, { anchor: 'top left', swfObject: so, contentId: 'projectFlash', allowSizeReduction: false, outlineType: 'rounded-white', outlineWhileAnimating: true, preserveContent: false} )
						var expander = hs.getExpander(el);
      					expander.reflow(); // Reflows and recalculates the size of a HTML expander after the content is changed dynamically. 
                      } 
               		}).request();	
}
*/

/*** INFOBOX - START ***/
function InfoBox(marker,divHeight, anchorOffsetX, anchorOffsetY, divHtml) {
    this.marker = marker;
    this.divHeight = divHeight;
    this.anchorOffsetX = anchorOffsetX;
    this.divHtml = divHtml
    if (null == this.anchorOffsetX){
        this.anchorOffsetX = 0;
    }

    this.anchorOffsetY = anchorOffsetY;

    if (null == this.anchorOffsetY){
        this.anchorOffsetY = 0;
    }

}

//InfoBox.prototype = new GOverlay();

InfoBox.prototype.initialize = function(map) {
    var div = document.createElement("div");
    div.style.position = "absolute";
	div.style.height = this.divHeight + "px";
    div.style.left 	= (map.fromLatLngToDivPixel(this.marker.getPoint()).x - this.anchorOffsetX)+ 'px';
    div.style.top 	= (map.fromLatLngToDivPixel(this.marker.getPoint()).y - this.divHeight - this.anchorOffsetY) + 'px';
	
	div.style.background = "url('/gfx/icons/gm-pointer-extend.png') no-repeat top right";
	div.style.padding = "3px 16px 0px 4px";
	div.style.fontFamily = "Verdana, sans-serif;";
	div.style.fontSize = "10px";
	div.style.color = "#FFFFFF";
	
	// div.onmouseout = this.setInterval;
	// div.onmouseover = this.clearInterval;
	
	div.style.whiteSpace = "nowrap";
	
    div.innerHTML = this.divHtml	
	
    Project.gmap.getPane(G_MAP_FLOAT_PANE).appendChild(div);
    this.map_ = Project.gmap;
    this.div_ = div;
}

InfoBox.prototype.remove = function() {
    this.div_.parentNode.removeChild(this.div_);
}

InfoBox.prototype.redraw = function(force) {
    this.div_.style.left 	= (this.map_.fromLatLngToDivPixel(this.marker.getPoint()).x - this.anchorOffsetX)+ 'px';
    this.div_.style.top = (this.map_.fromLatLngToDivPixel(this.marker.getPoint()).y - this.divHeight - this.anchorOffsetY) + 'px';
}
/*** INFOBOX - END ***/
