﻿/**
 * GeoMashup customization examples 
 * 
 * * The filename must be changed to custom.js for customizations to take effect.
 * * You can edit the examples and enable customizations you want.
 * * If you know javascript, you can add your own customizations using the Google Maps API
 *   documented at http://code.google.com/apis/maps/documentation/reference.html#GMap2
 *
 * Properties
 * A properties object is available in all custom functions, and has these useful
 * variables:
 * * properties.url_path - the URL of the geo-mashup plugin directory
 * * properties.template_url_path - the URL of the active theme directory
 * * properties.map_content - 'global', 'single', or 'contextual'
 * * properties.map_cat     - the category ID of a cateogory map
 *
 * The old custom-marker.js from pre-1.0 versions of Geo Mashup is no longer used.
 */

/* Waitt - Amelia */

var assets_path = "/wp-content/themes/waitt/images/mapnav_final/"; //path to image assets etc.

var lastMarkerClicked = null;


/**
 * Customize a Geo Mashup map after the relevant content has been loaded.
 *
 * @param properties the properties of the GeoMashup being customized
 * @param map        the Google Map object documented at http://code.google.com/apis/maps/documentation/reference.html#GMap2
 */
 

function customizeGeoMashupMap ( properties, map ) {

	// Load some KML only into global maps - for instance pictures of squirrels
	
	/* DELETE this line to enable this example
	if (properties.map_content == 'global') {
		var kml = new GGeoXml("http://api.flickr.com/services/feeds/geo/?g=52241987644@N01&lang=en-us&format=rss_200");
		map.addOverlay(kml);
	}
	DELETE this line to enable this example */

	// Recenter the map when displaying category ID 7
	
	/* DELETE this line to enable this example
	if (properties.map_cat == 7) {
		map.setCenter( new GLatLng(18.5,15.3), 3 );
	}
	
	
	DELETE this line to enable this example */
	
	//test greenwhich
	/*
	var point = new GLatLng( 0,0);
	var marker = new GMarker(point);
	map.addOverlay(marker);
	*/
	
	//map.addMapType(G_SATELLITE_3D_MAP);
	
	if (GeoMashup.opts.post_data.posts.length>0) {
	
		map.addControl(new TabbedMarkerNavControl());

	}
	

	/* Start Custom Sonar tile layer load - built with Microsoft MapCruncher */
 	
	var sonarSatMap = getSonarSatMapType();
  	map.addMapType(sonarSatMap); 
  	map.setMapType(sonarSatMap);
  	
}

function getSonarSatMapType() {
	var sonarHybridLayer = new Array(); 
 	sonarHybridLayer[0] = G_SATELLITE_MAP.getTileLayers()[0]; //comment this out to remove default sattelite map layer
 	sonarHybridLayer[1] = new GTileLayer(new GCopyrightCollection('') , 12, 19); 
 	sonarHybridLayer[1].getTileUrl = function (a,b) { 
 		return  "/wp-content/themes/amelia/sonar-tiles/Layer_NewLayer/" + TileToQuadKey(a.x,a.y,b) + ".png";  
 	};
 	sonarHybridLayer[1].getCopyright = function(a,b) {return "Waitt Institute for Discovery";}; 
 	sonarHybridLayer[1].getOpacity = function () {return 0.5;};//of the non transparent part sonar
 	if(navigator.userAgent.indexOf("MSIE") == -1) 
   		sonarHybridLayer[1].isPng = function() {return true;};

 	var sonarSatMap = new GMapType(sonarHybridLayer, G_SATELLITE_MAP.getProjection(), 'Sonar/Sat',{errorMessage:""}); 
 	sonarSatMap.getTextColor = function() {return "#FFFFFF";}; 

	return sonarSatMap;
}


/**
 * Provide a custom marker icon by color name. Since multiple categories can
 * be assigned to the same color in the Geo Mashup Options, this can be more
 * efficient than providing individual category icons.
 *
 * @param properties the properties of the GeoMashup object being customized
 * @param color_name the color_name assigned in the Geo Mashup Options
 * @return the custom GIcon
 */
function customGeoMashupColorIcon ( properties, color_name ) {
  var icon = null;
	
	// Make an icon for the color 'lime' from images in the geo-mashup/images directory
	
	/* DELETE this line to enable this example 
  if (color_name == 'fuchsia') {
    icon = new GIcon();
    icon.image = properties.url_path + '/images/my_lime_icon.png';
    icon.shadow = properties.url_path + '/images/my_shadow.png';
    icon.iconSize = new GSize(21, 31);
    icon.shadowSize = new GSize(51, 29);
    icon.iconAnchor = new GPoint(8, 31);
    icon.infoWindowAnchor = new GPoint(8, 1);
  }
	DELETE this line to enable this example */

  return icon;
}

/**
 * Provide a custom marker icon by category names.
 *
 * @param properties the properties of the GeoMashup object being customized
 * @param categories the array of category names assigned to post being marked
 * @return the custom GIcon
 */
function customGeoMashupCategoryIcon ( properties, categories ) {
    var icon = new GIcon(G_DEFAULT_ICON);
	
	var catID = categories;
	if (GeoMashup.opts.map_cats) {
		return icon = getCategoryMarkerIcon(catID, "");
	} else return null;
		
//		icon.shadow = properties.url_path + '/images/my_shadow.png';
//		icon.iconSize = new GSize(21, 31);
//		icon.shadowSize = new GSize(51, 29);

//		icon.infoWindowAnchor = new GPoint(8, 1);
		//mylog(icon);
		
/*
  if (categories[0] == 230) {
    icon = new GIcon();
    icon.image = properties.url_path + '/images/mm_20_maroon.png';
    icon.shadow = properties.url_path + '/images/my_shadow.png';
    icon.iconSize = new GSize(21, 31);
    icon.shadowSize = new GSize(51, 29);
    icon.iconAnchor = new GPoint(8, 31);
    icon.infoWindowAnchor = new GPoint(8, 1);
  }
*/
	// Make an icon for posts assigned to multiple categories
	// using images from the current template directory
/*

  if (categories.length > 1) {
    icon = new GIcon();
    icon.image = properties.url_path + '/images/mm_20_maroon.png';
    icon.shadow = properties.url_path + '/images/my_shadow.png';
    icon.iconSize = new GSize(21, 31);
    icon.shadowSize = new GSize(51, 29);
    icon.iconAnchor = new GPoint(8, 31);
    icon.infoWindowAnchor = new GPoint(8, 1);
  }

  var i = categories.length;
  while (i--) {
      if (categories[i] == 230) {
          icon = new GIcon();
          icon.image = properties.url_path + '/images/mm_20_aqua.png';
          icon.shadow = properties.url_path + '/images/my_shadow.png';
          icon.iconSize = new GSize(10, 15);
          icon.shadowSize = new GSize(25, 15);
          icon.iconAnchor = new GPoint(5, 20);
          icon.infoWindowAnchor = new GPoint(8, 1);
      }
  }
*/
  return icon;
}

function getCategoryMarkerIcon(thisCategoryID) {

	var icon = new GIcon(G_DEFAULT_ICON);

	var categoryIndex = null;
		if (GeoMashup.opts.map_cats) {
		for (j=0;j<GeoMashup.opts.map_cats.length;j++) {
		
			if (GeoMashup.opts.map_categories[j].term_id==thisCategoryID)
				categoryIndex = j;
			
		}
		
		var markerCatIndex = 0;
		for (j=0;j<GeoMashup.opts.map_cats.length;j++) {
				markerCatIndex = categoryIndex;
				//add members to make it easier to select the right marker class
				GeoMashup.opts.map_categories[categoryIndex].marker_class = GeoMashup.opts.map_cat_marker[j];
				if (GeoMashup.opts.map_cat_marker[markerCatIndex]) {
					icon = getMapNavMarkerIcon(GeoMashup.opts.map_cat_marker[categoryIndex]);
				}
				
				//mylog("markerClass = " + GeoMashup.opts.map_categories[categoryIndex].marker_class);
	
		}
		
	return icon;
	}
	
	return null;
}

/*
function getMapNavMarkerIcon(markerClass, status) {

	var icon = new GIcon(G_DEFAULT_ICON);
	
	var topOffset = 0;
	var path = "/wp-content/themes/waitt/images/mapnav_final/";
	
	icon.iconAnchor = new GPoint(9 ,10);

	switch (markerClass) {
		case "circle":
			topOffset = 20
			break;
		case "triangle":
			topOffset = 40		
			break;
		case "star":
			topOffset = 60
			break;
		default:
			markerClass = "square";
	}
	
    icon.iconSize = new GSize(18, 20);

	if (status == "" || status == null)
		imageFile = 'markers.png';
	else if (status=="active")
		imageFile = 'markers_here.png';
		
	icon.sprite = {image:path + imageFile, width:18, height:20, top:topOffset, left:0}
	
	icon.shadow = path+"shadow-"+markerClass+".png";
	
	icon.shadowSize = new GSize(25, 25);

	return icon;
}
*/

function getMapNavMarkerIcon(markerClass, status) {

	var icon = new GIcon(G_DEFAULT_ICON);
	
	var topOffset = 0;
	
	

	switch (markerClass) {
		case "circle":
			//topOffset = 20
			break;
		case "triangle":
			//topOffset = 40		
			break;
		case "star":
			//topOffset = 60
			break;
		default:
			markerClass = "";
	}
	if (markerClass!="") {
		icon.iconAnchor = new GPoint(9 ,10);
		
		icon.iconSize = new GSize(18, 20);
	
		if (status == "" || status == null)
			imageFile = markerClass+'.png';
		else if (status=="active")
			imageFile = markerClass+'_here.png';
			
		icon.image = assets_path+imageFile;
		
		icon.shadow = assets_path+"shadow-"+markerClass+".png";
		
		icon.shadowSize = new GSize(25, 25);
	}
	return icon;
}

function getMapNavMarkerImagePath(markerClass, status) {


	switch (markerClass) {
		case "circle":
			break;
		case "triangle":
			break;
		case "star":
			break;
		default:
			markerClass = "";
	}
	if (markerClass!="") {
		if (status == "" || status == null)
			imageFile = markerClass+'.png';
		else
			imageFile = markerClass+'-on.png';
			
		return assets_path + imageFile;
	} else return "";
}

function getMapNavMarkerImagePathFromOldPath(oldImageFilePath, status) {

	var file = oldImageFilePath.replace(assets_path,"");
	var markername_part = file.replace(".png","").replace("_here","");
	
	return getMapNavMarkerImagePath(markername_part, status);

}

/**
 * Provide a custom marker for single post maps.
 *
 * @param properties the properties of the GeoMashup object being customized
 * @return the custom GIcon
 */
function customGeoMashupSinglePostIcon ( properties ) {
	var icon = null;
  
	// Use the Google 'A' icon instead of the default

	/* DELETE this line to enable this example 
	icon = new GIcon(G_DEFAULT_ICON);
	icon.image = 'http://www.google.com/mapfiles/markerA.png';
	DELETE this line to enable this example */

	return icon;
}
	
/**
 * Provide a custom marker for locations with multiple posts.  The marker icon 
 * already exists when we discover more posts there, so we just change the image. 
 *
 * @param properties the properties of the GeoMashup object being customized
 * @return the custom GIcon
 */
function customGeoMashupMultiplePostImage ( properties, current_image ) {
	var image = null;

	// Replace multiple post icons only when the current image is in the format 
	// my_*.png, where the asterisk can be any letters.

	/* DELETE this line to enable this example 
	if (current_image.search(/my_\w*.png/) >= 0) {
		image = properties.template_url_path + '/images/my_plus.png';
	}
	DELETE this line to enable this example */

  return image;
}
		
		/* GeoMashup Override */
		
		GeoMashup.getPostFromPoint = function (point) {
		//TODO - Refactor custom createMarker override to work with multiple posts on the same point
			for(i=0; i<GeoMashup.locations[point].posts.length; i++) {
					
					//switch the nav bar accordion tab accordingly
					return GeoMashup.locations[point].posts[i];
						
			}
		}

		GeoMashup.setCurrentTab = function (categoryId, post_id) {
			
				//if (GeoMashup.opts.tab_categories)
				//detect the correct index of the post that the tab is referring to
				try {
				if (tabStopAPI)
					for (i = 0; i < tabStopAPI.length; i++)
					{
						for (ii = 0; ii < tabStopAPI[i].getTabs().length; ii++) {
						
							if ( tabStopAPI[i].getTabs()[ii].getAttribute("postId") == post_id && tabStopAPI[i].getIndex()!=ii) {
									markerJustClicked = true;
									tabStopAPI[i].click(ii);
								
								if( mapNavTabsAPI.getIndex()!=i  ) 
								{
									mapNavTabsAPI.click(i);
									//mylog("switch category tab index = "+i);
								}
							}
						
						}
						
					}
					
					} catch (ex) {
					}
					
					
				return false;	
				
		}
		
		// Infowin class for displaying a miniature info window. Does not
		// respond to any events - so you should show and remove the
		// overlay yourself as necessary.
		
		function WaittInfowin(latlng, html) {
			this.latlng_ = latlng;
			this.html_ = html;
			this.prototype = new GOverlay();
			
			var offsetY = 28;
			var offsetX = 265;
			
			// Creates the DIV representing the infowindow
			this.initialize = function(map) {
			this.map_ = GeoMashup.map;
		
			var div = document.createElement('div');
			this.div_ = div;
			
				div.id = 'waittinfo';
		
				var point = this.map_.fromLatLngToDivPixel(this.latlng_);
				div.style.top = (point.y - offsetY) + 'px';
				div.style.left = (point.x - offsetX) + 'px';
		
				var hdiv = document.createElement('div');
				this.hdiv_ = hdiv;
				
				var img = document.createElement('img');
				this.img_ = img;
				img.style.marginTop = '-5px';
				img.src='images/overlay_bottom.png';
			
				this.div_.appendChild(hdiv);
				//this.div_.appendChild(img);
		
			GeoMashup.map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
		
			this.update(this.html_);
			}
			
			this.update = function(html){
			this.html_ = html;
			this.hdiv_.innerHTML = html;
		
			this.redraw(true);
			}
			
			// Remove the main DIV from the map pane
			this.remove = function() {
			try {
				GeoMashup.map.getPane(G_MAP_FLOAT_PANE).removeChild(this.div_);		
			} catch (e) {
			}
			// this.div_.removeChild(this.hdiv_);  
			// this.div_.removeChild(this.img_);
		  }
		
			// Copy our data to a new instance
			this.copy = function() {
			return new Infowin(this.latlng_, this.html_);
			}
			
			// Redraw based on the current projection and zoom level
			this.redraw = function(force) {
			if (!force) return;
				
				this.map_.panTo(this.latlng_);
				var point = this.map_.fromLatLngToDivPixel(this.latlng_);
				this.div_.style.top = (point.y - offsetY) + 'px';
				this.div_.style.left = (point.x - offsetX) + 'px';
			}
		}


		// Override default JSON createMarker function
		GeoMashup.clickMarker = function(post_id, try_count) {
			
			if (typeof(try_count) == 'undefined') {
				try_count = 1;
			}
			if (this.posts[post_id] && try_count < 4) {
				if (GeoMashup.posts[post_id].marker.isHidden()) {
					try_count++;
					setTimeout(function () { 
						GeoMashup.clickMarker(post_id, try_count);
					}, 300);
				} else {
					GEvent.trigger(GeoMashup.posts[post_id].marker,"click"); 
					//GeoMashup.setCurrentTab("",post_id);
		
		
					//set all markers to inactive state since only one should be active at any time just like info windows
					//for (pid in GeoMashup.posts) {
					if (lastMarkerClicked!=null) {
						hoveroffimage=getMapNavMarkerImagePathFromOldPath(lastMarkerClicked.getIcon().image, "");
						lastMarkerClicked.setImage(hoveroffimage);
					} //} 
					
					//set the current marker as active state
					hoverimage=getMapNavMarkerImagePathFromOldPath(GeoMashup.posts[post_id].marker.getIcon().image, "here");
					GeoMashup.posts[post_id].marker.setImage(hoverimage);                    
							
					lastMarkerClicked = GeoMashup.posts[post_id].marker;     
					
				}
				
			}
			
		};
		// Override default JSON createMarker function
		GeoMashup.clickMarkerOnly = function(post_id, try_count) {
			
			if (typeof(try_count) == 'undefined') {
				try_count = 1;
			}
			if (this.posts[post_id] && try_count < 4) {
				if (GeoMashup.posts[post_id].marker.isHidden()) {
					try_count++;
					setTimeout(function () { 
						GeoMashup.clickMarkerOnly(post_id, try_count);
					}, 300);
				} else {
					GEvent.trigger(GeoMashup.posts[post_id].marker,"click"); 
					//GeoMashup.setCurrentTab("",post_id);
					
					//set all markers to inactive state since only one should be active at any time just like info windows
					//for (pid in GeoMashup.posts) {
					if (lastMarkerClicked!=null) {
						hoveroffimage=getMapNavMarkerImagePathFromOldPath(lastMarkerClicked.getIcon().image, "");
						lastMarkerClicked.setImage(hoveroffimage);
					} //} 
					
					//set the current marker as active state
					hoverimage=getMapNavMarkerImagePathFromOldPath(GeoMashup.posts[post_id].marker.getIcon().image, "here");
					GeoMashup.posts[post_id].marker.setImage(hoverimage);                    
							
					lastMarkerClicked = GeoMashup.posts[post_id].marker;     
					
					
				}
				
			}
			
		};

		// Override default JSON createMarker function
		GeoMashup.createMarker = function(point,post) {
		
		var marker_opts = {title:post.title};
		if ( !post.icon ) {
			this.addObjectIcon( post );
		}
		marker_opts.icon = post.icon;

		
		if (!marker_opts.icon) {
			if (post.categories.length > 1) {
				marker_opts.icon = new GIcon(this.multiple_category_icon);
			} else {
				marker_opts.icon = new GIcon(this.categories[post.categories[0]].icon);
			}
		}

		var marker = new GMarker(point,marker_opts);
				
		// Switch icon on marker mouseover and mouseout
        GEvent.addListener(marker, "mouseover", function() {
		  hoverimage=getMapNavMarkerImagePathFromOldPath(marker.getIcon().image, "here");
		  marker.setImage(hoverimage);

    	});
        GEvent.addListener(marker, "mouseout", function() {
		  hoveroutimage=getMapNavMarkerImagePathFromOldPath(marker.getIcon().image, "");
		  marker.setImage(hoveroutimage);

        });

		// Show this markers index in the info window when it is clicked
		GEvent.addListener(marker, "click", function() {
			// hide open WaittInfowin
            if (GeoMashup.overlay) {
                GeoMashup.map.removeOverlay(GeoMashup.overlay);
            }

            //update the nav bar elements accordingly
            GeoMashup.setCurrentTab("",GeoMashup.getPostFromPoint(point));
                    
                    
			var post_ids, i, url, info_window_request, post_element, post_request;
			//GeoMashup.map.closeInfoWindow();
			// just recording this for use in the closeOverlay function
		    if (GeoMashup.locations[point].loaded) {
			if (GeoMashup.opts.show_post && GeoMashup.getShowPostElement()) {
			    GeoMashup.getShowPostElement().innerHTML = GeoMashup.locations[point].post_html;
			}
                GeoMashup.overlay = new WaittInfowin(point, GeoMashup.locations[point].info_node.innerHTML);
                GeoMashup.map.addOverlay(GeoMashup.overlay);

            } else {
                GeoMashup.overlay = new WaittInfowin(point, '<div class="bucket"><div class="head" style="height: 15px;" align="center"><h2><img src="' + GeoMashup.opts.url_path + '/images/busy_icon.gif" alt="Loading..." /></h2></div></div>');
                GeoMashup.map.addOverlay(GeoMashup.overlay);
                        
				post_ids = '';
				
				for(i=0; i<GeoMashup.locations[point].posts.length; i++) {
					if (i>0) post_ids += ',';
					post_ids += GeoMashup.locations[point].posts[i];

				}
				url = GeoMashup.opts.url_path + '/geo-query.php?post_ids=' + post_ids;
				info_window_request = new GXmlHttp.create();
				info_window_request.open('GET', url, true);
				info_window_request.onreadystatechange = function() {
					var node, links, i;
					if (info_window_request.readyState == 4 && info_window_request.status == 200) {
						node = document.createElement('div');
						node.innerHTML = info_window_request.responseText;
						links = node.getElementsByTagName('a');
						for (i=0; i<links.length; ++i) {
							links[i].onclick = function () { return GeoMashup.directLink(this); }
						}
						GeoMashup.locations[point].info_node = node;
						GeoMashup.locations[point].loaded = true;
						
						  GeoMashup.overlay.update(GeoMashup.locations[point].info_node.innerHTML);
                              
						
						if (GeoMashup.opts.show_post && 'full-post' !== GeoMashup.opts.template && GeoMashup.getShowPostElement()) {
							url += '&template=full-post';
							post_request = new GXmlHttp.create();
							post_request.open('GET', url, true);
							post_request.onreadystatechange = function() {
								if (post_request.readyState == 4 && post_request.status == 200) {
									GeoMashup.getShowPostElement().innerHTML = post_request.responseText;
									GeoMashup.locations[point].post_html = post_request.responseText;
								} // end readystate == 4
							}; // end onreadystatechange function
							post_request.send(null);
						}
					} // end readystate == 4
				}; // end onreadystatechange function
				info_window_request.send(null);
				
			} // end post not loaded yet 
		}); // end marker click

		GEvent.addListener(marker, 'infowindowclose', function() {
			var post_element = GeoMashup.getShowPostElement();
			if (post_element) {
				post_element.innerHTML = '';
			}
		});

		
		return marker;
	}
	
	
	function TileToQuadKey ( x, y, zoom){ 
	    var quad = ""; 
	    for (var i = zoom; i > 0; i--){
	        var mask = 1 << (i - 1); 
	        var cell = 0; 
	        if ((x & mask) != 0) 
	            cell++; 
	        if ((y & mask) != 0) 
	            cell += 2; 
	        quad += cell; 
	    } 
	    return quad; 
	}


	function TabbedMarkerNavControl(categoryId) {
		this.categoryId = categoryId;
		this.mode = '';
		
	  	if (categoryId==null)
			this.mode = 'category';			
		else 
			this.mode = 'category';
	
    }
    
    TabbedMarkerNavControl.prototype = new GControl();

    TabbedMarkerNavControl.prototype.initialize = function(map) {
    
      if (parent)
      if (!parent.document.getElementById(GeoMashup.opts.nav))
      	return null;
      	
      var container = document.createElement("div");
	  
	  if (parent.document && parent.document.getElementById(GeoMashup.opts.nav)) {

		var count = 0;
		 
		//var tabs = document.createElement("div");
		  
		//container.appendChild(tabs);
		GeoMashup.opts.tab_categories = new Array();
		GeoMashup.opts.tab_posts = new Array();
		html=GenerateMapNavHTML(GeoMashup.opts.tab_categories, GeoMashup.opts.tab_posts, GeoMashup.opts.map_categories, GeoMashup.posts, jQuery("#"+GeoMashup.opts.nav, parent.document.body).attr("timeline"));

		jQuery(container).append(html);

		parent.document.getElementById(GeoMashup.opts.nav).appendChild(container);
       	
		jQuery(document).ready(function() { 
				 //enable category tabs with jquery.tools scrollable
				targetFrame = parent.document.body;//window.parent.document;
				
				//position the map nav control to match the mockups
				
				//jQuery('*',targetFrame).size();
				var panes = jQuery("#"+GeoMashup.opts.nav + " .pane", targetFrame);
				mapNavTabsAPI = jQuery("#"+GeoMashup.opts.nav + " ul.tabs", targetFrame).tabs(panes, {api: true, current: 'here'});
				
				inc=0;
				for ( var cat in GeoMashup.opts.map_categories ) {
					var tabStopPanes = jQuery("#"+GeoMashup.opts.nav + " .pane:eq(0) .timeline-panes > .tap-stop-pane", targetFrame);
					tabStopAPI[inc] = jQuery("#"+GeoMashup.opts.nav + " ul.map-nav-tab-stops:eq("+inc+")", targetFrame).tabs(tabStopPanes, {api: true, current: 'active'});
					buildTabStopStepScroll(tabStopAPI, inc);
					inc++;
				}
				
				//set the default marker to the first category tab's first stop
				GeoMashup.clickMarker(tabStopAPI[0].getCurrentTab()[0].getAttribute("postid"));
				
				mapNavTabsAPI.onClick( function(tabs, index) {
					//take them to the correct marker
					
					//prevent infinite recursion
					if (!markerJustClicked) {
						GeoMashup.clickMarkerOnly(tabStopAPI[index].getCurrentTab()[0].getAttribute("postId"));
						
						//updateScrollLeftRightNav(tabStopAPI[tabStopAPIIndex]);
						//updateNextPrevNav(tabStopAPI[tabStopAPIIndex]);
						
					} else {
						markerJustClicked = false;
					}
					return false;
				});
				
				jQuery("#"+GeoMashup.opts.nav, targetFrame).css("visibility","visible");
				jQuery("#"+GeoMashup.opts.nav, targetFrame).fadeIn();
				
				mapId = jQuery("#"+GeoMashup.opts.nav, targetFrame).attr("map");
				if (mapId!="") {
					jQuery("#"+GeoMashup.opts.nav, targetFrame).css("top", jQuery("#"+mapId, targetFrame).height() - jQuery("#"+GeoMashup.opts.nav, targetFrame).height()-60);				
					jQuery("#"+GeoMashup.opts.nav, targetFrame).css("left", jQuery("#"+mapId, targetFrame).width() - jQuery("#"+GeoMashup.opts.nav, targetFrame).width()-120);				
				}


				
		 });

      }
       
      return container;
     
    }

    // By default, the control will appear in the top left corner of the
    // map with 7 pixels of padding.
    //TabbedMarkerNavControl.prototype.getDefaultPosition = function() {
    //  return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(7, 7));
    //}

    // Sets the proper CSS for the given button element.
    TabbedMarkerNavControl.prototype.setButtonStyle_ = function(button) {
      //button.style.textDecoration = "none";
      //button.style.color = "#0000cc";
      //button.style.backgroundColor = "white";
      //button.style.font = "small Arial";
      //button.style.border = "1px solid black";
      //button.style.padding = "2px";
      //button.style.marginBottom = "3px";
      //button.style.textAlign = "center";
      //button.style.width = "6em";
      //button.style.cursor = "pointer";
    }


String.prototype.convertHTMLEntity = function () {
	var myString = this;
	myString = myString.replace( /\&amp;/g, '&' );
	myString = myString.replace( /\&lt;/g, '<' );
	myString = myString.replace( /\&quot;/g, '"' );
	myString = myString.replace( /\&copy;/g, '©' );
	myString = myString.replace( /\&reg;/g, '®' );
	myString = myString.replace( /\&laquo;/g, '«' );
	myString = myString.replace( /\&raqou;/g, '»' );
	myString = myString.replace( /\&apos;/g, "'" );
	return myString;
}

function in_array (needle, haystack, argStrict) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true
    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
 
    var key = '', strict = !!argStrict;
 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }
 
    return false;
}



