// JavaScript Document
Stop = false;
Capa = false;
Speed  = 40;
Offset = 10;
function derecha(capa){
Stop = false;
Capa = capa; 
rula_derecha();
}
function izquierda(capa){
Stop = false;
Capa = capa; 
rula_izquierda();
}

function arriba(capa){
Stop = false;
Capa = capa; 
rula_arriba();
}
function abajo(capa){
Stop = false;
Capa = capa; 
rula_abajo();
}
function para(){
	Stop = true;
	//Speed = 100;
}

function rula_derecha(){
	if ( Stop ) return 0;
 	objeto = document.getElementById(Capa);
	objeto.scrollLeft+=Offset;
	if(objeto.scrollWidth - objeto.offsetWidth > objeto.scrollLeft) setTimeout(rula_derecha ,Speed);
}

function rula_izquierda(){
	if ( Stop ) return 0;
	objeto = document.getElementById(Capa);
	objeto.scrollLeft-=Offset;
	if(objeto.scrollWidth - objeto.offsetWidth > objeto.scrollLeft) setTimeout(rula_izquierda ,Speed);
}

function rula_arriba(){
	if ( Stop ) return 0;
	//Speed-=10;
 	objeto = document.getElementById(Capa);
	objeto.scrollTop+=Offset;
	if(objeto.scrollHeight - objeto.offsetHeight > objeto.scrollTop) setTimeout(rula_arriba ,Speed);
}

function rula_abajo(){
	if ( Stop ) return 0;
	objeto = document.getElementById(Capa);
	objeto.scrollTop-=Offset;
	if(objeto.scrollHeight - objeto.offsetHeight > objeto.scrollTop) setTimeout(rula_abajo ,Speed);
}



var slave = '';  // variable global necesaria para ser vista en el manejador;

function objetus()
	   {
		  try {  xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP");   }
		  catch(e) {
			 try  {	xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");  }
			  catch(E) {
				  xmlhttp = false;
			   }
		  }
		   
		  if (!xmlhttp && typeof XMLHttpRequest != 'undefined'){
				xmlhttp = new XMLHttpRequest();
		  }
		  return xmlhttp;
	   }
	
// LLAMADAS

	// especifica para la carga de contenido. Usa el manejador XML. para pintar las diversas partes de la carga
	function contenido(aplicacion)
		{
			servidor = new objetus();	 
	      	cadena= "index.php?ajaxcontrolpagina=1&aplicacion=" + aplicacion;
  			servidor.open("GET",cadena, true);
	    	servidor.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //Esta es la parte más importante para usar POST
			servidor.setRequestHeader('Accept-Charset', 'UTF-8');
   			servidor.onreadystatechange=manejadorXML;
   			servidor.send(null); 
   			return;
		}
	// se usa con el objeto upload y sirve para montar una barra de uploading mientras se sube al server y se ejecuta una accion para tratar lo subido


	function carga_simple(ruta,mslave,variables)
	{	 	 
		 servidor = new objetus();
	 	//alert('carga_simple');
	 	if(arguments.length<3) variables=''; 
	 	slave=mslave;
	 	ruta = ruta + '?' + variables + "&ajaxcontrol=1&destino=" + slave;
	 	servidor.open('GET',ruta,true); 
	 	servidor.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //Esta es la parte más importante para usar POST
	 	servidor.setRequestHeader('Accept-Charset', 'UTF-8');
	 	servidor.onreadystatechange=manejadorTEXT;
	 	servidor.send(null);
	}

	
// MANEJADORES
	function manejadorXML(){
	if (servidor.readyState==1) {
		//alert('cargando');
		if(document.getElementById('actividad_ajax')){
			//document.getElementById('actividad_ajax').innerHTML ="<img src='http://imagenes.islared.com/ico_loading.gif' alt='cargando' title='cargando' height='19'>";
			document.getElementById('actividad_ajax').innerHTML ="<img src='http://imagenes.panorama-actual.es/ajax-loader.gif' alt='cargando' title='cargando' height='10'>";
		}else{
			document.getElementById(slave).innerHTML =	"<img src='http://imagenes.panorama-actual.es/ajax-loader.gif' alt='cargando' title='cargando' height='10'>";
		}
		
	}
	
	if (servidor.readyState == 4){ //Esto quiere decir que ha terminado
	    //alert('terminado');
		if(servidor.status == 200){ //El proceso ha terminado con exito
			  //alert('OK' + servidor.responseText);
			  if(document.getElementById('actividad_ajax')){
				  document.getElementById('actividad_ajax').innerHTML = "";
			  }
			  
			  vari=servidor.responseXML;

			  var titulo = vari.getElementsByTagName('titulo')[0].childNodes[0].nodeValue;
			  var contenido = vari.getElementsByTagName('contenido')[0].childNodes[0].nodeValue;
			  var mem = vari.getElementsByTagName('mem')[0].childNodes[0].nodeValue;
			  var time = vari.getElementsByTagName('time')[0].childNodes[0].nodeValue;
			  document.getElementById('titulo').innerHTML    = 	titulo;
			  document.getElementById('contenido').innerHTML =	contenido;
			  document.getElementById('mem').innerHTML       = 	mem;
			  document.getElementById('time').innerHTML      =	time;
			  
			}
			else{
			 //alert('KO');
				if(document.getElementById('actividad_ajax')){
					 document.getElementById('actividad_ajax').innerHTML = "<img src='http://imagenes.islared.com/FUTURE_ICONS/confgclose_16_hot.gif' alt='ERROR SERVERFILE NO ENCONTRADO' title='ERROR SERVERFILE NO ENCONTRADO'>";  
				}else{
					document.getElementById(slave).innerHTML = "<img src='http://imagenes.islared.com/FUTURE_ICONS/confgclose_16_hot.gif' alt='ERROR SERVERFILE NO ENCONTRADO' title='ERROR SERVERFILE NO ENCONTRADO'>";
				}
			}
		}
		
	}
	
	function manejadorTEXT(){
	//if(slave=='capadebug') alert(debug);
	
 	if (servidor.readyState==1) {
		//alert('cargando');
		if(document.getElementById('actividad_ajax')){
			//document.getElementById('actividad_ajax').innerHTML ="<img src='http://imagenes.islared.com/ico_loading.gif' alt='cargando' title='cargando' height='19'>";
			document.getElementById('actividad_ajax').innerHTML ="<img src='http://imagenes.panorama-actual.es/ajax-loader.gif' alt='cargando' title='cargando' height='10'>";
		}else{
			document.getElementById(slave).innerHTML =	"<img src='http://imagenes.panorama-actual.es/ajax-loader.gif' alt='cargando' title='cargando' height='10'>";
		}
		
	}
	//	"cargando..."; 
	if (servidor.readyState == 4){ //Esto quiere decir que ha terminado
	    //alert('terminado');
		if(servidor.status == 200){ //El proceso ha terminado con exito
			  //alert('OK' + servidor.responseText);
			  if(document.getElementById('actividad_ajax')){
				  document.getElementById('actividad_ajax').innerHTML = "";
			  }
			  document.getElementById(slave).innerHTML = servidor.responseText;		
			  
			}
			else{
			 //alert('KO');
				if(document.getElementById('actividad_ajax')){
					 document.getElementById('actividad_ajax').innerHTML = "<img src='http://imagenes.islared.com/FUTURE_ICONS/confgclose_16_hot.gif' alt='ERROR SERVERFILE NO ENCONTRADO' title='ERROR SERVERFILE NO ENCONTRADO'>";  
				}else{
					document.getElementById(slave).innerHTML = "<img src='http://imagenes.islared.com/FUTURE_ICONS/confgclose_16_hot.gif' alt='ERROR SERVERFILE NO ENCONTRADO' title='ERROR SERVERFILE NO ENCONTRADO'>";
				}
			}
		}
	
	}
	
	
	
/////////////////7

function setZoom(img, dir, width, height, margin, zIndex, delay) {
alert(width + " " + height + " " + margin);	
setTimeout(function() {
    if (img.dir==dir) {
      img.style.width=width;
      img.style.height=height;
      img.style.margin=margin;
      img.style.zIndex=zIndex;
      img.parentNode.parentNode.style.zIndex=zIndex;
	  
    }
  }, delay);
}

function larger(img, width, height) {
  img.dir='rtl';
  //now=parseInt(img.style.zIndex);
  now =0;
  for (i=now+1; i<=10; i++) {
 	w=(width*(10+i))/20+'px';
    h=(height*(10+i))/20+'px';
	m=(-i)+'px 0 0 '+(-width*i/40)+'px';
    setZoom(img, 'rtl', w, h, m, i, 20*(i-now));
  }
}

function smaller(img, width, height) {
  img.dir='ltr';
  //now=parseInt(img.style.zIndex);
  now =10;
  for (i=now-1; i>=0; i--) {
    w=(width*(10+i))/10+'px';
    h=(height*(10+i))/10+'px';
    m=(-i)+'px 0 0 '+(-width*i/40)+'px';
    setZoom(img, 'ltr', w, h, m, i, 20*(now-i));
  }
 
}

