var is_opera = ( window.navigator.userAgent.toLowerCase().indexOf( "opera" ) != -1 ); 
var is_ie = ( window.navigator.userAgent.toLowerCase().indexOf( "msie" ) != -1 ) && !is_opera;
function trim(cadena) {for(i=0; i<cadena.length;++i) {if(cadena.charAt(i)==" ") cadena=cadena.substring(i+1, cadena.length); else break;} for(i=cadena.length-1; i>=0; i=cadena.length-1) {if(cadena.charAt(i)==" ") cadena=cadena.substring(0,i); else break;} return cadena;}
function getInnerText (node) {if (typeof node.textContent != 'undefined') {return node.textContent;}else if (typeof node.innerText != 'undefined') {return node.innerText;}else if (typeof node.text != 'undefined') {return node.text;}else {switch (node.nodeType) {case 3:case 4:return node.nodeValue;break;case 1:case 11:var innerText = '';for (var i = 0; i < node.childNodes.length; i++) {innerText += getInnerText(node.childNodes[i]);}return innerText;break;default:return '';}}}
function getHTTPObject() {var http = false;try {http=new XMLHttpRequest();}catch (trymicrosoft) {try {http = new ActiveXObject("Msxml2.XMLHTTP");}catch (othermicrosoft){try{http = new ActiveXObject("Microsoft.XMLHTTP");}catch (failed){http = false;}}}return http}
// **************************************************************************************************************************
// Author: marc.compte@sigte.udg.es
//
// License: The following code (and the rest of the files within this package) is offered, as it is and with no warranty, under a GNU/GPL license. You are allowed to distribute copies, make changes to the code and redistribute them, as long as the code being distributed is licensed under a GNU/GPL license.
//
// If you are willing to make changes to the code or distribute it, please read the complete license description at: http://www.gnu.org
// **************************************************************************************************************************
// Checks whether a string (txt) is encolsed by a specific character (wrapper)
function isEnclosedBy(txt, wrapper) {return (txt.charAt(0)==wrapper && txt.charAt(txt.length-1)==wrapper);}
// Removes one character off the string at each end
function removeWrapper(txt, wrapper) {return txt.substring(1,txt.length-1);}
// Removes line breaks off a string
function ripBreaks(tmp) {
	while (tmp.indexOf('\n')!=-1) tmp=tmp.replace('\n','');
	while (tmp.indexOf('\r')!=-1) tmp=tmp.replace('\r','');
	while (tmp.indexOf('\t')!=-1) tmp=tmp.replace('\t','');
	return tmp;
}
// AJAX call object. Let's you specify the usuall parameters plus the object that will receive the code (o: object), the method within the object (callBack: string), the return mode (returnMode: string) ... either Text or XML ... and needs a newly created HTTP request object.
function AJAXcall(method, url, async, o, callBack, returnMode, HTTPObject) {
	this.method=method;
	this.url=url;
	this.async=async;
	this.callBack=callBack;
	if (callBack!='parseConfig' && callBack!='parseIP' && callBack!='parseLang') HTTPObject=GXmlHttp.create();
	else HTTPObject=new getHTTPObject();
	if (arguments.length==5) this.returnMode='Text';
	else this.returnMode=returnMode;
	this.execute=function() {
		HTTPObject.open(method, url, async);
		HTTPObject.send(null);
		callItBack=false;
		if (async) {
			HTTPObject.onreadystatechange=function() {
				if (HTTPObject.readyState==4) {
					switch (HTTPObject.status) {
						case 200:
							tmp=HTTPObject.responseText;
							break;
						case 404:
							if (url.indexOf('?')!=0) url=url.substring(0,url.indexOf('?'));
							tmp='ERROR 404: El archivo '+url+' no fué encontrado.';
							break;
					}
					if (tmp.toLowerCase().indexOf('error1')!=-1 || tmp.toLowerCase().indexOf('warning1')!=-1) alert('Hi ha hagut un error al caràcter '+tmp.toLowerCase().indexOf('error ')+':\n\n'+tmp);
					else {
						res=eval('HTTPObject.response'+returnMode);
						if (returnMode=='Text') eval('o.'+callBack+'(\''+ripBreaks(res)+'\');');
						else eval('o.'+callBack+'(res);');
					}
				}
			}
		} else {
			res=eval('HTTPObject.response'+this.returnMode);
			if (this.returnMode=='Text') eval('o.'+callBack+'(\''+ripBreaks(res)+'\');');
			else eval('o.'+callBack+'(res);');
		}
	}
	this.execute();
}
function DataSource() {
	this.idx=null;
	this.map=null;
	this.name=null;
	this.server=null;
	this.user=null;
	this.password=null;
	this.database=null;
	this.sql=null;
	this.table=null;
	this.id=null;
	this.lat=null;
	this.long=null;
	this.titol=null;
	this.fieldNames=new Array();
	this.tabs=new Array();
	this.collection=new Array();
	this.template=null;
	this.call=null;
	this.count=0;
	this.getPOIS=function() { // calls the data and sends the result to parsePOIS
		async=true;
		if (this.map.mode=='edit') async=false;
		add='?usermode='+this.map.admin+'&root='+this.map.backPath+'&config='+this.map.configFile;
		if (this.map.mode=='edit') add+='&id='+id_usuari;
		if (sql_limit!=-1) add+='&limit='+sql_limit;
		if (this.map.realAdmin && !this.map.admin) add+='&forcePublic=true';
		url=this.map.path+'get_pois.php'+add+'&source='+this.idx;
		this.map.showTip(txt_loading+' ... ', 'mapa_mssg mapa_mssg_saving');
		this.call=new AJAXcall('GET', url, true, this, 'parsePOIS', 'Text');
	}
	this.parsePOIS=function(tmp) { // goes throough the data and builds up the prototyped objects
		// resize map (needed to make the map area 100% 100%)
		ugmap.map.checkResize();
		ugmap.homeView();
		tmp=tmp.split('|'); // extracts records
		tmp[0]=tmp[0].split(',');
		idField=''; latField=''; longField='';
		for (j=0;j<tmp[0].length;++j) { // captures the field names and adds them as new attributos of info_usuari
			tmp[0][j]=tmp[0][j].toLowerCase();
			if (isEnclosedBy(tmp[0][j],'*')) { // checks if this is the id field and stores it individually
				tmp[0][j]=removeWrapper(tmp[0][j]);
				idField=tmp[0][j];
			} else if (isEnclosedBy(tmp[0][j],'#')) { // checks if this is the latitude field and stores it individually
				tmp[0][j]=removeWrapper(tmp[0][j]);
				latField=tmp[0][j];
			} else if (isEnclosedBy(tmp[0][j],'%')) { // checks if this is the longitude field and stores it individually
				tmp[0][j]=removeWrapper(tmp[0][j]);
				longField=tmp[0][j];
			} else { // creates the user prototype's attribute
				fieldName=tmp[0][j];
				while (fieldName.indexOf(' ')!=-1) fieldName=fieldName.replace(' ','');
				if (eval('info_usuari.prototype.'+fieldName)+''=='undefined') {
					eval('info_usuari.prototype.'+fieldName+'=null;');
				}
			}
		}
		// stores the list of fields as a prototype's attribute
		this.fieldNames=tmp[0];
		// stores the user information in prototype instances
		cat=''; cat2='';
		this.count=tmp.length-1;
		for (user=1;user<tmp.length;++user) { // creates the user objects
			tmp[user]=tmp[user].split(',');
			// Instantiate the user
			this.map.usuari[this.map.usuari.length]=new info_usuari(this.map.usuari.length, this);
			// Update its data
			for (j=0;j<tmp[user].length;++j) {
				fieldName=tmp[0][j];
				fieldValue=tmp[user][j];
				sourceName=fieldValue.split('.');
				while (fieldValue.indexOf('.coma.')!=-1) fieldValue=fieldValue.replace('.coma.',',');
				while (fieldValue.indexOf('.apos.')!=-1) fieldValue=fieldValue.replace('.apos.','\\\'');
				switch (fieldName.toLowerCase()) {
					case idField:
						fieldName='id';
						break;
					case latField:
						fieldName='lat';
						break;
					case longField:
						fieldName='long';
						break;
					case 'catname': // adds the category and data source to the list
						if (sourceName[0]!=cat) {
							cat=sourceName[0];
							if (this.map.list) {
								el=document.createElement('div');
								el.className='mapa_list_source';
								el.id=cat;
								el.innerHTML=cat+' ('+this.count+')';
								this.map.list.appendChild(el);
							}
						}
						if (sourceName[1]!=cat2) {
							cat2=sourceName[1];
							if (document.getElementById(cat)) {
								el=document.createElement('div');
								el.className='mapa_list_category';
								el.id=cat2;
								el.innerHTML=cat2;
								document.getElementById(cat).appendChild(el);
							}
						}
						break;
				}
				if (fieldName+''!='undefined') eval('this.map.usuari[this.map.usuari.length-1].'+fieldName+'=\''+fieldValue+'\'');
			}
			// sets the user image marker
			this.map.usuari[this.map.usuari.length-1].icon.image=this.map.usuari[this.map.usuari.length-1].imageicon;
			anchor=(this.map.usuari[this.map.usuari.length-1].imagewidth/2)-1;
				// makes an exception for the video marker
				if (this.map.usuari[this.map.usuari.length-1].imageicon.indexOf('icona_video')!=-1) anchor=9;
			this.map.usuari[this.map.usuari.length-1].icon.iconSize = new GSize(this.map.usuari[this.map.usuari.length-1].imagewidth, this.map.usuari[this.map.usuari.length-1].imageheight);
			this.map.usuari[this.map.usuari.length-1].icon.iconAnchor = new GPoint(anchor, this.map.usuari[this.map.usuari.length-1].imageheight);
			this.map.usuari[this.map.usuari.length-1].icon.shadow=this.map.usuari[this.map.usuari.length-1].imageshadow;
			this.map.usuari[this.map.usuari.length-1].prepareGeoCode();
			// gets the associated collections
			this.map.usuari[this.map.usuari.length-1].getCollections();
		}
		// if it is the last dataSource, then draws the points
		if (this.idx+1==this.map.source.length) this.map.drawPOIS(0);
	}
	this.addCollection=function(template, table, id, typ) { // creates a new collection definition
		id_col=this.collection.length;
		this.collection[id_col]=new Collection(id_col, template, table, id, this, typ);
		return id_col;
	}
}
function View(lat, lon, zoom, map) { // View prototype. Defines initial center point, zoom level and map type.
	this.lat=lat;
	this.long=lon;
	this.zoom=zoom;
	this.map=map;
}
function Menu(_top, _left) {
	this.container=document.createElement('div');
	this.top=parseInt(_top);
	this.left=parseInt(_left);
	this.container.style.position='absolute';
	this.container.style.top=this.top+'px';
	this.container.style.left=this.left+'px';
	this.buttons=new Array();
	this.width=0;
	this.addButton=function(text, action, width, title) {
		this.buttons[this.buttons.length]=new MenuItem(this, this.buttons.length, text, action, width, title);
		return this.buttons[this.buttons.length-1].container;
	}
	this.load=function(map) {
		// list buttons
			if (map.admin) {
				map.legend=this.addButton(txt_indexTabText+'&nbsp;<img src="'+map.path+'m_ruta.gif">', 'ugmap.showList();', 85, txt_unfoldIndexTabText);
				map.list=document.createElement('div'); // list of POIs
				map.list.className='map_user_list transp85';
				map.list.style.position='absolute';
				map.list.style.top=(parseInt(map.legend.style.top)+14)+'px';
				map.list.style.left=(parseInt(this.container.style.left)-7)+'px';
				map.list.style.visibility='hidden';
				map.map.getContainer().appendChild(map.list);
				if (map.list.addEventListener) {
					map.list.addEventListener('DOMMouseScroll',map.listMousewheel, false);
				}
			}
		// full screen/embed switch
			if (window!=top) map.fullscreen=this.addButton(txt_maximizeTabText, 'window.open(\'mapa.php\', \'\', \'fullscreen=yes, resizable=yes\');', 85, txt_maximizeTabTitle);
			else map.fullscreen=this.addButton(txt_closeTabText, 'window.close();', 70, txt_closeTabTitle);
		// reload data
			map.refresh=this.addButton(txt_refreshTabText, 'ugmap.getPOIS();', 72, txt_refreshTabTitle);
		// see current view details & pretend public switch
			if (map.realAdmin) {
				if (map.admin) {
					map.getCenter=this.addButton(txt_viewTabText, 'ugmap.getCurrentViewDetails();',56, txt_viewTabTitle);
					map.makePublic=this.addButton(txt_makePublicText, 'ugmap.loadAsPublic();',100,txt_makePublicTitle);
					map.language=this.addButton(txt_indexLangText+'&nbsp;<img src="'+map.path+'m_ruta.gif">', 'ugmap.showLang();', 82, txt_indexLangTitle);
					map.languagelist=document.createElement('div'); // list of POIs
					map.languagelist.className='map_user_list transp85';
					map.languagelist.style.position='absolute';
					map.languagelist.style.width='87px';
					map.languagelist.style.top=(parseInt(map.language.style.top)+14)+'px';
					i=75;
					if (window!=top) i=47;
					map.languagelist.style.left=(parseInt(map.language.style.left)+i)+'px';
					map.languagelist.innerHTML='<div class="mapa_menu_switch_element" onclick="ugmap.switchLang(\'es\');">Castellano</div>';
					map.languagelist.innerHTML+='<div class="mapa_menu_switch_element" onclick="ugmap.switchLang(\'ca\');">Català</div>';
					map.languagelist.innerHTML+='<div class="mapa_menu_switch_element" onclick="ugmap.switchLang(\'en\');">English</div>';
					map.languagelist.style.visibility='hidden';
					map.map.getContainer().appendChild(map.languagelist);
					if (map.languagelist.addEventListener) {
						map.languagelist.addEventListener('DOMMouseScroll',map.listMousewheel, false);
					}
				} else map.makePublic=this.addButton(txt_makeAdminText, 'ugmap.loadAsAdmin();',100,txt_makeAdminTitle);
				// 
			}
			// language switch
			
		// 
			this.container.style.visibility='visible';
	}
}
function MenuItem(menu, idx, text, action, width, title) {
	this.menu=menu;
	this.idx=idx;
	this.text=text;
	this.action=action;
	this.container=document.createElement('div');
	this.container.style.position='absolute';
	this.container.style.top='10px';
	this.container.style.left=this.menu.width+'px';
	this.container.style.width=width;
	this.menu.width+=width;
	this.container.innerHTML='<div onclick="'+action+'" onMouseOver="if (this.className==\'map_button transp60\') this.className=\'map_button transp80\'" onMouseOut="if (this.className==\'map_button transp80\') this.className=\'map_button transp60\'" class="map_button transp60" title="'+title+'">'+text+'</div>';
	this.menu.container.appendChild(this.container);
}
function infoGmap(name, mode, js_name, config) { // Main object
	this.js_name=js_name;
	this.ip=0;
	this.adminIPs='';
	this.admin=false;
	this.realAdmin='';
	this.name=name;
	this.nom=name;
	this.mode=mode;
	this.usuari=new Array();
	this.map=null;
	this.message_tips=null;
	this.iu_template='';
	this.path='';
	this.lang='en';
	this.backPath='';
	this.source=new Array();
	this.originalView=null;
	this.configFile=config;
	this.menu=null;
	this.loadAsPublic=function() {
		loc=document.location+'';
		c='&';
		if (loc.indexOf('?')==-1) c='?';
		document.location=loc	+c+'forcePublic=true';
	}
	this.loadAsAdmin=function() {
		loc=document.location+'';
		loc=loc.replace('?forcePublic=true','');
		document.location=loc.replace('&forcePublic=true','');
	}
	this.switchLang=function(l) {
		loc=document.location+'';
		con=new Array('?','&');
		for (c=0;c<con.length;++c) {
			loc=loc.replace(con[c]+'lang=ca','');
			loc=loc.replace(con[c]+'lang=es','');
			loc=loc.replace(con[c]+'lang=en','');
		}
		c='&';
		if (loc.indexOf('?')==-1) c='?';
		document.location=loc	+c+'lang='+l;
	}
	this.drawPOIS=function(i_u) {
		if (i_u<this.usuari.length) {
			if (this.usuari[i_u].lat=='' || this.usuari[i_u].long=='') {
				this.usuari[i_u].getGeoCode(this.usuari[i_u]);
			} else this.usuari[i_u].addMarker();
			setTimeout('ugmap.drawPOIS('+(i_u+1)+')',1);
		} else {
			if (this.mode=='edit') this.usuari[0].showPopUp(this.iu_template);
		}
		if (i_u==this.usuari.length && i_u>10) {
			this.showTip(txt_loaded, 'mapa_mssg mapa_mssg_saved');
			this.hideTip();
			if (window!=top && this.admin) setTimeout("ugmap.legend.childNodes[0].className='map_button transp60';ugmap.legend.childNodes[0].title='"+txt_unfoldIndexTabText+"';ugmap.fadeOut(ugmap.list, 1, 85);",2000);
		}
	}
	this.click=function() {if (this.list.style.visibility=='visible') this.showList();}
	this.homeView=function() {this.changeView(this.originalView);}
	this.changeView=function(view) {
		this.map.setCenter(new google.maps.LatLng(view.lat, view.long), parseInt(view.zoom));
		this.map.setMapType(this.map.getMapTypes()[view.map]);
	}
	this.setInterface=function() {
		this.map.enableDoubleClickZoom();
		this.map.enableContinuousZoom();
		this.map.enableScrollWheelZoom();
		this.map.addMapType(G_PHYSICAL_MAP);
		google.maps.Event.addListener(this.map, "click", function() {ugmap.click()});
		this.map.addControl(new google.maps.HierarchicalMapTypeControl());
		this.map.addControl(new google.maps.ScaleControl());
		if (window==top) { // adds large map control and overview map if we are on fullscreen
			this.map.addControl(new google.maps.OverviewMapControl());
			this.map.addControl(new google.maps.LargeMapControl());
		} else { // adds small map control if we are in a frame
			this.map.addControl(new google.maps.SmallMapControl());
		}
	}
	this.getCurrentViewDetails=function() {
		details=window.open();
		details.document.writeln('Centre: '+this.map.getCenter());
		details.document.writeln('<br/>Zoom level: '+this.map.getZoom());
		details.document.writeln('<br/>Map type: '+this.map.getCurrentMapType().getName());
		details.document.close();
	}
	this.finishStartUp=function() {
		ugmap.map = new google.maps.Map2(document.getElementById(ugmap.name));
		ugmap.setInterface(); // adds map controls and events
		ugmap.homeView(); // Sets the initial extent view and map type
		// Adds a hidden iframe, to make the downloads available
			ifr=document.createElement('div');
			ifr.innerHTML='<iframe name="temp" height="0" width="0" style="display:none;background:none;" frameborder="0"></iframe>';
			ugmap.map.getContainer().parentNode.appendChild(ifr);
		if (ugmap.admin) { // Adds admin message
			admin_mssg=document.createElement('div');
			admin_mssg.innerHTML='La teva IP forma part del grup d\'administradors: '+ugmap.ip;
			admin_mssg.style.color='red';
			admin_mssg.style.fontWeight='bold';
			ugmap.map.getContainer().appendChild(admin_mssg);
		}
		// Creates the menu
		if (window==top) left='80px';
		else left='54px';
		ugmap.menu=new Menu(0, left);
		ugmap.menu.load(ugmap);
		ugmap.map.getContainer().appendChild(ugmap.menu.container);
		// loading layer
		ugmap.message_tips=document.createElement('div'); 
			ugmap.message_tips.style.position='absolute';
			ugmap.message_tips.className='mapa_mssg_saving';
			ugmap.message_tips.style.top=(parseInt(document.body.clientHeight)-50)+'px';
			ugmap.message_tips.style.left=((ugmap.map.getSize().width/2)-130)+'px';
			ugmap.message_tips.style.visibility='visible';
			ugmap.map.getContainer().appendChild(ugmap.message_tips);
		// user counter
		ugmap.user_counter=document.createElement('div');
			ugmap.user_counter.style.position='absolute';
			ugmap.user_counter.className='mapa_counter transp80';
			ugmap.user_counter.style.top='7px';
			ugmap.user_counter.style.left=((ugmap.map.getSize().width)-340)+'px';
			ugmap.user_counter.style.visibility='visible';
			ugmap.user_counter.innerHTML=0;
			ugmap.map.getContainer().appendChild(ugmap.user_counter);
		ugmap.getPOIS();
	}
	this.startUp=function() {
		google.load('maps','2.x', {"locale" : this.lang});
		google.setOnLoadCallback(this.finishStartUp);
	}
	this.initialize=function() {
		this.source=new Array();
		getConfig=new AJAXcall('GET', this.configFile, false, this, 'parseConfig', 'XML');
		this.startUp();
	}
	this.listMousewheel=function(event) {
		if (event.preventDefault) event.preventDefault();
		event.returnValue = false;
	}
	this.parseIP=function(tmp) {
		this.ip=tmp;
		this.admin=this.adminIPs.indexOf(','+this.ip+',')!=-1;
		this.realAdmin=this.admin;
		loc=document.location+'';
		if (loc.indexOf('forcePublic=true')!=-1) this.admin=false;
	}
	this.parseLang=function(tmp) {eval(tmp);document.getElementById(this.name).innerHTML=txt_loading_map+' ...';}
	this.parseConfig=function(tmp) {
		// get root element
		config=tmp.getElementsByTagName('ugmap').item(0);
		// get the application path
		this.lang=getInnerText(config.getElementsByTagName('lang').item(0));
		loc=document.location+'';
		if (loc.indexOf('?lang=')!=-1 || loc.indexOf('&lang=')!=-1) {
			i=loc.indexOf('?lang=');
			if (i==-1) i=loc.indexOf('&lang=');
			ini=loc.substring(i+6,loc.length);
			fi=ini.indexOf('&');
			if (fi==-1) fi=ini.length;
			if (ini.substring(0,fi)!=this.lang) this.lang=ini.substring(0,fi);
		}
		this.path=getInnerText(config.getElementsByTagName('path').item(0));
		// add a slash to the path if there isn't one
			if (this.path.substring(this.path.length-1,this.path.length)!='/' && this.path!='') this.path+='/';
		getLang=new AJAXcall('GET',this.path+'lang/'+this.lang+'.js', false, this, 'parseLang', 'Text');
		// get the admins
		this.adminIPs=getInnerText(config.getElementsByTagName('admins').item(0));
		while (this.adminIPs.indexOf(' ')!=-1) this.adminIPs=this.adminIPs.replace(' ','');
		this.adminIPs=','+this.adminIPs+',';
		getIP=new AJAXcall('GET',this.path+'get_ip.php?echo_it=true', false, this, 'parseIP', 'Text');
		// get the initial extent
		ext=config.getElementsByTagName('view').item(0);
		if (window==top) ext=config.getElementsByTagName('maxView').item(0);
		lat=getInnerText(ext.getElementsByTagName('lat').item(0));
		lon=getInnerText(ext.getElementsByTagName('long').item(0)); zoom=getInnerText(ext.getElementsByTagName('zoom').item(0)); map=getInnerText(ext.getElementsByTagName('mapType').item(0));
		//if (window==top) {zoom=parseInt(zoom);lat='42.60970621339408'; lon='1.3018798828125';map=1;}
		this.originalView=new View(lat, lon, zoom, map);
		// get data sources and process them
		sources=config.getElementsByTagName('dataSource');
		for (i=0;i<sources.length;++i) {
			this.source[this.source.length]=new DataSource();
			this.source[this.source.length-1].idx=i;
			this.source[this.source.length-1].map=this;
			this.source[this.source.length-1].name=sources[i].getAttribute('name');
			for (j=0;j<sources[i].childNodes.length;++j) {
				if (sources[i].childNodes[j].nodeType==1) {
					key=sources[i].childNodes[j].tagName.toLowerCase();
					switch (key) {
						case 'category':
							break;
						case 'infotab':
							tabs=this.source[this.source.length-1].tabs;
							tab_idx=tabs.length;
							tabName=sources[i].childNodes[j].getAttribute('name');
							tabType=getInnerText(sources[i].childNodes[j].getElementsByTagName('type').item(0));
							tabTemplate=getInnerText(sources[i].childNodes[j].getElementsByTagName('template').item(0));
							tabUserlevel=getInnerText(sources[i].childNodes[j].getElementsByTagName('userlevel').item(0));
							addIt=false;
							
							if (tabUserlevel=='admin') {
								if (this.admin) addIt=true;
							} else addIt=true;
							if (addIt) {
								tabs[tab_idx]=new Tab(tab_idx, this.source[this.source.length-1], tabName, tabType, tabTemplate);
								//tabs[tab_idx].getTemplate();
								switch (tabType.toLowerCase()) {
									case 'collection':
									case 'links':
									case 'pictures':
										itemTable=getInnerText(sources[i].childNodes[j].getElementsByTagName('table').item(0));
										itemTemplate=getInnerText(sources[i].childNodes[j].getElementsByTagName('itemTemplate').item(0));
										itemId=getInnerText(sources[i].childNodes[j].getElementsByTagName('id').item(0));
										if (itemTable!='' && itemId!='') {
											id_col=this.source[this.source.length-1].addCollection(itemTemplate, itemTable, itemId, tabType);
										}
										break;
								}
							}
							break;
						default:
							eval('this.source[this.source.length-1].'+key+'="'+getInnerText(sources[i].childNodes[j])+'"');
							break;
					}
				}
			}
		}
		if(this.path.indexOf('..')==-1) {
			path=this.path; i=0;
			while (path.indexOf('/')!=-1) {
				path=path.replace('/','');
				++i;
			}
		}
		path='';
		while (i>0) {
			path+='../';
			--i;
		}
		this.backPath=path;
	}
	this.getPOIS=function() {
		this.removePOIS();
		if (this.list && this.list.style.visibility=='hidden') this.showList();
		for (s=0;s<this.source.length;++s) {
			for (t=0;t<this.source[s].tabs.length;++t) {
				this.source[s].tabs[t].getTemplate();
			}
			this.source[s].getPOIS();
		}
	}
	this.removePOIS=function() {
		if (this.list) this.list.innerHTML='';
		if (this.user_counter) this.user_counter.innerHTML=0;
		for (i=0;i<this.usuari.length;++i) {
			this.usuari[i].removeMarker();
		}
		this.usuari=new Array();
	}
	this.showLang=function() {
		if (this.languagelist) {
			if (this.languagelist.style.visibility=='visible') {
				this.language.childNodes[0].className='map_button transp60';
				//this.language.childNodes[0].title=txt_unfoldIndexTabText;
				this.fadeOut(this.languagelist, 20, 85);
			} else {
				this.languagelist.style.visibility='visible';
				this.language.childNodes[0].className='map_button_on transp85';
				//this.language.childNodes[0].title=txt_foldIndexTabText;
			}
		} else alert('No s\'ha pogut trobar la llegenda');
	}
	this.showList=function() {
		if (this.list) {
			if (this.list.style.visibility=='visible') {
				this.legend.childNodes[0].className='map_button transp60';
				this.legend.childNodes[0].title=txt_unfoldIndexTabText;
				this.fadeOut(this.list, 20, 85);
			} else {
				this.list.style.visibility='visible';
				this.legend.childNodes[0].className='map_button_on transp85';
				this.legend.childNodes[0].title=txt_foldIndexTabText;
			}
		} else alert('No s\'ha pogut trobar la llegenda');
	}
	this.tipIsHiding=false;
	this.isHiding=false;
	this.currentInterval=null;
	this.hidingState=null;
	this.showTip=function(txt, className) {
		this.message_tips.style.filter='alpha(opacity=80);';
		this.message_tips.setAttribute('style',this.message_tips.getAttribute('style')+';-moz-opacity:.80;opacity:.80;');
		clearInterval(this.hidingState);
		this.tipIsHiding=false;
		this.message_tips.innerHTML=txt;
		this.message_tips.className=className;
		this.message_tips.style.visibility='visible';
	}
	this.fadeOut=function(o, speed, endWith) {
		if (!this.isHiding) {
			this.isHiding=o;
			this.currentInterval=setInterval(this.js_name+'.fadeOut(\'null\', '+speed+', '+endWith+')',1);
		} else {
			estil=this.isHiding.getAttribute('style');
			if (is_ie) op=this.isHiding.style.filter;
			else {
				op=this.isHiding.getAttribute('style').substring(this.isHiding.getAttribute('style').indexOf('opacity'),this.isHiding.getAttribute('style').length);
				if (this.isHiding.getAttribute('style').indexOf('opacity')==-1) op='opacity:.'+endWith+';';
			}
			if(op=='undefined') {
				op='alpha(opacity=0);';
			}
			if (op=='') {
				if (is_ie) this.isHiding.style.filter='alpha(opacity='+endWith+');';
				else this.isHiding.setAttribute('style',estil+';-moz-opacity:.'+endWith+';opacity:.'+endWith+';');
			} else {
				fi=op.length;
				if (op.indexOf(')')!=-1) fi=op.indexOf(')')-1;
				if (op.indexOf(';')!=-1) fi=op.indexOf(';');
				if ((typeof op)=='string') op=parseFloat(op.substring(op.indexOf('opacity')+8,fi));
				else op=0;
				if (op==1) op=100;
				if (op<1) op=parseInt(op*100);
				newOp=op-speed;
				if (newOp<10) newOp='0'+newOp;
				//if (newOp<0) newOp=0;
				if (newOp>10) {
					if (is_ie) this.isHiding.style.filter='alpha(opacity='+newOp+');';
					else {
						this.isHiding.setAttribute('style',estil+';-moz-opacity:.'+newOp+';opacity:.'+newOp+';');
					}
				} else {
					if (is_ie) this.isHiding.style.filter='alpha(opacity='+(endWith)+');';
					else this.isHiding.setAttribute('style',estil+';-moz-opacity:.'+endWith+';opacity:.'+endWith+';');
					this.isHiding.style.visibility='hidden';
					clearInterval(this.currentInterval);
					this.isHiding=false;
				}
			}
		}
	}
	this.hideTip=function() {
		estil=this.message_tips.getAttribute('style');
		if (!this.tipIsHiding) {
			this.tipIsHiding=true;
			this.hidingState=setInterval(this.js_name+'.hideTip()',100);
		} else {
			if (is_ie) op=this.message_tips.style.filter;
			else op=this.message_tips.getAttribute('style').substring(this.message_tips.getAttribute('style').indexOf('opacity'),this.message_tips.getAttribute('style').length);
			if(op=='undefined') {
				op='alpha(opacity=0);';
			}
			if (op=='') {
				if (is_ie) this.message_tips.style.filter='alpha(opacity=95);';
				else this.message_tips.setAttribute('style',estil+';-moz-opacity:.95;opacity:.95;');
			} else {
				fi=op.length;
				if (op.indexOf(')')!=-1) fi=op.indexOf(')')-1;
				if (op.indexOf(';')!=-1) fi=op.indexOf(';');
				if ((typeof op)=='string') op=parseFloat(op.substring(op.indexOf('opacity')+8,fi));
				else op=0;
				if (op==1) op=100;
				if (op<1) op=parseInt(op*100);
				newOp=op-5;
				if (newOp<10) newOp='0'+newOp;
				if (op>0) {
					if (is_ie) this.message_tips.style.filter='alpha(opacity='+newOp+');';
					else {
						this.message_tips.setAttribute('style',estil+';-moz-opacity:.'+newOp+';opacity:.'+newOp+';');
					}
				} else {
					if (is_ie) this.message_tips.style.filter='alpha(opacity=100);';
					else this.message_tips.setAttribute('style',estil+';-moz-opacity:1;opacity:1;');
					this.message_tips.style.visibility='hidden';
					clearInterval(this.hidingState);
					this.tipIsHiding=false;
				}
			}
		}
	}
}
function info_usuari(idx, source) {
	this.id=i;
	this.idx=idx;
	this.source=source;
	this.icon = new GIcon();
	this.icon.shadow = this.source.map.path+"marker_shadow.png";
	//this.icon.iconSize = new GSize(20, 34);
	this.icon.shadowSize = new GSize(30, 24);
	//this.icon.iconAnchor = new GPoint(9, 34);
	this.icon.infoWindowAnchor = new GPoint(10, 0);
	this.icon.infoShadowAnchor = new GPoint(18, 25);
	this.category=null;
	this.template=null;
	this.geocode=null;
	this.manualMove=false;
	this.geocoder=new GClientGeocoder();
	this.prevZoom=2;
	this.prevPoint=null;
	this.prevMapType=null;
	this.collection=new Array();
	this.tmp=null;
	this.removeMarker=function() {
		this.source.map.map.removeOverlay(this.marker);
	}
	this.depuraTemplate=function(tmp) {
		for (f=0;f<this.source.fieldNames.length;++f ) {
			field=this.source.fieldNames[f];
			while (tmp.indexOf('|'+field+'|')!=-1) tmp=tmp.replace('|'+field+'|',eval('this.'+field));
		}
		while (tmp.indexOf('|id|')!=-1) tmp=tmp.replace('|id|',this.id);
		while (tmp.indexOf('|idx|')!=-1) tmp=tmp.replace('|idx|',this.id);
		while (tmp.indexOf('|zoomin|')!=-1) tmp=tmp.replace('|zoomin|',this.source.map.js_name+'.usuari['+idx+'].zoomIn(this);');
		return tmp;
	}
	this.zoomIn=function(o) {
		if (!this.prevPoint) {
			this.prevZoom=this.source.map.map.getZoom();
			this.prevPoint=this.source.map.map.getCenter();
			this.prevMapType=this.source.map.map.getCurrentMapType();
			this.source.map.map.panTo(this.point);
			this.source.map.map.setZoom(13);
			mt=this.source.map.map.getMapTypes();
			this.source.map.map.setMapType(mt[2]);
			o.src=this.source.map.path+'zoomout.gif';
			o.title='Tornar a la vista anterior';
		} else {
			this.source.map.map.panTo(this.prevPoint);
			this.source.map.map.setZoom(this.prevZoom);
			this.source.map.map.setMapType(this.prevMapType);
			this.prevZoom=2;
			this.prevPoint=null;
			this.prevMapType=null;
			o.src=this.source.map.path+'zoomin.gif';
			o.title='Veure d\'aprop';
		}
	}
	this.getCollections=function() {
		for (i=0;i<this.source.collection.length;++i) {
			myCol=this.addCollection(this.source.collection[i].template,this.source.collection[i].table, this.source.collection[i].id, this.source.collection[i].type);
			uri=this.source.map.path+'get_collection.php?root='+this.source.map.backPath+'&source='+this.source.idx+'&id='+this.id+'&config='+this.source.map.configFile+'&coll='+myCol;
			http2=new getHTTPObject();
			http2.open('GET', uri, false);
			http2.send(null);
			if (http2.status==200) {
				tmp2=http2.responseText;
				tmp2=tmp2.split('|');
				tmp2[0]=tmp2[0].split(',');
				for (j=0;j<tmp2[0].length;++j) {
					tmp2[0][j]=tmp2[0][j].toLowerCase();
					fieldName=tmp2[0][j];
					while (fieldName.indexOf(' ')!=-1) fieldName=fieldName.replace(' ','');
					if (eval('CollectionItem.prototype.'+fieldName)+''=='undefined') {
						eval('CollectionItem.prototype.'+fieldName+'=null;');
					}
				}
				this.collection[myCol].fieldNames=tmp2[0];
				for (k=1;k<tmp2.length;++k) {
					tmp2[k]=tmp2[k].split(',');
					
					this.collection[myCol].item[this.collection[myCol].item.length]=new CollectionItem(this.collection[myCol]);
					for (u=0;u<tmp2[k].length;++u) {
						fieldName=tmp2[0][u];
						fieldValue=tmp2[k][u];
						while (fieldValue.indexOf('.coma.')!=-1) fieldValue=fieldValue.replace('.coma.',',');
						while (fieldValue.indexOf('.apos.')!=-1) fieldValue=fieldValue.replace('.apos.','\\\'');
						
						eval('this.collection['+myCol+'].item['+(this.collection[myCol].item.length-1)+'].'+fieldName+'=\''+ripBreaks(fieldValue)+'\'');
					}
					
				}
			}
		}
	}
	this.targetMe=function() {this.source.map.map.panTo(this.point);}
	this.showPopUp=function(tmp) {
		// Hide shortcut list if it is visible
		if (this.source.map.list && this.source.map.list.style.visibility=='visible' && (window!=top) ) this.source.map.showList();
		// Make it center on the marker when closing the info window
		if (window!=top) google.maps.Event.addListener(this.source.map.map.getInfoWindow(), "closeclick", function() {ugmap.usuari[idx].targetMe()});
		var tabs = new Array();
		for (t=0;t<this.source.tabs.length;++t) {
			addIt=true;
			if (this.source.tabs[t].type=='video' && (this.video=='' || this.video+'' == 'undefined')) addIt=false;
			if (this.source.tabs[t].type=='pictures') {
				a=0; found=false;
				while (a<this.collection.length && !found) {
					if (this.collection[a].type=='pictures') found=true;
					else a=a+1;
				}
				if (found) {
					if (this.collection[a].item.length<1) addIt=false;
				} else addIt=false;
			}
			if (this.source.tabs[t].type=='links') {
				a=0; found=false;
				while (a<this.collection.length && !found) {
					if (this.collection[a].type=='links') found=true;
					else a=a+1;
				}
				if (found) {
					if (this.collection[a].item.length<1) addIt=false;
				} else addIt=false;
			}
			if (addIt) {
				temp_template=this.source.tabs[t].template;
				for (c=0;c<this.collection.length;++c) {
					temp_template=this.collection[c].load(temp_template, c);
				}
				tabContent=this.depuraTemplate(temp_template);
				if (t==1) tabContent+='<img src="'+this.source.map.path+'blank.gif" height="0" width="0" onload="loadModules('+idx+')">';
				tabs[tabs.length]=new GInfoWindowTab(this.source.tabs[t].name, tabContent);
			}
		}
		if (tabs.length>0) this.marker.openInfoWindowTabs(tabs);
	}
	this.shortCutEnd=function() {
		this.source.map.map.setZoom(11);
		google.maps.Event.removeListener(this.listener);
	}
	this.shortCut=function() {
		//this.targetMe();
		//this.targetMe();
		//this.listener=google.maps.Event.addListener(this.source.map.map, "moveend", function() {ugmap.usuari[idx].shortCutEnd()});
		
		//this.source.map.map.setZoom(11);
		
		//this.source.map.map.setCenter(new google.maps.LatLng(this.marker.getPoint().y, this.marker.getPoint().x), 12);
		if (window==top) {
			//if (this.source.map.map.getZoom()<11) this.source.map.map.zoomIn();
			//else this.source.map.map.setMapType(this.source.map.map.getMapTypes()[2]);
		}
		this.popUp();
	}
	this.addCollection=function(template, table, id, typ) {
		id_col=this.collection.length;
		this.collection[id_col]=new Collection(id_col, template, table, id, this, typ);
		this.collection[id_col].getTemplate();
		return id_col;
	}
	this.point=null;
	this.marker=null;	
	this.searchedCP=false;
	this.prepareGeoCode=function() {
		if (this.source.geocode+''!='undefined' && this.source.geocode!='') {
			while (this.source.geocode.indexOf(' ')!=-1) this.source.geocode=this.source.geocode.replace(' ','');
			this.geocode=this.source.geocode;
			tmp='';
			if (this.geocode.indexOf(',')!=-1) tmp=this.geocode.split(',');
			if (this.geocode.indexOf('+')!=-1) tmp=this.geocode.split('+');
			if (tmp=='') eval('this.geocode=this.'+this.geocode.toLowerCase());
			else {
				res='';
				for (gc=0;gc<tmp.length;++gc) {
					res+=eval('this.'+tmp[gc])+' ';
				}
				this.geocode=res;
			}
		}
	}
	this.getGeoCode=function(o) {
		if (this.geocode!='') {
			o.geocoder.getLatLng(this.geocode,function(t) {o.save(t);});
		} else {
			this.save();
		}
	}
	this.save=function(t) {
		if (t) {
			this.lat=t.y;
			this.long=t.x;
			this.addMarker();
			this.saveCoordinates();
		} else if (!this.searchedCP) {
			this.searchedCP=true;
			this.getGeoCode(this);
		} else {
			if (this.source.map.admin) {
				alert('No s\'han trobat les coordenades de l\'adreça "'+this.geocode+'" (taula: '+this.source.table+' | id: '+this.id+')');
			}
			this.lat=0;
			this.long=0;
			this.addMarker();
		}
	}
	this.addMarker=function() {
		this.point=new google.maps.LatLng(this.lat, this.long);
		_title=eval('this.'+this.source.title);
		if (!this.source.map.admin) {
			_title='';
			this.source.map.map.disableInfoWindow();
		}
		if (this.source.map.mode=='edit') {
			if (ugmap.usuari.length==0) alert('No s\'ha trobat cap registre a la base de dades');
			else {
				this.marker=new google.maps.Marker(this.point, {draggable: true, icon:this.icon, title:_title});
				google.maps.Event.addListener(this.marker, "dragstart", function() {ugmap.usuari[0].marker.closeInfoWindow()});
				google.maps.Event.addListener(this.marker, "dragend", function() {ugmap.usuari[0].saveCoordinates()});
			}
		} else {
			if (this.source.map.admin) {
				this.marker=new google.maps.Marker(this.point, {draggable: true, icon:this.icon, title:_title});
				google.maps.Event.addListener(this.marker, "dragstart", function() {ugmap.usuari[idx].marker.closeInfoWindow()});
				google.maps.Event.addListener(this.marker, "dragend", function() {ugmap.usuari[idx].updateCoordinates()});
			} else {
				this.marker=new google.maps.Marker(this.point, {icon:this.icon, clickable:false});
			}
		}
		this.source.map.map.addOverlay(this.marker);
		this.marker.enableDragging();
		//if (ugmap.admin) google.maps.Event.addListener(this.marker, "click", this.popUp);
		if (this.source.map.list && this.source.map.admin) {
			cat=this.catname.split('.');
			so=cat[0];
			cat=cat[1];
			el=document.createElement('div');
			el.className='mapa_list_element';
			c='999999';
			if (this.catcolor+''!='undefined' && this.catccolor+''!='null') c=this.catcolor;
			el.style.borderBottom='1px dashed #'+c;
			
			el.style.color='#'+c;
			el.innerHTML='<a href="javascript:void(0);" onclick="ugmap.usuari['+idx+'].shortCut();" title="'+eval('this.'+this.source.title)+'"><img src="'+this.imageicon+'" height="11" align="top" border="0"> '+eval('this.'+this.source.title)+'</a>';
			//el.title=eval('this.'+this.source.title);
			if (document.getElementById(cat)) {
				document.getElementById(cat).appendChild(el);
				document.getElementById(cat).style.background='#'+c;
			} else if (document.getElementById(so)) document.getElementById(so).appendChild(el);
			//alert(this.source.map.map.getSize().height);
			this.source.map.list.scrollLeft=100;
			if (this.source.map.list.scrollLeft>0) this.source.map.list.style.width=parseInt(this.source.map.list.clientWidth)+parseInt(this.source.map.list.scrollLeft)+30;
			if (parseInt(this.source.map.list.clientHeight)+70>this.source.map.map.getSize().height) {
				
				this.source.map.list.style.height=this.source.map.map.getSize().height-70;
				this.source.map.list.style.overflow='auto';
			}
		}
		if (this.source.map.user_counter) {
			n=parseInt(this.source.map.user_counter.innerHTML);
			this.source.map.user_counter.innerHTML=(n+1)+' '+txt_userClassName;
		}
		google.maps.Event.addListener(this.marker, "click", this.popUp);
	}
	this.popUp=function() {ugmap.usuari[idx].showPopUp(ugmap.iu_template);}
	this.updateCoordinates=function() {
		this.manualMove=true;
		if (confirm('El marcador '+this.idx+' (Tabla: '+this.source.table+', Id: '+this.id+') ha sido desplazado. Deseas guardar las nuevas coordenadas?')) {
			this.saveCoordinates();
		}
	}
	this.saveCoordinates=function() {
		if (this.manualMove){
			this.source.map.showTip('Guardando cambios ...', 'mapa_mssg mapa_mssg_saving');
			/*this.source.map.message_tips.style.filter='alpha(opacity=100);';
			this.source.map.message_tips.setAttribute('style',this.source.map.message_tips.getAttribute('style')+';-moz-opacity:1;opacity:1;');
			clearInterval(this.source.map.hidingState);
			this.source.map.tipIsHiding=false;
			this.source.map.message_tips.innerHTML='Guardando cambios ...';
			this.source.map.message_tips.className='mapa_mssg mapa_mssg_saving';
			this.source.map.message_tips.style.visibility='visible';*/
		}
		add='&root='+this.source.map.backPath+'&config='+this.source.map.configFile;
		call=new AJAXcall('GET', this.source.map.path+'save_coordinates.php?id='+this.id+add+'&lat='+this.marker.getPoint().y+'&lon='+this.marker.getPoint().x+'&source='+this.source.idx, true, this, 'coordinatesSaved', 'Text');
	}
	this.coordinatesSaved=function() {
		if (this.manualMove){
			setTimeout('ugmap.hideTip()',300);
			this.source.map.map.panTo(new google.maps.LatLng(this.marker.getPoint().y, this.marker.getPoint().x));
		}
		this.manualMove=false;
	}
}
function initialize() {ugmap.initialize();}
function Tab(idx, source, name, typ, template) {
	this.idx=idx;
	this.source=source;
	this.type=typ;
	this.name=name;
	this.template='';
	this.saveTemplate=function(data, responseCode) {
		while (data.indexOf('\n')!=-1) data=data.replace('\n','');
		while (data.indexOf('\r')!=-1) data=data.replace('\r','');
		while (data.indexOf('\t')!=-1) data=data.replace('\t','');
		source.tabs[idx].template=data;
	}
	this.getTemplate=function() {GDownloadUrl(ugmap.path+template, source.tabs[idx].saveTemplate);}
}
function Collection(idx, template, table, id, u, typ) {
	this.template=template;
	this.table=table;
	this.id=id;
	this.type=typ;
	this.item=new Array();
	this.fieldNames=null;
	this.saveTemplate=function(data, responseCode) {
		while (data.indexOf('\n')!=-1) data=data.replace('\n','');
		while (data.indexOf('\r')!=-1) data=data.replace('\r','');
		while (data.indexOf('\t')!=-1) data=data.replace('\t','');
		u.collection[idx].template=data;
	}
	this.getTemplate=function() {GDownloadUrl(ugmap.path+template, u.collection[idx].saveTemplate);}
	this.load=function(temp, col_id) {
		if (temp.indexOf('|'+this.table+'|')!=-1) {
			tt='';
			for (i=0;i<this.item.length;++i) {
				tt+=this.item[i].depuraTemplate(this.template);
			}
			add='';
			switch (this.type) {
				case 'pictures':
					tipus='fotografies';
					num=u.collection[col_id].item.length;
					if (num==1) tipus='fotografia';
					if (num!=1) {
						temp=temp.replace('|num_pictures|', '<a href="javascript:void(0)" onClick="batchMove(-20);" onMouseOver="startMoving();batchMove(-5)" onMouseOut="stopMoving()" title="Fes clic per a accelerar el desplaçament"><img src="mapa/m_back.gif" border="0"></a> '+num+' '+tipus+'  <a href="javascript:void(0)" onClick="batchMove(20);" onMouseOver="startMoving();batchMove(5)" onMouseOut="stopMoving()" title="Fes clic per a accelerar el desplaçament"><img src="mapa/m_forward.gif" border="0"></a>');
					} else {
						temp=temp.replace('|num_pictures|', num+' '+tipus);
					}
					add='<img src="'+ugmap.path+'blank.gif" width="0" height="0" onload="addPicturesUI(this.parentNode.parentNode.parentNode.parentNode)">';
					break;
				case 'links':
					tipus='enllaços';
					num=u.collection[col_id].item.length;
					if (num==1) tipus='enllaç';
					temp=temp.replace('|num_links|', num+' '+tipus);
					break;
			}
			while (temp.indexOf('|'+this.table+'|')!=-1) {
				temp=temp.replace('|'+this.table+'|', tt+add);
			}
		}
		return temp;
	}
}
function CollectionItem(col) {
	this.parentCollection=col;
	this.depuraTemplate=function(tmp) {
		for (f=0;f<this.parentCollection.fieldNames.length;++f ) {
			field=this.parentCollection.fieldNames[f];
			newVal=eval('this.'+field);
			if (this.parentCollection.type=='links' && field=='fitxer') {
				if (newVal.indexOf(';')!=-1) {
					temporal=newVal.split(';');
				} else temporal=new Array(newVal);
				newVal='';
				for (tp=0;tp<temporal.length;++tp) {
					newVal+='<a href="'+temporal[tp]+'" target="_blank">'+temporal[tp]+'</a><br/>';
				}
			}
			while (tmp.indexOf('|'+field+'|')!=-1) tmp=tmp.replace('|'+field+'|',newVal);
		}
		return tmp;
	}
}
function loadVideo(id, dst, titol) {
	dst.style.padding='2px';
	h=parseInt(dst.style.height); w=parseInt(dst.style.width);
	var v = new SWFObject(ugmap.path+"player_flv_maxi.swf", dst.id, w, h, "7", "#fff");
	v.addParam("allowfullscreen","true");
	v.addParam("wmode","transparent");
	v.addVariable("flv", 'downloads/'+id);
	v.addVariable("autoplay", '1');
	v.addVariable("showvolume", '1');
	v.addVariable("showtime", '1');
	//v.addVariable("showfullscreen", '1');
	v.addVariable("playercolor", 'CC6600');
	v.addVariable("buttonovercolor", 'FFFF00');
	v.addVariable("slidercolor1", '0000FF');
	v.addVariable("slidercolor2", '6666FF');
	v.addVariable("bgcolor", 'FFFFFF');
	v.addVariable("bgcolor1", 'FFFFFF');
	v.addVariable("bgcolor2", 'FFFFFF');
	v.addVariable("title", titol);
	//v.addVariable("height",h);
	//v.addVariable("displayheight",h);
	//v.addVariable("width",w);
	v.write(dst.id);
}
function loadModules(uid) { // loads the modules
	uid=parseInt(uid);
	uo=ugmap.usuari[uid];
	// load minimap
	if (document.getElementById('mapa_info_minimap')) {
		mini=document.getElementById('mapa_info_minimap');
		mini.style.width='160px'; mini.style.height='160px';
		this.map = new google.maps.Map2(mini);
		this.map.enableDoubleClickZoom();
		this.map.enableContinuousZoom();
		this.map.enableScrollWheelZoom();
		this.map.addControl(new google.maps.SmallZoomControl());
		// Center view to the current user
		this.marker=new google.maps.Marker(uo.point, {icon:uo.icon, title:eval('uo.'+uo.source.title), clickable:false});
		this.map.setCenter(new google.maps.LatLng(this.marker.getPoint().y, this.marker.getPoint().x), 16);
		this.map.setMapType(this.map.getMapTypes()[2]);
		this.map.addOverlay(this.marker);
		this.map.checkResize();
	}
}
function addPicturesUI(s) { // adds the left and right control panels to the pictures tab
	space=130; padding=16;
	ui=document.createElement('div');
	h=(parseInt(s.style.height));
	w=(parseInt(s.style.width)/2)-space;
	ui.style.height=h+'px';
	ui.style.width=(w+(padding*2))+'px';
	//ui.style.border='1px solid black';
	ui.innerHTML='<img src="'+ugmap.path+'blank.gif" style="float:left;width:'+(w+(padding*2))+'px;height:'+h+'px;">';
	ui.style.position='absolute';
	ui.style.zIndex=10;
	ui.style.top='48px';
	ui.style.left=(-padding)+'px';
	createEvent(ui, 'mouseover', 'moveBack');
	createEvent(ui, 'mouseout', 'stopMoving');
	if (is_ie) s.parentNode.parentNode.parentNode.appendChild(ui);
	else s.parentNode.parentNode.appendChild(ui);
	ui2=document.createElement('div');
	ui2.style.height=h+'px';
	ui2.style.width=(w+(padding+10))+'px';
	//ui2.style.border='1px solid black';
	ui2.innerHTML='<img src="'+ugmap.path+'blank.gif" style="float:left;width:'+(w+(padding+10))+'px;height:'+h+'px;">';
	ui2.style.position='absolute';
	ui2.style.zIndex=10;
	ui2.style.top='48px';
	ui2.style.left=(w+(space*2)+7)+'px';
	createEvent(ui2, 'mouseover', 'moveForward');
	createEvent(ui2, 'mouseout', 'stopMoving');
	if (is_ie) s.parentNode.parentNode.parentNode.appendChild(ui2);
	else s.parentNode.parentNode.appendChild(ui2);
}
function createEvent(el, ev, fu) { // creates an event
	if (el.addEventListener) el.addEventListener (ev,eval(fu),false);
	else if (el.attachEvent) el.attachEvent('on'+ev,eval(fu));
	else eval('el.on'+ev+' = '+fu);
}
function moveBack(event) { // scroll the picture strip to the right
	startMoving();
	batchMove(-1);
}
function moveForward(event) { // scroll the picture strip to the left
	startMoving();
	batchMove(1);
}
moving=false;
function startMoving() {moving=true;} // start scrolling the picture strip
function stopMoving() {moving=false;} // stop scrolling the picture strip
function batchMove(num) { // scroll the picture strip
	s=document.getElementById('mapa_info_pictures');
	if (parseInt(s.scrollLeft)>-10 && moving) {
		s.scrollLeft=parseInt(s.scrollLeft)+num;
		setTimeout('batchMove('+num+')',1);
	}
}
