

var JSONLoader={};
JSONLoader.counter=0;
JSONLoader.read=function(B,C){
	var D="_"+JSONLoader.counter++;
	JSONLoader[D]=function(E){C(E)};
	var A=document.createElement("script");
	A.src=B+"JSONLoader."+D;
	document.body.appendChild(A)
	};
	var Metaweb={};
	Metaweb.HOST="http://www.freebase.com";
	Metaweb.QUERY_SERVICE="/api/service/mqlread";
	Metaweb.counter=0;
	Metaweb.read=function(E,D){
		var F="_"+Metaweb.counter++;
		Metaweb[F]=function(J){
			var I=J.qname;
			if(I.code.indexOf("/api/status/ok")!=0){
				var H=I.messages[0];
				throw H.code+": "+H.message
			}
				var G=I.result;
				document.body.removeChild(A);
				delete Metaweb[F];
				D(G)
		};
		envelope={qname:{query:E}};
		var C=encodeURIComponent(JSON.serialize(envelope));
		var B=Metaweb.HOST+Metaweb.QUERY_SERVICE+"?queries="+C+"&callback=Metaweb."+F;
		var A=document.createElement("script");
		A.src=B;
		document.body.appendChild(A)};
		var JSON={};
		JSON.parse=function(s){
			try{
				return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(s.replace(/"(\\.|[^"\\])*"/g,"")))&&eval("("+s+")")}catch(e){
					return false
					}
				};
				(function(){
					var A={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},B={"boolean":function(C){
						return String(C)},"null":function(C){
							return"null"},number:function(C){
								return isFinite(C)?String(C):"null"
							},string:function(C){
								if(/["\\\x00-\x1f]/.test(C)){
									C=C.replace(/([\x00-\x1f\\"])/g,function(E,D){
										var F=A[D];
										if(F){
											return F
										}F=D.charCodeAt();
										return"\\u00"+Math.floor(F/16).toString(16)+(F%16).toString(16)
									})
								}
								return'"'+C+'"'
							},array:function(D){
								var F=["["],C,I,H,E=D.length,G;
									for(H=0;H<E;H+=1){
										G=D[H];
										I=B[typeof G];
										if(I){
											G=I(G);
											if(typeof G=="string"){
												if(C){F[F.length]=","
											}
											F[F.length]=G;
											C=true
										}
									}
								}
								F[F.length]="]";
								return F.join("")},object:function(D){
									if(D){
										if(D instanceof Array){
											return B.array(D)
										}
										var E=["{"],C,H,G,F;
										for(G in D){
											F=D[G];
											H=B[typeof F];
											if(H){
												F=H(F);
												if(typeof F=="string"){
													if(C){
														E[E.length]=","
													}
													E.push(B.string(G),":",F);
													C=true
												}
											}
										}
										E[E.length]="}";
										return E.join("")
									}
									return"null"
								}
							};
							JSON.serialize=function(C){
								return B.object(C)
							}
						})();/* 
 * TimeMap Copyright 2008 Nick Rabinowitz.
 * Licensed under the GNU General Public License
 * (see LICENSE.txt or http://www.gnu.org/licenses)
 */



function timemapInit(C){
	if(!("mapId" in C)||!C.mapId){
		alert("TimeMap init: No map id was specified!");
		return 
	}
	if(!("timelineId" in C)||!C.timelineId){
		alert("TimeMap init: No timeline id was specified!");
		return 
	}C=C||{};
	C.options=C.options||{};
	C.datasets=C.datasets||[];
	C.bandInfo=C.bandInfo||false;
	C.scrollTo=C.scrollTo||"earliest";
	if(!C.bandInfo){
		var H=C.bandIntervals||[Timeline.DateTime.WEEK,Timeline.DateTime.MONTH];
		C.bandInfo=[{
			width:"80%",intervalUnit:H[0],intervalPixels:70},{
				width:"20%",intervalUnit:H[1],intervalPixels:100,showEventText:false,trackHeight:0.4,trackGap:0.2
			}]
	}
	var K=new TimeMap(document.getElementById(C.timelineId),document.getElementById(C.mapId),C.options);
	var G=[];
	for(var J=0;J<C.datasets.length;J++){
		var B=C.datasets[J];
		var E={};
		E.title=B.title||"";
		E.subtitle=B.subtitle||"";
		if(B.theme){
			E.theme=B.theme
		}
		if(B.dateParser){
			E.dateParser=B.dateParser
		}
		G[J]=K.createDataset("ds"+J,E);
		if(J>0){
			G[J].eventSource=G[0].eventSource
		}
	}
	var F=[];
	var D=(G[0]&&G[0]["eventSource"])||new Timeline.DefaultEventSource();
	for(var J=0;J<C.bandInfo.length;J++){
		var I=C.bandInfo[J];
		if(!(("eventSource" in I)&&I.eventSource==null)){
			I.eventSource=D
		}else{
			I.eventSource=null
		}
		F[J]=Timeline.createBandInfo(I);
		if(J>0){
			F[J].eventPainter.setLayout(F[0].eventPainter.getLayout())
		}
	}
	K.initTimeline(F);
	var A={};
	A.count=0;
	A.loadTarget=C.datasets.length;
	A.ifLoadedFunction=function(){
		if(C.scrollTo=="earliest"){
			K.timeline.getBand(0).setCenterVisibleDate(D.getEarliestDate())
		}else{
			K.timeline.getBand(0).setCenterVisibleDate(D.getLatestDate())
		}
		K.timeline.layout()
	};
	A.ifLoaded=function(){
		this.count++;
		if(this.count==this.loadTarget){
			this.ifLoadedFunction()
		}
	};
	for(var J=0;J<C.datasets.length;J++){
		(function(L){
			var Q=C.datasets[L]["data"];
			var P=G[L];
			var R=function(S){
				return S};
				var O=C.datasets[L]["preloadFunction"]||R;var N=C.datasets[L]["transformFunction"]||R;
				switch(Q.type){
					case"basic":
					var M=O(Q.value);
					P.loadItems(M,N);
					A.ifLoaded();
					break;					
				}
			}
			)
		(J)
		}
	};
	var JSONLoader={};
	JSONLoader.counter=0;
	JSONLoader.read=function(H,G){
		var F="_"+JSONLoader.counter++;
		JSONLoader[F]=function(A){
			G(A)
		};
		var E=document.createElement("script");
		E.src=H+"JSONLoader."+F;
		document.body.appendChild(E)
	};
	var Metaweb={};
	Metaweb.HOST="http://www.freebase.com";
	Metaweb.QUERY_SERVICE="/api/service/mqlread";
	Metaweb.counter=0;
	Metaweb.read=function(I,J){
		var H="_"+Metaweb.counter++;Metaweb[H]=function(A){
			var B=A.qname;
			if(B.code.indexOf("/api/status/ok")!=0){
				var C=B.messages[0];
				throw C.code+": "+C.message
			}
			var D=B.result;
			document.body.removeChild(G);
			delete Metaweb[H];
			J(D)
		};
		envelope={qname:{query:I}};
		var K=encodeURIComponent(JSON.serialize(envelope));
		var L=Metaweb.HOST+Metaweb.QUERY_SERVICE+"?queries="+K+"&callback=Metaweb."+H;
		var G=document.createElement("script");
		G.src=L;document.body.appendChild(G)
	};
	var JSON={};
	JSON.parse=function(s){
		try{
			return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(s.replace(/"(\\.|[^"\\])*"/g,"")))&&eval("("+s+")")
		}catch(e){
			return false
		}
	};
	(function(){
		var C={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},D={"boolean":function(A){
			return String(A)
		},"null":function(A){
			return"null"},number:function(A){
				return isFinite(A)?String(A):"null"
			},string:function(A){
				if(/["\\\x00-\x1f]/.test(A)){
					A=A.replace(/([\x00-\x1f\\"])/g,function(G,H){
						var B=C[H];if(B){
							return B
						}
						B=H.charCodeAt();
						return"\\u00"+Math.floor(B/16).toString(16)+(B%16).toString(16)
					})
				}
				return'"'+A+'"'
			},array:function(M){
				var K=["["],N,A,B,L=M.length,J;
					for(B=0;B<L;B+=1){
						J=M[B];
						A=D[typeof J];
						if(A){
							J=A(J);
							if(typeof J=="string"){
								if(N){K[K.length]=","}K[K.length]=J;
								N=true
							}
						}
					}
					K[K.length]="]";
					return K.join("")},object:function(K){
						if(K){
							if(K instanceof Array){
								return D.array(K)
							}
							var J=["{"],L,A,B,I;
							for(B in K){
								I=K[B];
								A=D[typeof I];
								if(A){
									I=A(I);
									if(typeof I=="string"){
										if(L){J[J.length]=","}
										J.push(D.string(B),":",I);
										L=true
									}
								}
							}
							J[J.length]="}";
							return J.join("")
						}
						return"null"
					}
				};
			JSON.serialize=function(A){
				return D.object(A)
			}
})();
	



function TimeMap(J,H,I){
	this.mElement=H;
	this.tElement=J;
	this.datasets={};
	this.mapBounds=new GLatLngBounds();
	I=I||{};
	this.settings={
		syncBands:I.syncBands||true,
		mapCenter:I.mapCenter||new GLatLng(0,0),
		mapZoom:I.mapZoom||0,
		mapType:I.mapType||G_PHYSICAL_MAP,
		showMapTypeCtrl:I.showMapTypeCtrl||true,
		showMapCtrl:I.showMapCtrl||true,
		hidePastFuture:I.hidePastFuture||true,
		centerMapOnItems:I.centerMapOnItems||true
	};
	
	var G=this.settings;
	if(GBrowserIsCompatible()){
		this.map=new GMap2(this.mElement);
		if(G.showMapCtrl){
			//canviar el tipus de zoom
			this.map.addControl(new GSmallZoomControl())
		}
		if(G.showMapTypeCtrl){
			this.map.addControl(new GMapTypeControl())
		}
		
		//eliminar menu tipus mapes
		
		this.map.addMapType(G_PHYSICAL_MAP);
		this.map.removeMapType(G_HYBRID_MAP);
	//	this.map.removeMapType(G_NORMAL_MAP);
	//	this.map.removeMapType(G_SATELLITE_MAP);
		
		this.map.disableDoubleClickZoom();
		//this.map.enableScrollWheelZoom();
		this.map.enableContinuousZoom();
		this.map.setCenter(G.mapCenter,G.mapZoom);
		this.map.setMapType(G.mapType)
		
	}
	var F=this.map;
	Timeline.DurationEventPainter.prototype._showBubble=function(C,A,B){
		GEvent.trigger(B.placemark,"click")
	}
}

TimeMap.prototype.createDataset=function(E,D){
	if(!("title" in D)){
		D.title=E
	}
	if(!("subtitle" in D)){
		D.subtitle=E
	}
	var F=new TimeMapDataset(this,D);
	this.datasets[E]=F;
	return F
};
TimeMap.prototype.initTimeline=function(I){
	for(var G=1;G<I.length;G++){
		if(this.settings.syncBands){
			I[G].syncWith=(G-1)
		}
		I[G].highlight=true
	}
	this.timeline=Timeline.create(this.tElement,I);
	if(this.settings.hidePastFuture){
		var H=this.timeline.getBand(0);
		var J=this.datasets;
		var L=this.map;H.addOnScrollListener(function(){
			var C=H.getMaxVisibleDate().getTime();
			var B=H.getMinVisibleDate().getTime();
			for(id in J){
				var D=J[id].getItems();
				for(var F=0;F<D.length;F++){
					if(D[F].event!=null){
						var E=D[F].event.getStart().getTime();
						var A=D[F].event.getEnd().getTime();
						if(E>C){
							D[F].placemark.hide();
							D[F].closeInfoWindow()
						}else{
							if(A<B||(D[F].event.isInstant()&&E<B)){
								D[F].placemark.hide();
								D[F].closeInfoWindow()
							}else{
								D[F].placemark.show()
							}
						}
					}
				}
			}
		})
	}
	if(this.settings.hideOffMap){
		var J=this.datasets;
		var L=this.map;
		GEvent.addListener(L,"moveend",function(){
			var A=L.getBounds();
			for(id in J){
				var C=J[id].getItems();
				for(var D=0;D<C.length;D++){
					var B=C[D].placemark.getLatLng();
					if(!A.containsLatLng(B)&&C[D].event!=null){
						C[D].event.hide()
					}else{
						C[D].event.show()
					}
				}
			}
		})
	}
	resizeTimerID=null;
	var K=this.timeline;
	window.onresize=function(){
		if(resizeTimerID==null){
			resizeTimerID=window.setTimeout(function(){
				resizeTimerID=null;
				K.layout()
			},500)
		}
	}
};

TimeMap.prototype.createLegend=function(F){
	F="#"+F;
	for(id in this.datasets){
		var G=this.datasets[id];
		var E='<div style="float:left;margin-right:5px;border:1px solid #000;width:12px;height:12px;background:'+G._theme.color+'">&nbsp;</div>';
		var H='<div class="legenditem">'+E+G.title+"</div>";
		$(F).append(H)
	}
};
function TimeMapDataset(C,D){
	this.timemap=C;
	this.eventSource=new Timeline.DefaultEventSource();
	this._items=[];
	this.title=D.title||"";
	this.subtitle=D.subtitle||"";
	this._theme=D.theme||new TimeMapDatasetTheme({});
	this._dateParser=D.dateParser||Timeline.DateTime.parseIso8601DateTime
}
TimeMapDataset.prototype.getItems=function(){
	//si es comenta la linia seguent mostra tots els punts al mapa
	return this._items
};
TimeMapDataset.prototype.loadItems=function(F,G){
	for(var E=0;E<F.length;E++){
		this.loadItem(F[E],G)
	}
	
	var H=this.timemap;
	
	if (document.getElementById("id_ruta").value=="2"){			
			var listaCoords = [            
			[9.55, -79.65],
			[10.417046, -75.526199],
			[11.241109,-74.20578],
			[11.541993, -72.911453],			
			[11.586055, -72.865791],
			[12.528825, -69.966431],
			[12.1262, -68.930114],
			[11.403471, -69.677696],			
			[12.163661, -68.302689],
			[10.429066, -68.010650],
			[10.807880, -64.207020],	
			[10.957506,-64.025574],            
			[10.047729, -61.916779],				
			[18.493154, -69.881287],			
			[18.047370, -66.558490]
			];		
		for(var i in listaCoords) {
		listaCoords[i] = new GLatLng(
		listaCoords[i][0],
		listaCoords[i][1]
		);
		}		
		for(var i in listaCoords) {			
			if(i>0) {
				H.map.addOverlay(
				new GPolyline(
				[listaCoords[i-1],
				listaCoords[i]],
				"#003967",3) //color de la linia i el gruixut
				);
			}
		} 		
	}	
   
    if (document.getElementById("id_ruta").value=="1"){			
    
			var listaCoords = [
			[37.065657, 15.284729],
			[41.888764, 12.465878],			
			[44.413766, 12.197056],
			[31.775461, 35.213928],			
			[37.982363, 23.716736],
			[41.010475, 28.978329],			
			[31.198056, 29.919167]
			];		
		for(var i in listaCoords) {
		listaCoords[i] = new GLatLng(
		listaCoords[i][0],
		listaCoords[i][1]
		);
		}		
		for(var i in listaCoords) {			
			if(i>0) {
				H.map.addOverlay(
				new GPolyline(
				[listaCoords[i-1],
				listaCoords[i]],
				"#005926",3) //color de la linia i el gruixut
				);
			}
		} 		
	}
    
    if (document.getElementById("id_ruta").value=="3"){			
    
			var listaCoords = [
			[39.919427,116.349335],
			[34.391563,109.438291],			
			[34.266296, 108.934937],
			[32.398806,110.999336],			
			[31.494262,112.565918],
			[30.866426,113.951225],			
			[30.591819, 114.305878],
            [32.054063,118.796196],
			[31.303195,120.614777],			
			[31.224546, 121.470337],
            [39.919427,116.349335]            
			];		
		for(var i in listaCoords) {
		listaCoords[i] = new GLatLng(
		listaCoords[i][0],
		listaCoords[i][1]
		);
		}		
		for(var i in listaCoords) {			
			if(i>0) {
				H.map.addOverlay(
				new GPolyline(
				[listaCoords[i-1],
				listaCoords[i]],
				"#8F1419",3) //color de la linia i el gruixut
				);
			}
		} 		
	}
    
    
    if (document.getElementById("id_ruta").value=="4"){	
    		var listaCoords = [	    		
            [40.662931,-4.700089],
            [47.379754,8.53775],
            [47.657063,9.478455],
            [47.379754,8.53775],
            [40.662931,-4.700089],
            [41.149968,-8.61024],
            [40.662931,-4.700089],
            [43.615697,1.442642],
            [50.121459,8.680573],
            [50.989125,11.324158],
            [50.742539,7.096481],
            [40.423951,-3.703766],
            [40.662931,-4.700089],
            [45.772792,4.834328],
            [-4.655817,55.48027]    	           
			];		
		for(var i in listaCoords) {
		listaCoords[i] = new GLatLng(
		listaCoords[i][0],
		listaCoords[i][1]
		);
		}		
		for(var i in listaCoords) {			
			if(i>0) {
				H.map.addOverlay(
				new GPolyline(
				[listaCoords[i-1],
				listaCoords[i]],
				"#A34E0B",3) //color de la linia i el gruixut
				);
			}
		} 		
	}
    
    
    if (document.getElementById("id_ruta").value=="5"){	
    		var listaCoords = [	   
      		[36.434293,28.231773],          
            [34.852129,33.43689],
            [37.991022,23.716736],
            [40.488737,9.008789],
            [39.647997,2.911377],
            [41.402566,2.1698],
            [41.820455,1.400757],
            [42.975014,1.607094],
            [43.626135,1.442642],            
            [43.183566,3.004192],
            [43.619425,3.879204],
            [43.951552,4.805832],
            [44.061193,4.77562], 
            [45.5244048647944, 4.878530502319336],
            [45.772792,4.834328],
            [48.861779,2.351074],
            [43.960202,4.805832],
            [43.614205,3.879204],
            [43.615697,1.442642],
            [42.71552,-0.525573],
            [42.68824,-0.530777],
            [42.584433,-0.55069],
            [42.584433,-0.55069],
            [42.671775,-1.81576],  
            [42.67041, -2.030787],          
            [42.549539,-2.271423],
            [42.468805,-2.449951],
            [42.430045,-2.564621],
            [42.419148,-2.734222],
            [42.602631,-6.807404],
            [42.343828,-3.699646],
            [42.346746,-3.819466],
            [42.340148,-3.834229],            
            [42.288282,-4.138836],
            [42.310323,-4.045715],
            [42.288282,-4.138836],
            [42.607651,-6.807748],
            [42.807754,-7.615518],
            [42.884015,-8.54599],
            [42.908663,-9.264221],
            [39.333665,-9.267555]   	           
			];		
		for(var i in listaCoords) {
		listaCoords[i] = new GLatLng(
		listaCoords[i][0],
		listaCoords[i][1]
		);
		}		
		for(var i in listaCoords) {			
			if(i>0) {
				H.map.addOverlay(
				new GPolyline(
				[listaCoords[i-1],
				listaCoords[i]],
				"#B09100",3) //color de la linia i el gruixut
				);
			}
		} 		
	}
    

	if (document.getElementById("id_ruta").value=="6"){	
    		var listaCoords = [	
            [41.391749,2.1698],
            [52.383563,4.890976],
            [12.513006,-69.968491],
            [-12.031262,-77.047119],
            [-16.481522,-68.146133],
            [-16.525488,-68.205271],
            [-13.783695,-67.423182],
            [-13.783695,-67.423182],
            [-14.349444,-67.599993],
            [-14.46161,-67.560768],
            [-16.481522,-68.146133],
            [-12.031262,-77.047119],
            [52.383563,4.890976],
            [41.391749,2.1698]
			];		
		for(var i in listaCoords) {
		listaCoords[i] = new GLatLng(
		listaCoords[i][0],
		listaCoords[i][1]
		);
		}		
		for(var i in listaCoords) {			
			if(i>0) {
				H.map.addOverlay(
				new GPolyline(
				[listaCoords[i-1],
				listaCoords[i]],
				"#2A7092",3) //color de la linia i el gruixut
				);
			}
		} 		
	}
    
    
    if (document.getElementById("id_ruta").value=="7"){	
    		var listaCoords = [	            
            [41.391749,2.1698],
            [42.7950227645602,-0.5436515808105469],            
            [42.68824,-0.530777],
            [42.584433,-0.55069],
            [42.563702,-0.713768],
            [42.608695,-0.858307],
            [42.615281,-1.116292],
            [42.584433,-0.55069],
            [42.671775,-1.81576],
            [42.67041, -2.030787],
            [42.549539,-2.271423],
            [41.536081,-2.460594],
            [42.468805,-2.449951],
            [42.430045,-2.564621],
            [42.419148,-2.734222],
            [42.332662,-2.861252],
            [42.440688,-2.952576],	
            [42.343828,-3.699646],
            [42.288282,-4.138836],
            [42.457835,-6.768093],
            [42.316289,-4.543362],
            [42.337642,-4.602134],
            [42.354545,-4.864838],
            [42.372026,-5.03044],
            [42.602883,-5.571785],
            [42.4607,-6.063423],
            [42.602631,-6.807404],
            [42.858161,-7.778878],
            [42.884015,-8.54599],
            [42.78885,-8.888626],
            [42.943983,-9.194355],
            [42.908663,-9.264221],
            [39.333665,-9.267555]
			];		
		for(var i in listaCoords) {
		listaCoords[i] = new GLatLng(
		listaCoords[i][0],
		listaCoords[i][1]
		);
		}		
		for(var i in listaCoords) {			
			if(i>0) {
				H.map.addOverlay(
				new GPolyline(
				[listaCoords[i-1],
				listaCoords[i]],
				"#41446D",3) //color de la linia i el gruixut
				);
			}
		} 		
	}

	/*
    
1Plaza del Triunfo sevilla	37.385429,-5.992273
2Plaza del Triunfo sevilla	37.385084,-5.992283
3Archivo General de Indias 	37.384819,-5.993828
4Calle Hernando Colón	37.387109,-5.993392
5Plaza de San Francisco	37.388587,-5.993938
6calle Zaragoza	37.388378,-5.99754
* 6Plaza de Molviedro sevilla37.387835,-5.99807

7Plaza de Toros de la Maestranza	37.385999,-5.99888
8Reales Atarazanas 37.38264,-5.996295
9Torres de la Plata	37.383595,-5.994323
10calle Betis	37.383241,-5.999658

*/
    if (document.getElementById("id_ruta").value=="8"){	
    		var listaCoords = [	            
            [37.385429,-5.992273],
            [37.384819,-5.993828],
            [37.387109,-5.993392],
            [37.388587,-5.993938],
            [37.388378,-5.99754],
            [37.385999,-5.99888],
            [37.38264,-5.996295],
            [37.383595,-5.994323],
            [37.383241,-5.999658]
			];		
		for(var i in listaCoords) {
		listaCoords[i] = new GLatLng(
		listaCoords[i][0],
		listaCoords[i][1]
		);
		}		
		for(var i in listaCoords) {			
			if(i>0) {
				H.map.addOverlay(
				new GPolyline(
				[listaCoords[i-1],
				listaCoords[i]],
				"#ff9900",3) //color de la linia i el gruixut
				);
			}
		} 		
	}
    
    
	if(H.settings.centerMapOnItems){
		H.map.setZoom(H.map.getBoundsZoomLevel(H.mapBounds));
		H.map.setCenter(H.mapBounds.getCenter())
	}
};
TimeMapDataset.prototype.loadItem=function(U,c){
	
	if(c!=undefined){
		U=c(U)
	}
	if(U==null){
		return 
	}
	var V=U.options.theme||this._theme;
	var j=this.timemap;
	var f=(U.start==undefined||U.start=="")?null:this._dateParser(U.start);
	var g=(U.end==undefined||U.end=="")?null:this._dateParser(U.end);
	var k=(U.end==undefined);
	
	var l=k?V.eventIcon:null;
	
	
	//marc
	//var T=U.title+'\r\n'+" | aa";
	//var M=" | "+U.subtitle;
	var M=U.subtitle;
	
	var T=U.title;
	
	if(f!=null){
		if (M){
			text_nom = T+" ("+M+")";
		}else{
			text_nom = T;	
		}		
		var a=new Timeline.DefaultEventSource.Event(f,g,null,null,k,text_nom,null,null,null,l,V.eventColor,null)
	}else{
		var a=null
	}
	var W=null;
	var h="";
	var b=null;
	
	
	
	
	
	
	
	if("point" in U){
		
		b=new GLatLng(parseFloat(U.point.lat),parseFloat(U.point.lon));
		
		if(j.settings.centerMapOnItems){
			j.mapBounds.extend(b)
		}
		markerIcon=("icon" in U)?U.icon:V.icon;
		W=new GMarker(b,{icon:markerIcon});
		h="marker"
		
		
		
		//map.addOverlay(polyline);
		
	}else{
		
	}
	if(W==null){
		return 
	}
	
	var i=("options" in U)?U.options:{};
	i.title=T;
	i.subtitle=M;
	i.type=h;
	i.infoPoint=b;
	var X=new TimeMapItem(W,a,j.map,i);

	if(a!=null){
		a.placemark=W;
		a.item=X
	}
	W.event=a;
	W.item=X;
	this._items.push(X);
				
	var Z=j.map;
	GEvent.addListener(W,"click",function(){
		//var center:LatLng = getCenter();	
	//	j.map.setCenter();
	//	j.map.setZoom(level:10, opt_doContinuousZoom:false) 	
		
        if (document.getElementById("id_div").value==""){
			j.map.zoomIn(); //fer zoom al clickar	
		}				
		X.openInfoWindow()		
		
	});				
	j.map.addOverlay(W)
	
	
	//marc
	//**//
	// tierrafirme	 INICI
	
	// FINAL
	
	
	if(a!=null){this.eventSource.add(a)}
	
	
	
};
TimeMapDataset.parseKML=function(U){
	var V=[];
	kmlnode=GXml.parse(U);
	var T=kmlnode.getElementsByTagName("Placemark");
	var X=false;
	for(var M=0;M<T.length;M++){
		var P=T[M];
		var O,N={};
		O=P.getElementsByTagName("name");
		if(O.length>0){
			N.title=O[0].firstChild.nodeValue
		}
		O=P.getElementsByTagName("description");
		N.options={};
		if(O.length>0){
			N.options.description=O[0].firstChild.nodeValue
		}
		O=P.getElementsByTagName("TimeStamp");
		if(O.length>0){
			N.start=O[0].getElementsByTagName("when")[0].firstChild.nodeValue;
			X=true
		}
		if(!X){
			O=P.getElementsByTagName("TimeSpan");
			if(O.length>0){
				N.start=O[0].getElementsByTagName("begin")[0].firstChild.nodeValue;
				N.end=O[0].getElementsByTagName("end")[0].firstChild.nodeValue;
				X=true
			}
		}
		if(!X){N.push(TimeMapDataset.parseParentNode(P))}
		O=P.getElementsByTagName("Point");
					
					
					
					
	if(O.length>0){
		N.point={};var R=O[0].getElementsByTagName("coordinates")[0].firstChild.nodeValue;
		var W=R.split(",");
		N.point={lat:trim(W[1]),lon:trim(W[0])}
		}else{
			O=P.getElementsByTagName("LineString");
			if(O.length>0){
				N.polyline=[];
				var R=O[0].getElementsByTagName("coordinates")[0].firstChild.nodeValue;
				var Q=trim(R).split(/[\r\n\f]+/);
				for(var S=0;S<Q.length;S++){
					var W=Q[S].split(",");
					N.polyline.push({lat:trim(W[1]),lon:trim(W[0])})
				}
			}else{
				O=P.getElementsByTagName("Polygon");
				if(O.length>0){N.polyline=[];
				var R=O[0].getElementsByTagName("coordinates")[0].firstChild.nodeValue;
				var Q=trim(R).split(/[\r\n\f]+/);
				for(var S=0;S<Q.length;S++){
					var W=Q[S].split(",");
					N.polyline.push({lat:trim(W[1]),lon:trim(W[0])})
				}
			}
		}
	}
	V.push(N)
}
kmlnode=null;
O=null;
return V
};
TimeMapDataset.parseParentNode=function(C){
	check=false;
	var D={};
	pn=C.parentNode;
	if(pn.nodename=="Folder"||pn.nodename=="Document"){
		for(ele in pn.childNodes){
			if(ele.nodename=="TimeStamp"){
				D.start=ele.getElementsByTagName("when")[0].firstChild.nodeValue;
				check=true
			}else{
				if(ele.nodename="TimeStamp"){
					beginNodes=ele.getElementsByTagName("begin");
					if(beginNodes.length>0){
						D.start=beginNodes[0].firstChild.nodeValue
					}
					if(endNodes.length>0){
						D.end=endNodes[0].firstChild.nodeValue
					}
					check=true
				}
			}
		}
	}else{
		check=true
	}
	if(!check){
		D=TimeMapDataset.parseParentNode(pn)
	}
	return D
};
function TimeMapDatasetTheme(B){
	B=B||{};
	this.icon=B.icon||G_DEFAULT_ICON;
	this.color=B.color||"#FE766A";
	this.lineColor=B.lineColor||this.color;
	this.polygonLineColor=B.polygonLineColor||this.lineColor;
	this.lineOpacity=B.lineOpacity||1;
	this.polgonLineOpacity=B.polgonLineOpacity||this.lineOpacity;
	this.lineWeight=B.lineWeight||2;
	this.polygonLineWeight=B.polygonLineWeight||this.lineWeight;
	this.fillColor=B.fillColor||this.color;
	this.fillOpacity=B.fillOpacity||0.25;
	this.eventColor=B.eventColor||this.color;
	this.eventIconPath=B.eventIconPath||"timemap/images/";
	this.eventIconImage=B.eventIconImage||"red-circle.png";
	this.eventIcon=B.eventIcon||this.eventIconPath+this.eventIconImage
	//mostra les imatges
}
TimeMapDataset.redTheme=function(B){
	return new TimeMapDatasetTheme(B)};
	url_web = "img/";
	TimeMapDataset.blueTheme=function(D){
		D=D||{};
		var C=new GIcon(G_DEFAULT_ICON);
		C.image=url_web+"tierra-dot.png";
		C.iconSize=new GSize(32,32);
		C.shadow=url_web+"msmarker.shadow.png";
		C.shadowSize=new GSize(59,32);
		D.icon=C;
		D.color="#5A7ACF";
		D.eventIconImage="tierr-circle.png";
		return new TimeMapDatasetTheme(D)
	};
	TimeMapDataset.greenTheme=function(D){
		D=D||{};
		var C=new GIcon(G_DEFAULT_ICON);
		C.image=url_web+"green-dot.png";
		C.iconSize=new GSize(32,32);
		C.shadow=url_web+"msmarker.shadow.png";
		C.shadowSize=new GSize(59,32);
		D.icon=C;
		D.color="#19CF54";
		D.eventIconImage="green-circle.png";
		return new TimeMapDatasetTheme(D)
	};
	TimeMapDataset.ltblueTheme=function(D){
		D=D||{};
		var C=new GIcon(G_DEFAULT_ICON);
		C.image=url_web+"ltblue-dot.png";
		C.iconSize=new GSize(32,32);
		C.shadow=url_web+"msmarker.shadow.png";
		C.shadowSize=new GSize(59,32);
		D.icon=C;D.color="#5ACFCF";
		D.eventIconImage="ltblue-circle.png";
		return new TimeMapDatasetTheme(D)
	};
	TimeMapDataset.purpleTheme=function(D){
		D=D||{};
		var C=new GIcon(G_DEFAULT_ICON);
		C.image=url_web+"purple-dot.png";
		C.iconSize=new GSize(32,32);
		C.shadow=url_web+"msmarker.shadow.png";
		C.shadowSize=new GSize(59,32);
		D.icon=C;D.color="#8E67FD";
		D.eventIconImage="purple-circle.png";
		return new TimeMapDatasetTheme(D)
	};
	TimeMapDataset.orangeTheme=function(D){
		D=D||{};
		var C=new GIcon(G_DEFAULT_ICON);
		C.image=url_web+"orange-dot.png";
		C.iconSize=new GSize(32,32);
		C.shadow=url_web+"msmarker.shadow.png";
		C.shadowSize=new GSize(59,32);
		D.icon=C;
		D.color="#FF9900";
		D.eventIconImage="orange-circle.png";
		return new TimeMapDatasetTheme(D)
	};
	TimeMapDataset.yellowTheme=function(D){
		D=D||{};
		var C=new GIcon(G_DEFAULT_ICON);
		C.image=url_web+"yellow-dot.png";
		C.iconSize=new GSize(32,32);
		C.shadow=url_web+"msmarker.shadow.png";
		C.shadowSize=new GSize(59,32);
		D.icon=C;
		D.color="#ECE64A";
		D.eventIconImage="yellow-circle.png";				
		return new TimeMapDatasetTheme(D)
	};
    TimeMapDataset.marroTheme=function(D){
		D=D||{};
		var C=new GIcon(G_DEFAULT_ICON);
		C.image=url_web+"marro-dot.png";
		C.iconSize=new GSize(32,32);
		C.shadow=url_web+"msmarker.shadow.png";
		C.shadowSize=new GSize(59,32);
		D.icon=C;
		D.color="#A34E0B";
		D.eventIconImage="marro-circle.png";				
		return new TimeMapDatasetTheme(D)
	};
    TimeMapDataset.oroTheme=function(D){
		D=D||{};
		var C=new GIcon(G_DEFAULT_ICON);
		C.image=url_web+"oro-dot.png";
		C.iconSize=new GSize(32,32);
		C.shadow=url_web+"msmarker.shadow.png";
		C.shadowSize=new GSize(59,32);
		D.icon=C;
		D.color="#B09100";
		D.eventIconImage="oro-circle.png";				
		return new TimeMapDatasetTheme(D)
	};
    TimeMapDataset.aquaTheme=function(D){
		D=D||{};
		var C=new GIcon(G_DEFAULT_ICON);
		C.image=url_web+"aqua-dot.png";
		C.iconSize=new GSize(32,32);
		C.shadow=url_web+"msmarker.shadow.png";
		C.shadowSize=new GSize(59,32);
		D.icon=C;
		D.color="#2A7092";
		D.eventIconImage="aqua-circle.png";				
		return new TimeMapDatasetTheme(D)
	};
    TimeMapDataset.violetaTheme=function(D){
		D=D||{};
		var C=new GIcon(G_DEFAULT_ICON);
		C.image=url_web+"violeta-dot.png";
		C.iconSize=new GSize(32,32);
		C.shadow=url_web+"msmarker.shadow.png";
		C.shadowSize=new GSize(59,32);
		D.icon=C;
		D.color="#41446D";
		D.eventIconImage="violeta-circle.png";				
		return new TimeMapDatasetTheme(D)
	};
    TimeMapDataset.taronjaTheme=function(D){
		D=D||{};
		var C=new GIcon(G_DEFAULT_ICON);
		C.image=url_web+"taronja-dot.png";
		C.iconSize=new GSize(32,32);
		C.shadow=url_web+"msmarker.shadow.png";
		C.shadowSize=new GSize(59,32);
		D.icon=C;
		D.color="#41446D";
		D.eventIconImage="taronja-circle.png";				
		return new TimeMapDatasetTheme(D)
	};
function TimeMapItem(H,G,F,E){
	
	this.placemark=H;
	this.event=G;
	this.map=F;
	E=E||{};
	this._type=E.type||"";
	this._title=E.title||"";
	this._subtitle=E.subtitle||"";
	this._description=E.description||"";
	
	this._infoPoint=E.infoPoint||null;
	this._infoHtml=E.infoHtml||"";
	this._infoUrl=E.infoUrl||"";
	this._maxInfoHtml=E.maxInfoHtml||"";
	this._maxInfoUrl=E.maxInfoUrl||"";
	this._maxOnly=E.maxOnly||false;
	this.getType=function(){
		return this._type
	};
	this.getTitle=function(){
		return this._title
	};
	this.getSubTitle=function(){
		return this._subtitle
	};
	this.getInfoPoint=function(){
		return this._infoPoint
	};
	if(this._infoHtml==""&&this._infoUrl==""&&!this._maxOnly){
		
		//aqui canvia els textos dins els globols
		this._infoHtml='<div class="infotitle" style="font-size:12px;font-weight:bold">'+this._title+"</div>";
		if(this._description!=""){
			this._infoHtml+='<div class="infodescription"  style="font-size:10px;">'+this._description+"</div>"
		}
	}
}
TimeMapItem.prototype.openInfoWindow=function(){
	var I;
	var J=false;
	/*
	if(this._maxInfoHtml!=""||this._maxInfoUrl!=""){
		J=true;
		var M=document.createElement("div");
		if(this._maxInfoHtml!=""){
			M.innerHTML=this._maxInfoHtml
		}else{
			M.innerHTML="Loading..."
		}I={maxContent:M};
		if(this._maxInfoHtml==""){
			var N=this.map.getInfoWindow();
			var K=this._maxInfoUrl;
			GEvent.addListener(N,"maximizeclick",function(){
				GDownloadUrl(K,function(A){M.innerHTML=A})
			})
		}
	}else{
		I={}
	}*/
	
	
	
	if(this._infoHtml!=""||(J&&this._maxOnly)){
		if(this.getType()=="marker"){
			this.placemark.openInfoWindowHtml(this._infoHtml,I) //akest funciona
			
			
			//alert(this._infoPoint) mostra la ubicacio del punt
			//alert(this._title)// mostra el titol
			document.getElementById("id_div").value = this._title
			
		}else{
			this.map.openInfoWindowHtml(this.getInfoPoint(),this._infoHtml,I)
		}
		/*
		if(J&&this._maxOnly){
			this.map.getInfoWindow().maximize();
			var N=this.map.getInfoWindow();
			var H=this.map;
			GEvent.addListener(N,"restoreclick",function(){
				H.closeInfoWindow()
			})
		}
		*/
	}
	/*
	else{
		if(this._infoUrl!=""){
			var L=this;
			GDownloadUrl(this._infoUrl,function(A){
				L._infoHtml=A;
				L.openInfoWindow()
			})
		}
	}
	*/
	
	
};
TimeMapItem.prototype.closeInfoWindow=function(){
	if(this.getType()=="marker"){
		this.placemark.closeInfoWindow()
	}else{
		var B=this.map.getInfoWindow();
		if(B.getPoint()==this.getInfoPoint()&&!B.isHidden()){
			this.map.closeInfoWindow()
		}
	}
};

function trim(B){return B.replace(/^\s\s*/,"").replace(/\s\s*$/,"")}
	
	