/**
 * 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.custom_url_path - the URL of the geo-mashup-custom 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
 *
 * Actions
 * Customization is achieved by adding "actions" to Geo Mashup. Currently, these actions
 * are available:
 *
 * newMap, clusterOptions, singleMarkerOptions, objectMarkerOptions, marker, categoryIcon, multipleIcon, 
 * categoryLine, loadedMap
 */

 

/**
 * Customize a Geo Mashup map before it is configured or loaded with markers. 
 *
 * @param object properties the properties of the GeoMashup being customized
 * @param google.maps.Map2 map        the Google Map object documented at http://code.google.com/apis/maps/documentation/reference.html#GMap2
 */

GeoMashup.addAction( 'loadedMap', function( properties, map ) 
{
	var mappe_tematiche = percorsi['cat-mappe-tematiche'];
	var mappe_luoghi = percorsi['cat-mappe-luoghi'];
	
	var mappa_type = percorsi['type'];
	
	if(mappa_type == 'global')
	{
		for (var i in mappe_tematiche)
		{
			GeoMashup.hideCategory(mappe_tematiche[i]);
		}
		for (var i in mappe_luoghi)
		{
			GeoMashup.hideCategory(mappe_luoghi[i]);
		}
		
	}
	GeoMashup.clickMarker(window.percorsi['post-last'],1);
	//console.log(window.percorsi['post-last']);
} );





GeoMashup.addAction( 'selectedMarker', function ( properties, marker , map ) 
{
} );






GeoMashup.addAction( 'markerInfoWindowOptions', function ( properties, loc , window_opts ) 
{
	for (first in loc.cache) break;
	var node = loc.cache[first].info_node;
	var infoOptions = new Object();
	var infoTabs = new Array();
	

	infoOptions.maxWidth = 300;
	infoTabs[0] = new GInfoWindowTab('Post', node.getElementsByTagName('div')[0]);
	
	if(node.getElementsByTagName('div')[1].getElementsByTagName('img')[0] != null)
	{
		infoTabs[1] = new GInfoWindowTab('Multimedia', node.getElementsByTagName('div')[1] );
	}
	loc.marker.bindInfoWindowTabs(infoTabs, infoOptions);
	GeoMashup.map.updateInfoWindow(infoTabs);
} );


GeoMashup.addAction( 'objectMarkerOptions', function( properties, options, obj ) 
{    
	
  if (obj.categories.length > 1) {
  	for (var i in obj.categories)
  	{
		//CATEGORIE MULTIPLE
  		//Esclusione cat 68 -> "In evidenza"
  		if(obj.categories[i] != 68)
  		{
  			//console.log(i);
  		
  			var category_id = obj.categories[i];
  			var iconSize = new google.maps.Size(25, 25);
  			var iconPos = new google.maps.Point(8, 31);
  			var infoWindowPos = new google.maps.Point(12, 0);
  			var image = properties.template_url_path + '/images/maps/cat'+category_id+'.png';
  			
  			options.icon.image =image;
  			options.icon.iconSize = iconSize;
  			options.icon.iconAnchor = iconPos;
  			options.icon.infoWindowAnchor = infoWindowPos;
  		}
  	}
  }
  else 
  {
  	//CATEGORIA SINGOLA
	  var category_id = obj.categories[0];
	  //console.log(category_id);
	  var iconSize = new google.maps.Size(25, 25);
	  var iconPos = new google.maps.Point(8, 31);
	  var infoWindowPos = new google.maps.Point(12, 0);
	  var image = properties.template_url_path + '/images/maps/cat'+category_id+'.png';
	  
	  options.icon.image =image;
	  options.icon.iconSize = iconSize;
	  options.icon.iconAnchor = iconPos;
	  options.icon.infoWindowAnchor = infoWindowPos;
  }
} );




