var img 		= new Array();
var	imgTm		= 0;
var ponteiro 	= 0;
var delay		= 10000;

var obj;

function imagem( url , titulo , texto )
{
	this.url 	= url;
	this.titulo = titulo;
	this.texto	= texto;
}

function addImg( url , titulo , texto )
{
	img.push( new imagem( url , titulo , texto ) );	
}

function slide( id )
{
	imgTm 	= img.length;
	obj		= document.getElementById( id );
		
	if( imgTm > 0 )
	{
		exibeImg( 0 );
		sl = setInterval( " proximo()" , delay );
		
	}
}
function primeiro()
{
	var p = 0;
	if( imgTm > 0 )	exibeImg( p );
}

function ultimo()
{
	var p = imgTm-1;
	if( imgTm > 0 ) exibeImg( p );
}

function proximo()
{
	var p = ponteiro + 1;
	if( imgTm > 0 ) exibeImg( p );
}

function anterior()
{
	var p = ponteiro - 1;
	if( imgTm > 0 ) exibeImg( p )
}

function exibeImg( p )
{
	var newImg = document.createElement('img');
	var a = document.createElement('a');
	
	
	a.setAttribute('href', unescape( img[ponteiro].texto.replace(/\+/g," ") ));
	
	ponteiro = p;
	
	obj.innerHTML = '';
	
	if( ponteiro < 0 ) ponteiro = imgTm - 1 ;
	if( ponteiro > ( imgTm - 1 ) ) ponteiro = 0;
	
	newImg.setAttribute( 'src' , img[ponteiro].url );
	newImg.setAttribute( 'title' , img[ponteiro].titulo );
	newImg.setAttribute( 'vspace' , '5' );
	newImg.setAttribute( 'hspace' , '5' );
	newImg.setAttribute( 'align' , 'left' );
	
	a.appendChild( newImg );
	
	obj.appendChild(a);	
	
	obj.innerHTML += '<table><tr><td><p style="font: bold 14px;">' + unescape( img[ponteiro].titulo.replace(/\+/g," ") ) + '</p>' +  "</td></tr></table>";
}