function changePestanya(itemClicked, className) {
	var menuPastilla = document.getElementById("menuPastilla");
	if (menuPastilla) {
		var items = menuPastilla.getElementsByTagName("li");
		if (items) {
			for (var i = 0; i < items.length; i++) {
				var currentElement = items[i];
				if (currentElement == itemClicked) {
					currentElement.className = className;
				} else if (currentElement.id == 'itemMP1') {
					currentElement.className = "";
				} else {
					currentElement.className = "orange";
				}			
			} 
		}
	}
}


function LavanguardiaLomas() {
	var ns6 = (parseFloat(navigator.appVersion) >= 5 && navigator.appName.indexOf("Netscape") >= 0) ? true : false;
	var imageLoading = '<div class="valorado"><p style="text-align: center;"><img id="loadingPastilla" src="http://web.lavanguardia.es/lvd/lv24h2007/img/ajax-loader.gif" alt="Cargando ..."></p></div>';
	var errorLoading = '<div class="valorado"><p style="text-align: center;">Error cargando los datos</p></div>';
	var cache = new Hash(null);
	var cacheTimeInvalidation = 300000;
	var controlError = 0;

	/**
     * Realiza un voto sobre un componente
     *
     * @param id El identificador de componente
     * @param option La opci�n del voto 1 estrella, 2 estrellas, 3....
     * @param action La url de la acci�n a ejecutar
     * @param idDivResult Identificador del objeto donde se guardar� el resultado de la acci�n
     * @param idLoading Identificador del objeto que presenta el loading
     */
	this.votar = function(id, option, action, idDivResult, idLoading) {
		if (idLoading) {
			idLoading = "#" + idLoading;		
			$(idLoading).toggle();
		}
		
		$.ajax(
		{
			type: "POST",
			url: action,
			dataType: "txt",
			data: "id=" + id + "&option=" + option,
			contentType: "application/x-www-form-urlencoded; charset=ISO-8859-1",
			success: function(html)
			{
				if (idLoading) {
					$(idLoading).toggle();
				}

				if (html == 'ERROR') {
					alert("Usted ya ha votado.");
				} else {		
					if (idDivResult) {
						idDivResult = "#" + idDivResult;	
						$(idDivResult).html(html);
					}	
					setTimeout("LavanguardiaLomas.votos(compId, 'http://www.lavanguardia.es/periodico/ajax/lavanguardia/votos.action', 'divElementVotos', false)", 5000);
				}
			},
			complete: function(html)
			{
			},
			error: function(html)
			{
				if (idDivResult) {				
					$(idDivResult).html(errorLoading);
				}
			}
		})	 
	};
	
	this.visitar = function(id, action, idDivResult, idLoading) {
		if (idLoading) {
			idLoading = "#" + idLoading;		
			$(idLoading).toggle();
		}
		
		$.ajax(
		{			
			type: "POST",
			url: action,
			dataType: "txt",
			data: "id=" + id,
			contentType: "application/x-www-form-urlencoded; charset=ISO-8859-1",
			success: function(html)
			{						
				if (idLoading) {
					$(idLoading).toggle();
				}
				
				if (idDivResult) {
					idDivResult = "#" + idDivResult;	
					$(idDivResult).html(html);
				}				
			},
			complete: function(html)
			{
			},
			error: function(html)
			{
				if (idDivResult) {				
					$(idDivResult).html(errorLoading);
				}
			}
		});	 
	};
	
	this.hideCaptchaEnviarComentario = function(id) {
		if (id) {
			id = "#" + id;	
			$(id).toggle();
			$(id).html("");
		}
	};
	
	this.showCaptchaEnviarComentario = function(action, idDivResult, idLoading) {	
		if (idLoading) {
			idLoading = "#" + idLoading;		
			$(idLoading).toggle();
		}
		
		$.ajax(
		{
			type: "POST",
			url: action,
			dataType: "txt",
			//data: "id=" + id + "&alias=" + alias + "&email=" + email + "&localidad=" + localidad + "&pais=" + pais + "&texto=" + texto,
			contentType: "application/x-www-form-urlencoded; charset=ISO-8859-1",
			success: function(html)
			{	
					
				if (idLoading) {
					$(idLoading).toggle();
				}
				
				if (idDivResult) {
					idDivResult = "#" + idDivResult;	
					$(idDivResult).html(html);
				}
				
				LavanguardiaLomas.showObjectInPosition('divSubmitWithCaptcha', LavanguardiaLomas.findPosX('Enviar', 100), LavanguardiaLomas.findPosY('Enviar', -200));				
			},
			complete: function(html)
			{				
			},
			error: function(html)
			{
				if (idDivResult) {				
					$(idDivResult).html(errorLoading);
				}
			}
		});	 
	};
	
	this.comentar = function(id, action, alias, email, localidad, pais, texto, idDivResult, idLoading) {
		if (idLoading) {
			idLoading = "#" + idLoading;		
			$(idLoading).toggle();
		}
		
		$.ajax(
		{
			type: "POST",
			url: action,
			dataType: "txt",
			data: "id=" + id + "&alias=" + alias + "&email=" + email + "&localidad=" + localidad + "&pais=" + pais + "&texto=" + texto,
			contentType: "application/x-www-form-urlencoded; charset=ISO-8859-1",
			success: function(html)
			{						
				if (idLoading) {
					$(idLoading).toggle();
				}
				
				if (idDivResult) {
					idDivResult = "#" + idDivResult;	
					$(idDivResult).html(html);
				}				
			},
			complete: function(html)
			{						
			},
			error: function(html)
			{
				if (idDivResult) {				
					$(idDivResult).html(errorLoading);
				}	
			}
		});	 
	};
	
	this.votos = function(id, action, idDivResult, idLoading) {
		if (idLoading) {
			idLoading = "#" + idLoading;		
			$(idLoading).toggle();
		}
		
		$.ajax(
		{
			type: "POST",
			url: action,
			dataType: "txt",
			data: "id=" + id,
			contentType: "application/x-www-form-urlencoded; charset=ISO-8859-1",
			success: function(html)
			{							
				if (idLoading) {
					$(idLoading).toggle();
				}
				
				if (idDivResult) {
					idDivResult = "#" + idDivResult;	
					$(idDivResult).html(html);
				}				
			},
			complete: function(html)
			{			
			},
			error: function(html)
			{
				if (idDivResult) {				
					$(idDivResult).html(errorLoading);
				}	
			}
		})	 
	};
	
	this.enviarAmigo = function() {
	};
	
	this.showObjectInPosition = function(id, posX, posY){
		id = "#" + id;		
		$(id).show();
		if(ns6) {
			$(id).css("left",posX);
			$(id).css("top",parseInt(posY)+10);
			//$(id).style.left = posX + "px";
			//$(id).style.top = (parseInt(posY)+10) + "px";
		}
		else {
			$(id).css("left",posX);
			$(id).css("top",posY+10);
			//$(id).style.left = posX;
			//$(id).style.top = parseInt(posY)+10;
		}
	};
	
	this.findPosX = function(id, offset) {
		var curleft = 0;
		var obj = document.getElementById(id);
		if(obj.offsetParent)
	    	while(1) {
	      		curleft += obj.offsetLeft;
	      		if(!obj.offsetParent)
	        	break;
	      		obj = obj.offsetParent;
	    	}
		else if(obj.x) curleft += obj.x;
		// correccion para que no se pierda por el lado izquierdo.
		if(curleft < 1) curleft=5;
		
		return curleft + offset;
	};

	this.findPosY = function(id, offset) {
		var curtop = 0;
		var obj = document.getElementById(id);
		if(obj.offsetParent)
	    	while(1) {
	      		curtop += obj.offsetTop;
	      		if(!obj.offsetParent)
	        	break;
	      		obj = obj.offsetParent;
	    	}
		else if(obj.y) curtop += obj.y;
		
		return curtop + offset;
	};
	
	this.lomas = function(id, action, idDivResult, idLoading) {
		document.domain = "lavanguardia.es"
		
		if (idLoading) {
			idLoading = "#" + idLoading;		
			$(idLoading).show();
		}
	
		if (idLoading) {
			if (idDivResult) {
				idDivResult = "#" + idDivResult;	
				$(idDivResult).html(imageLoading);
			}	
		}
		
		if (cache.hasKey(action)) {		
			if (idDivResult) {
				now = new Date();
				cachedDate = cache.getItem(action + ".date");
				
				if (now - cachedDate < cacheTimeInvalidation) {
					$(idDivResult).html(cache.getItem(action));
					return;
				}
			}	
		}
		
		var myData = "";
		if (id) {
			myData = "id=" + id;
		} 
		
		$.ajax(
		{
			type: "POST",
			url: action,
			dataType: "txt",
			data: myData,
			contentType: "application/x-www-form-urlencoded; charset=ISO-8859-1",
			success: function(html)
			{						
				controlError = 0;
				
				if (idLoading) {
					$(idLoading).hide();
				}
				
				if (idDivResult) {	
					cache.addItem(action, html);
					cache.addItem(action + ".date", new Date());
					
					$(idDivResult).html(html);
				}			
			},
			complete: function(html)
			{				
			},
			error: function(html)
			{						
				cache.removeItem(action);
				
				if (controlError < 1) {					
					controlError = controlError + 1; 
					setTimeout("LavanguardiaLomas.lomas('" + id + "', '" + action + "', '" + idDivResult + "', '" + idLoading + "')", 1000);
				} else {
					if (idDivResult) {				
						$(idDivResult).html(errorLoading);
					}
				}
			}
		})	 
	};
}

var LavanguardiaLomas = new LavanguardiaLomas();
