$(function(){
	var rss = false;
	var banner = false;
	var wms = false;
	var ftp = false;

	// Eventos para las extensiones doc|xls|ppt|mdb|pdf|zip|txt|rar|exe|wma|mov|avi|wmv|mp3|mp4|csv|tmx|rdf|xml|odt|ods|odp|odg|kmz|kml|shp
	$("a[href$='.doc']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'DOC', texto]);
	});
	$("a[href$='.xls']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'XLS', texto]);
	});
	$("a[href$='.ppt']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'PPT', texto]);
	});
	$("a[href$='.mdb']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'MDB', texto]);
	});
	$("a[href$='.pdf']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'PDF', texto]);
	});
	$("a[href$='.zip']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'ZIP', texto]);
	});
	$("a[href$='.txt']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'TXT', texto]);
	});
	$("a[href$='.rar']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'RAR', texto]);
	});
	$("a[href$='.exe']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'EXE', texto]);
	});
	$("a[href$='.wma']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'WMA', texto]);
	});
	$("a[href$='.mov']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'MOV', texto]);
	});
	$("a[href$='.avi']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'AVI', texto]);
	});
	$("a[href$='.wmv']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'WMV', texto]);
	});
	$("a[href$='.mp3']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'MP3', texto]);
	});
	$("a[href$='.mp4']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'MP4', texto]);
	});
	$("a[href$='.csv']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'CSV', texto]);
	});
	$("a[href$='.tmx']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'TMX', texto]);
	});
	$("a[href$='.rdf']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'RDF', texto]);
	});
	$("a[href$='.xml']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'XML', texto]);
	});
	$("a[href$='.odt']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'ODT', texto]);
	});
	$("a[href$='.odf']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'ODF', texto]);
	});
	$("a[href$='.ods']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'ODS', texto]);
	});
	$("a[href$='.odp']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'ODP', texto]);
	});
	$("a[href$='.odg']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'ODG', texto]);
	});	
	$("a[href$='.kmz']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'KMZ', texto]);
	});		
	$("a[href$='.kml']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'KML', texto]);
	});		
	$("a[href$='.shp']").click(function(){
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Descarga', 'SHP', texto]);
	});		
	//Fin formato	
	
	
	//Evento para el clic de suscripción al RSS del portal
	$("a[href*='r01hPresentationRSS']").click(function(){
		rss = true;
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Suscripcion', 'RSS', texto]);
	});
	
	//Evento para el clic de acceso al servicio WMS del portal
	$("a[href*='WMS']").click(function(){
		wms = true;
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Servicio de Mapas WMS', 'WMS', texto]);
	});
	//Evento para el clic de acceso al FTP del portal
	$("a[href*='ftp.geo.euskadi.net']").click(function(){
		ftp = true;
		var texto = $(this).text();
		_gaq.push(['_trackEvent', 'Servicio FTP', 'FTP', texto]);
	});
	
	// Evento para elementos promocionales internos (requiere el uso del class="banner")
	$(".banner").click(function(){
		banner = true;
		var texto = $(this).text();
		var destino = $(this).attr("href");
		_gaq.push(['_trackEvent', 'Banners', texto, destino]);
	});	
	// Evento para los enlaces de salida
	$("a[href^='http:']").click(function(){
		if(!rss && !banner){
			var destino = $(this).attr("href").split('/')[2];
			var texto = $(this).text() || $(this).attr("alt") || destino;
			_gaq.push(['_trackEvent', 'Salida', texto, destino]);
		}
	});
	//Para los enlaces seguros (https)
	$("a[href^='https:']").click(function(){
		if(!rss && !banner){
			var destino = $(this).attr("href").split('/')[2];
			var texto = $(this).text() || $(this).attr("alt") || destino;
			_gaq.push(['_trackEvent', 'Salida', texto, destino]);
		}
	});
	// Evento para la nube de tags
	$(".r01gCloud ul li a").click(function(){
		var destino = $(this).attr("href");
		var tag = $(this).text() || $(this).attr("alt") || destino;
		_gaq.push(['_trackEvent', 'Nube de tags', tag, destino]);
	});
});
