	//
	fCookie = function(){ this.init(); }
	var p = fCookie.prototype;
	
	p.path = DIR_ROOT;
	
	p.init = function(){ }
	
	p.set = function(n, v){
		var d = new Date();
		d.setHours(d.getHours() + 1);
		//d.setSeconds(d.getSeconds() + 3);
		var t = d.toGMTString();
		document.cookie = n + '=' + escape(v) + '; expires=' + t + '; path=' + this.path + ';';
	}
	
	p.unset = function(n){
		document.cookie = n + '=; expires=Fri, 21 Dec 1976 04:31:24 GMT; path=' + this.path + ';';
	}
	
	p.get = function(n){
		var iIni = 0, iEnd = 0, ret = '';
		if (document.cookie.length > 0){
			var iIni = document.cookie.indexOf(n + '=');
			if (iIni != -1){ 
				iIni = iIni + n.length + 1; 
				iEnd = document.cookie.indexOf(";", iIni);
				if(iEnd == -1) iEnd = document.cookie.length;
				ret = unescape(document.cookie.substring(iIni, iEnd));
			}
		}
		return ret;
	}
	
	var Cookie = new fCookie();
	
	var oRecorridos = {
		req: null, 
		corredores: {total:0}, 
		markers: {}, 
		timeouts: {}, 
		lineasTotal: 0, 
		esperar: false, 
		polylines: [], 
		markersPara: [], 
		hidenMarkers: true, 
		//
		init: function(){
			this.eSolapas = $('solapasRecorrido');
			this.eLoader = $('loaderRecorrido');
			this.eRecorrido = $('grillaRecorrido');
			this.eFrecuencia = $('grillaFrecuencia');
			this.eParadas = $('grillaParadas');
			
			this.req = new Request();
			this.req.listener = this.onLoad.closure(this);
		}, 
		//
		search: function(){
			if (!this.req) { this.init(); }
			var v = 'linea' + SEP_IGUAL + this.iLinea + SEP_AND;
			
			this.esperar = true;
			this.eLoader.style.display = 'block';
			this.req.pedir('/requests/recorrido_linea.php', v);
		}, 
		onLoad: function(){
			var d = this.req.respuestaXML, o = null;
			
			this.eLoader.style.display = 'none';
			this.esperar = false;
			
			if (!!d && d.getAttribute('exito') == 1) {
				o = document.createElement('div');
				o.innerHTML = d.childNodes[0].data;
				if (this.eRecorrido.hasChildNodes()) {
					this.eRecorrido.insertBefore(o, this.eRecorrido.firstChild);
				}
				else {
					this.eRecorrido.appendChild(o);
				}
				this.corredores[this.iCorredor].lineas[this.iLinea].recorrido = o;
				
				o = document.createElement('div');
				o.innerHTML = d.childNodes[1].data;
				if (this.eFrecuencia.hasChildNodes()) {
					this.eFrecuencia.insertBefore(o, this.eFrecuencia.firstChild);
				}
				else {
					this.eFrecuencia.appendChild(o);
				}
				this.corredores[this.iCorredor].lineas[this.iLinea].frecuencia = o;
				
				o = document.createElement('div');
				o.innerHTML = d.childNodes[2].data;
				if (this.eParadas.hasChildNodes()) {
					this.eParadas.insertBefore(o, this.eParadas.firstChild);
				}
				else {
					this.eParadas.appendChild(o);
				}
				this.corredores[this.iCorredor].lineas[this.iLinea].paradas = o;
				
				var e = o.getElementsByTagName('script');
				if (e.length > 0) {
					var r, i;
					this.corredores[this.iCorredor].lineas[this.iLinea].markers = {ida: [], vuelta: []};
					eval(e[0].innerHTML);
					for (r in a) {
						for (i in a[r]) {
							this.addMarkerPara(this.iCorredor, this.iLinea, r, i, a[r][i]);
						}
					}
				}
				
				var a = false;
				if(trim(d.childNodes[3].data) != ''){
					eval(d.childNodes[3].data);
					var e = this.corredores[this.iCorredor].lineas[this.iLinea].e;
					
					this.corredores[this.iCorredor].lineas[this.iLinea].polyline = new GPolyline(a, e.style.backgroundColor, 4, 0.7, {clickable: true});
					var name = e.innerHTML;
					GEvent.addListener(this.corredores[this.iCorredor].lineas[this.iLinea].polyline, 'click', function(latlng) {
						oRecorridos.map.closeInfoWindow();
						oRecorridos.map.openInfoWindowHtml(
							latlng, 
							'<div class="globoMapaGoogle"><h5>' + 
							'L&iacute;nea ' + name + 
							'</h5></div>'
						);
					});
					this.addLine({c: this.iCorredor, l:this.iLinea, n:name});
				}
				
				this.eSolapas.style.display = 'block';
				
				if(!!this.map){
					this.map.checkResize();
					if (a) { this.map.setCenter(a[0], 13); }
				}
			}
		}, 
		addMarkerPara: function(cor, lin, rec, pos, para){
			var ICON = {};
			ICON.image = '/img/iconLineas/parada' + cor + '.png';
			ICON.size = new GSize(20, 28);
			ICON.iconAnchor = new GPoint(10, 28);
			ICON.infoWindowAnchor = new GPoint(9, 2);
			
			var GMO = {}
			GMO.icon = ICON;//G_DEFAULT_ICON;
			GMO.dragCrossMove = false;
			GMO.title = para.name;
			GMO.clickable = true;
			GMO.draggable = false;
			GMO.bouncy = false;
			GMO.autoPan = false;
			
			this.corredores[cor].lineas[lin].markers[rec][pos] = new GMarker(para.latlng, GMO);
			
			if (!!this.map) {
				this.map.addOverlay(this.corredores[cor].lineas[lin].markers[rec][pos]);
				
				if(!this.hidenMarkers){ this.corredores[cor].lineas[lin].markers[rec][pos].show(); }
				else{ this.corredores[cor].lineas[lin].markers[rec][pos].hide(); }
			}
			else { this.markersPara.push(this.corredores[cor].lineas[lin].markers[rec][pos]); }
			
			GEvent.addListener(this.corredores[cor].lineas[lin].markers[rec][pos], 'click', function() {
				this.openInfoWindowHtml(
					'<div class="infowindow">' +
					'<strong>Parada de l&iacute;nea ' + oRecorridos.corredores[cor].lineas[lin].e.innerHTML + '</strong>' + 
					' (' + ((rec == 'ida')? 'Ida' : 'Vuelta') + ')<br />' + 
					'<span>Direcci&oacute;n: <em>' + para.name + '</em></span>' + 
					'</p></div>'
				);
			});
		}, 
		showHideMarkersPara: function(){
			var cor, lin, rec, pos;
			
			this.hidenMarkers = !this.hidenMarkers;
			for(cor in this.corredores){
				
				if(!!this.corredores[cor].lineas){
					for(lin in this.corredores[cor].lineas){
						
						if(!!this.corredores[cor].lineas[lin].markers){
							for(rec in this.corredores[cor].lineas[lin].markers){
								
								if(!!this.corredores[cor].lineas[lin].markers[rec]){
									for(pos in this.corredores[cor].lineas[lin].markers[rec]){
										
										if(this.hidenMarkers){
											this.corredores[cor].lineas[lin].markers[rec][pos].hide();
										}
										else{
											this.corredores[cor].lineas[lin].markers[rec][pos].show();
										}
									}
								}
							}
						}
					}
				}
			}
		}, 
		goToMarker: function(cor, lin, rec, pos){
			FireEvent($('tabMapaRecorrido'), 'click');
			try{
				this.corredores[cor].lineas[lin].markers[rec][pos].show();
				GEvent.trigger(this.corredores[cor].lineas[lin].markers[rec][pos], "click");
			}catch(e){ ; }
		}, 
		//
		changeTab: function(e, o){
			if (!!e) { StopEvent(e); }
			if (!!this.oTabOn) {
				this.oTabOn.t.className = '';
				this.oTabOn.c.style.display = 'none';
			}
			this.oTabOn = o;
			this.oTabOn.t.className = 'on';
			this.oTabOn.c.style.display = 'block';
			if (o.t.id == 'tabMapaRecorrido' && !this.map) {
				this.loadMap();
			}
		}, 
		//
		showHideLines: function(e, c){
			var o = this.corredores[c], i;
			if (!o) {
				o = {e: e, c: $('corredorLineas' + c)}
				if (!!o.e) { o.e.className = 'on'; }
				if (!!o.c) { o.c.style.display = 'block'; }
				this.corredores[c] = o;
				this.corredores['total']++;
			}
			else {
				if (!!o.e) { o.e.className = ''; }
				if (!!o.c) { o.c.style.display = 'none'; }
				
				if (!!o.lineas) {
					for (i in o.lineas) {
						FireEvent(o.lineas[i].e, 'click');
					}
				}
				delete(this.corredores[c]);
				this.corredores['total']--;
			}
			this.showHideHelp();
		}, 
		addRemoveLines: function(e, c, i){
			if (!this.corredores[c]) { return false; }
			if (!this.corredores[c].lineas) {
				this.corredores[c].lineas = {};
			}
			
			var o = this.corredores[c].lineas[i];
			if (this.esperar) { return false; }
			if (!o) {
				o = {e: e}
				if(!!o.e){ o.e.className = 'on'; }
				this.corredores[c].lineas[i] = o;
				this.lineasTotal++;
				this.iCorredor = c;
				this.iLinea = i;
				this.search();
			}
			else {
				if (!!o.e) { o.e.className = ''; }
				if (!!o.recorrido) { o.recorrido.parentNode.removeChild(o.recorrido); }
				if (!!o.frecuencia) { o.frecuencia.parentNode.removeChild(o.frecuencia); }
				if (!!o.paradas) { o.paradas.parentNode.removeChild(o.paradas); }
				
				if (!!this.map) {
					if (!!this.corredores[c].lineas[i].polyline) {
						clearTimeout(this.timeouts[i]);
						this.map.removeOverlay(this.corredores[c].lineas[i].polyline);
						this.map.removeOverlay(this.markers[i]);
						
						delete(this.timeouts[i]);
						delete(this.markers[i]);
					}
					
					if (this.corredores[c].lineas[i].markers) {
						var r, p;
						for (r in this.corredores[c].lineas[i].markers) {
							for (p in this.corredores[c].lineas[i].markers[r]) {
								this.map.removeOverlay(this.corredores[c].lineas[i].markers[r][p]);
							}
						}
					}
				}
				
				delete(this.corredores[c].lineas[i]);
				
				this.lineasTotal--;
				if (this.lineasTotal == 0) {
					this.eSolapas.style.display = 'none';
				}
			}
			this.showHideHelp();
		}, 
		addLine: function(line){
			if (!this.map) { this.polylines.push(line); }
			else {
				//
				var poly = this.corredores[line.c].lineas[line.l].polyline;
				this.map.addOverlay(poly);
				var t = poly.getVertexCount();
				if(t > 1){
					var latLng_1 = poly.getVertex(0);
					var latLng_2 = poly.getVertex(1);
					this.addMarker(line.l, line.n, latLng_1.lat(), latLng_1.lng());
					this.timeouts[line.l] = setTimeout('oRecorridos.animMarker('+line.c+', '+line.l+', 0, 0)', 1000);
				}
			}
		}, 
		//
		loadMap: function(){
			if (GBrowserIsCompatible() && !this.map) {
				this.map = new GMap2($('mapaRecorrido'));
				this.map.enableDragging();
				this.map.enableInfoWindow();
				this.map.enableDoubleClickZoom();
				this.map.disableContinuousZoom();
				this.map.disableGoogleBar();
				this.map.disableScrollWheelZoom();
				this.map.setCenter(new GLatLng('-31.416706174503304', '-64.18381333351135'), 13);
				this.map.addControl(new GLargeMapControl());
				
				if (!!this.infMap) { this.initMap(this.infMap); }
				if (this.polylines.length > 0) {
					var i;
					for(i in this.polylines){ this.addLine(this.polylines[i]); }
				}
				if (this.markersPara.length > 0) {
					var i;
					for(i in this.markersPara){
						this.map.addOverlay(this.markersPara[i]);
						
						if(!this.hidenMarkers){ this.markersPara[i].show(); }
						else{ this.markersPara[i].hide(); }
					}
					this.markersPara = [];
				}
			}
		}, 
		initMap: function(inf){
			if (!this.map) { this.infMap = inf; }
			else { eval(inf); }
		}, 
		addMarker: function(idx, ttl, lat, lng){
			if(lat != 0 && lng != 0){
				var ICON = {}
				ICON.image = '/img/iconLineas/'+ttl+'.gif';
				ICON.size = new GSize(25, 25);
				ICON.iconAnchor = new GPoint(13, 25);
				
				var GMO = {}
				GMO.icon = ICON;//G_DEFAULT_ICON;
				GMO.dragCrossMove = true;
				GMO.title = ttl;
				GMO.clickable = false;
				GMO.draggable = false;
				GMO.bouncy = false;
				GMO.autoPan = false;
				
				this.markers[idx] = new GMarker(new GLatLng(lat, lng), GMO);
				this.markers[idx].show();
				this.map.addOverlay(this.markers[idx]);
			}
		}, 
		animMarker: function(cor, lin, ver, cur){
			var poly = this.corredores[cor].lineas[lin].polyline;
			
			var latLng_1 = poly.getVertex(ver);
			var latLng_2 = poly.getVertex(ver + 1);
			
			var met = Math.pow(2, 18 - this.map.getZoom());
			var len = Math.ceil(latLng_1.distanceFrom(latLng_2) / met);
			var lat = normalMove(cur, latLng_1.lat(), latLng_2.lat()-latLng_1.lat(), len);
			var lng = normalMove(cur, latLng_1.lng(), latLng_2.lng()-latLng_1.lng(), len);
			
			this.markers[lin].setPoint(new GLatLng(lat, lng));
			cur++;
			if (cur > len - 1) {
				cur = 0;
				ver++;
				if (ver >= poly.getVertexCount() - 1){ ver = 0; }
			}
			this.timeouts[lin] = setTimeout('oRecorridos.animMarker('+cor+', '+lin+', '+ver+', '+cur+')', 100);
		},
		//
		showHideHelp: function(){
			var h = $('ayudaRecorrido');
			if (this.corredores['total'] > 0 && this.lineasTotal == 0) {
				h.firstChild.style.display = 'none';
				h.lastChild.style.display = 'inline';
				h.style.display = 'block';
			}
			else if (this.corredores['total'] == 0 && this.lineasTotal == 0) {
				h.lastChild.style.display = 'none';
				h.firstChild.style.display = 'inline';
				h.style.display = 'block';
			}
			else {
				h.style.display = 'none';
			}
		}
	}
	
	normalMove = function(t,b,c,d){ return c*t/d + b; }
	
	AddEvent($('tabListadoRecorrido'), 'click', function(e){
		oRecorridos.changeTab(e, {t:$('tabListadoRecorrido'), c:$('contListadoRecorrido')});
	});
	AddEvent($('tabFrecuenciaRecorrido'), 'click', function(e){
		oRecorridos.changeTab(e, {t:$('tabFrecuenciaRecorrido'), c:$('contFrecuenciaRecorrido')});
	});
	AddEvent($('tabParadasRecorrido'), 'click', function(e){
		oRecorridos.changeTab(e, {t:$('tabParadasRecorrido'), c:$('contParadasRecorrido')});
	});
	AddEvent($('tabMapaRecorrido'), 'click', function(e){
		oRecorridos.changeTab(e, {t:$('tabMapaRecorrido'), c:$('contMapaRecorrido')});
	});
	FireEvent($('tabMapaRecorrido'), 'click');
	
	AddEvent($('mostrarOcultarParadasRecorrido'), 'click', function(e){
		oRecorridos.showHideMarkersPara();
		$('mostrarOcultarParadasRecorrido').firstChild.innerHTML = ((!oRecorridos.hidenMarkers)? 'Ocultar':'Mostrar') + ' Paradas';
	});
	
	var c = Cookie.get('corredor');
	if (c != '') {
		c = $('aCorredor' + c);
		if (!!c){
			FireEvent(c, 'click');
			Cookie.unset('corredor');
		}
	}
	
