function mostrarCartel(contenedor, titulo, texto) {
	cont = $(contenedor);
	cont.stop(true, true);
	cont.fadeOut("slow", function() {
		$("#mensaje").remove(); 		
		cont.append('<div id="mensaje"><h1>'+titulo+'</h1>'+texto+'<br/><br/><br/></div>');
		cont.fadeIn("normal", function() {
			hacerScroll(cont);
		});
	});	
}

function hacerScroll(elemento) {
	$('html,body').animate({ scrollTop: $(elemento).offset().top - 100 }, { duration: 'slow', easing: 'swing'});
}

function cargarEditor() {
		crearEditor('Comentario', 200);
}
	
function crearEditor(Nombre, alto) {

	var oFCKeditor = new FCKeditor( Nombre ) ;	
	oFCKeditor.BasePath	= BASE + 'js/fckeditor/fckeditor/';
	oFCKeditor.Height = alto;
	oFCKeditor.Width = 600; // ancho del editor
	oFCKeditor.ToolbarSet = "ToolBarPosts";
	oFCKeditor.ReplaceTextarea();
	
}		

function ltrim(s) {
   return s.replace(/^\s+/, "");
}

function rtrim(s) {
   return s.replace(/\s+$/, "");
}

function trim(s) {
   return rtrim(ltrim(s));
}


function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function abPos(o) { var o=(typeof(o)=='object'?o:$(o)), z={X:0,Y:0}; while(o!=null) { z.X+=o.offsetLeft; z.Y+=o.offsetTop; o=o.offsetParent; }; return(z); }
function XY(e,v) { var o=agent('msie')?{'X':event.clientX+document.documentElement.scrollLeft,'Y':event.clientY+document.documentElement.scrollTop}:{'X':e.pageX,'Y':e.pageY}; return(v?o[v]:o); }

star={};

star.mouse=function(e, n) { 

	starCur = $('#starCur'+n);
	starUser = $('#starUser'+n);
	
	if(star.stop || isNaN(star.stop)) {
	
		star.stop=0;
		document.onmousemove=function(e) {
		
			var p=abPos(document.getElementById('star'+n)), x=XY(e), oX=x.X-p.X, oY=x.Y-p.Y; star.num=n;
				
			if (oX<1 || oX>84 || oY<0 || oY>19) 
				{ star.stop=1; star.revert(); }        
			else {
				starCur.css('width', oX+'px');
				starUser.css('color', '#111');
				starUser.html(Math.round(oX/84*100)+'%');
			}
		};
	} 

};

star.update=function(e, n, IdFoto) {

	starCur = $('#starCur'+n);
	starUser = $('#starUser'+n);
	
	var	v=parseInt(starUser.html());		
	starCur.attr("title",v);

    req=new XMLHttpRequest();
	req.open('GET','http://www.cactuseros.com/VotarFotoCactus/'+IdFoto+'/Calificacion/'+(v/100),false); 
	req.send(null);    
	
	// voto... apago el rater
	star.desactivar(n);
	$('#cantVotos'+n).html('&nbsp;-&nbsp;Voto enviado!');
};

star.revert=function() { var n=star.num, v=parseInt($('#starCur'+n).attr("title"));

	starCur = $('#starCur'+n);
	starUser = $('#starUser'+n);
	
    starCur.css('width', Math.round(v*84/100)+'px');
    starUser.html(v>0?Math.round(v)+'%':'0%');
    starUser.css('color', '#888');
    
    document.onmousemove='';
};

star.desactivar=function(n) { 

	starCur = $('#starCur'+n);
	starUser = $('#starUser'+n);
	
	v = parseInt(starCur.attr("title"));
	starCur.css('width', Math.round(v*84/100)+'px');
    starUser.html(v > 0? Math.round(v)+'%':'');
    starUser.css('color', '#888');	
	
		
	$('#star'+n).bind("mousedown", function(event) {
		alert('Ya ha votado esta foto.'); 
		event.stopPropagation();
	});
	
	$('#star0'+n).bind("mousemove", function(event) { return false;});
};

star.inicializar=function(n) { 
	
	starCur = $('#starCur'+n);
	starUser = $('#starUser'+n);
	
	var v=parseInt(starCur.attr("title"));
	starCur.css('width', Math.round(v*84/100)+'px');
    starUser.html(v>0?Math.round(v)+'%':'0%');
	starUser.css('color', '#888');
};

function alertYaVoto() {
  alert('Ya ha votado esta foto.');
}

star.num=0;
