//Para imagenes
function moverImagenes(cuanto){
	var derecha = $('imagenes_contenidos').offsetLeft;
	anchoTotal = Math.abs($$('div.item_imagen').length*cuanto);
	anchoDisponible  = anchoTotal - 975;
	if((derecha > -1) && (cuanto>0)){
		$('botones_imagenes_menos').style.height="0px";
	}else if((cuanto<0)&&(anchoDisponible<-derecha)){
		$('botones_imagenes_mas').style.height="0px";
	}else{
		//si y solo si estamos en los límites
		new Effect.Move ('imagenes_contenidos',
			{	x: cuanto,
				y: 0, 
				mode: 'relative',
				afterFinish: activarBotos,
      				beforeStart: desactivarBotos 
      			});
		$('botones_imagenes_mas').style.height = "10px";
		$('botones_imagenes_menos').style.height = "10px";
	}
}

function activarBotos(){
	botonesArray = $$('#botones_imagenes a');
	botonesArray.each(function(item) {
	  	enableLink(item);
	});
}
function desactivarBotos(){
	botonesArray = $$('#botones_imagenes a');
	botonesArray.each(function(item) {
	  	disableLink(item);
	});
}
//Para Construcciones

function moverConstrucciones(cuanto,id){
	var derecha = $('construcciones_contenidos_' + id).offsetLeft;
	anchoTotal = Math.abs($$('#construcciones_contenidos_'+ id +' .construcciones_imagen').length*cuanto);
	anchoDisponible  = anchoTotal - (432);
	
	if((derecha > -1) && (cuanto>0)){
		
		$('botones_construcciones_menos_' + id).style.display="none";
		$('botones_construcciones_menos_' + id).style.visibility="hidden";
	}else if((cuanto<0)&&(anchoDisponible<=-derecha)){
		
		
		$('botones_construcciones_mas_' + id).style.display="none";
		$('botones_construcciones_mas_' + id).style.visibility="hidden";
	}else{
		//si y solo si estamos en los límites
		new Effect.Move ('construcciones_contenidos_' + id,
			{	x: cuanto,
				y: 0, 
				mode: 'relative',
				afterFinish: activarBotosConstrucciones,
				beforeStart: desactivarBotosConstrucciones 
      				
      			});
		$('botones_construcciones_menos_' + id).style.display="block";
		$('botones_construcciones_menos_' + id).style.visibility="visible";
		$('botones_construcciones_mas_' + id).style.display="block";
		$('botones_construcciones_mas_' + id).style.visibility="visible";
	}
}

function activarBotosConstrucciones(){
	botonesArrayConstrucciones = $$('a');
	botonesArrayConstrucciones.each(function(item) {
	  	enableLink(item);
	});
}
function desactivarBotosConstrucciones(){
	botonesArrayConstrucciones = $$('a');
	botonesArrayConstrucciones.each(function(item) {
	  	disableLink(item);
	});
}

function escondercliente(cliente){
	if (cliente){
		$('otros').style.visibility="hidden";
	}else{
		$('otros').style.visibility="visible";
	}
}


//General
function cancelLink () {
  return false;
}
function disableLink (link) {
  if (link.onclick)
    link.oldOnClick = link.onclick;
  link.onclick = cancelLink;
  if (link.style)
    link.style.cursor = 'default';
}
function enableLink (link) {
  link.onclick = link.oldOnClick ? link.oldOnClick : null;
  if (link.style)
    link.style.cursor = 
      document.all ? 'hand' : 'pointer';
}

//Menu desplegable
var antes;
Event.observe(window, 'load', function() {
	$$("#item .submenu").each(function(item){
		plegar(item.id);
	})
	agregarBlank();
});

function plegar(idSubmenu){
	antes = $(idSubmenu).clientHeight;
	var altopestana=$$('#'+idSubmenu+' .final_lista').first().clientHeight;
	diferencia=(antes-altopestana)-20;
	$(idSubmenu).style.clip = 'rect('+diferencia+'px 115px '+antes+'px 0px)';
	$(idSubmenu).style.top =-diferencia+150+"px";
	$$('#'+idSubmenu+' .final_lista_subir').first().style.display='block';
	$$('#'+idSubmenu+' .final_lista').first().style.display='none';
	return false;
}
function desplegar(idSubmenu){
	$(idSubmenu).style.clip = 'rect(0px 115px 1000px 0px)';
	$(idSubmenu).style.top ="150px";
	$$('#'+idSubmenu+' .final_lista_subir').first().style.display='none';
	$$('#'+idSubmenu+' .final_lista').first().style.display='block';
	return false;
}
function agregarBlank(){
	arrayAs = document.getElementsByTagName('a');
	for (var index = 0; index < arrayAs.length; ++index) {
		var item = arrayAs[index];
		if (item.className == 'ampliar'){
			item.onclick = function (){
				enlace = this.href;
				ventanaNueva = window.open(enlace,'nueva','width=480,height=200,scrollbars=0,resizable=1,toolbar=0,personalbar=0,menubar=0,status=0');
				ventanaNueva.focus();
				return false;
			}
		}
		if (item.className == 'ampliarplano'){
					item.onclick = function (){
						enlace = this.href;
						ventanaNueva = window.open(enlace,'nueva');
						ventanaNueva.focus();
						return false;
					}
		}
	}
}

function popupdinamico (nombre) {
	var ruta='/publico/popupdinamico.pl?';
	windowHandle=window.open(ruta+nombre, '_Imagen', 'width=480,height=200,scrollbars=0,resizable=1,toolbar=0,personalbar=0,menubar=0,status=0' );
	windowHandle.focus();
	return(false)
}




//AddEventListener
/*function anadeEvento (objeto, evento, funcion) {
	if(document.addEventListener) {
		objeto.addEventListener(evento, funcion, false);
	} else if(document.attachEvent) {
		objeto.attachEvent("on" + evento, funcion);
	}
}*/

