function getAjax()
{
    if (window.XMLHttpRequest && !(window.ActiveXObject)) {
        try {
			//Mozilla 
            req = new XMLHttpRequest();
        } 
        catch (e) {
            req = false;
        }
    }
    else 
	if (window.ActiveXObject) {
		try {
			//IE version 6 y 7
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			//IE version 5
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {
				req = false;
			}
		}
	}
	
    return req;
}

function loadUrl(req, url, callMe) {
    if (req) {
        req.onreadystatechange = callMe;//El atributo onreadystatechange asigna la función que se ejecutará cada vez que readyState cambie de valor. 
        req.open("GET", url, true);
		//alert(send);
		req.send("");   
    }
}
var cont=0;

function mostrar(ob,num){
	cont=cont+num;
	var puto=ob.length;
	
	if (cont<0)
		{
			cont=puto-1;
		}
		else if(cont==ob.length)
		{
		cont=0	
		}																																				
		//var reprod=document.getElementById("reprod");
		var img=document.getElementById("img");
		var h1=document.getElementById("h1");
		var p=document.getElementById("p");																	
		img.src="images/"+ob[cont].fototapa;
		h1.innerHTML="<h1>"+"<a href='?mod=noticiadesplegada1&id="+ob[cont].id+"'>"+ob[cont].titulo+"</a>"+"</h1>";
		p.innerHTML=ob[cont].bajada;
		//reprod.innerHTML="<img src='images/"+ob[cont].URL+"'/>"+"<a href='?mod=noticiadesplegada1&id="+ob[cont].id_noticia+"'>"+"<h1>"+ob[cont].titulo+"</h1>"+"</a>"+"<h2>"+ob[cont].bajada+"</h2>"+"<p>"+ob[cont].nota+"</p>";
			
}


var inter ="vacio"; 

function st()
	{
	if (inter == "vacio")
	{

	inter=setInterval('mostrar(arr,1)',6000);
	}
	else 
	{
	
		stopInt();
	
	}

	}


function stopInt()
{
	if(inter!="vacio")
	{
		clearInterval(inter);	
		inter="vacio";
	}
}
		
window.onload = function () 
{var mu=document.getElementById("reprod");
		req = getAjax();
		
		loadUrl(req,'consultas/consulta.php?',function()
		{
				if (req.readyState == 4) 
				{
					if (req.status == 200) 
					{ 
					
						//datos = eval(t.responseText);
						arr= eval(req.responseText);//crea el objeto
						
						if (arr.length == 0 ) {	
							alert("toy descargado");
						} 
						else 
						{		var img=document.getElementById("img");
								var h1=document.getElementById("h1");
								var p=document.getElementById("p");		
								img.src='images/'+arr[0].fototapa;
								h1.innerHTML="<a href='?mod=noticiadesplegada1&id="+arr[0].id+"'>"+"<h1>"+arr[0].titulo+"</h1>"+"</a>";
								p.innerHTML=arr[0].bajada;
								
								
								//reprod.innerHTML="<img src='images/"+arr[0].URL+"'/>"+"<a href='?mod=noticiadesplegada1&id="+arr[0].id_noticia+"'>"+"<h1>"+arr[0].titulo+"</h1>"+"</a>"+"<h2>"+arr[0].bajada+"</h2>"+"<p>"+arr[0].nota+"</p>";
														
						
						}
					}
					else 
					{
						log("There was a problem retrieving the data:</br>" + req.statusText);
					}
					
					
				}
		});

st();
var at=document.getElementById('atras');
var ad=document.getElementById('adelante');
var pl=document.getElementById('play');
var band=true;
	at.onmouseover=function()
	{
		this.src="images/atrasHover.gif"
	}
	at.onmouseout=function()
	{
		this.src="images/atras.gif"
	}	
	at.onclick=function()
	{
		mostrar(arr,-1);
	}
	ad.onmouseover=function()
	{
		this.src="images/adelanteHover.gif"
	}
	ad.onmouseout=function()
	{
		this.src="images/adelante.gif"
	}	
	ad.onclick=function()
	{
	mostrar(arr,1);
	}	
	pl.onmouseover=function()
	{
		this.src="images/pausaHover.gif"
	}
	pl.onmouseout=function()
	{
		this.src="images/pausa.gif"
	}	
	pl.onclick=function()
	{ this.src="images/pausaHover.gif"
		
			if (band == true) {
				stopInt();
				band = false;
				pl.onmouseout=function()
				{
					this.src="images/pausaHover.gif"
				}	
			
			
			}
			else {
				st();
				
				band = true
					pl.onmouseout=function()
				{
					this.src="images/pausa.gif"
				}	
			}
		//alert(band);
		}

	}