var Noticia = function(){
	this.titulo = null;
	this.link = null;
}

var NoticiaLoad = function(xmlpath){
	this.xmlpath = xmlpath;
	this.newsArr = new Array();
	this.xmlDoc = null;
	this.length = 0 ;
	this.iterator = 0; 
	this.current = null; // noticia atual
	this.errorLoad = false;

	this.loadXml = function(dname){
	var x =null;
		if (window.XMLHttpRequest){
			x=new window.XMLHttpRequest();
			x.open("GET",dname,false)
			x.send("")
			this.xmlDoc = x.responseXML;
		}
		// IE 5 and IE 6
		else if (ActiveXObject("Microsoft.XMLDOM")){
			x=new ActiveXObject("Microsoft.XMLDOM");
			x.async=false;	
			this.xmlDoc = x;
		}
	}

	this.read = function(){
		this.loadXml(this.xmlpath); //busca no xml as noticias  
		var noticias = this.xmlDoc.getElementsByTagName("item");
		for(i = 0; i < noticias.length; i++){
			var tempobj = new Noticia();
			tempobj.titulo = noticias[i].getAttribute("titulo");
			tempobj.link = noticias[i].getAttribute("link");
			this.newsArr[i] = tempobj;
			if(i==0){ // pega a primeira noticia como corrente
				this.current = tempobj;
			}
		}
		this.length = noticias.length;
	}

    // controle do anterior e proximo

	this.prox = function(){
		if(this.length>1 && this.iterator<this.length-1){
			this.iterator++;
			this.current = this.newsArr[this.iterator];
		}
	}
	this.ant = function(){
		if(this.length>1){	
			if(this.iterator!=0){
				this.iterator--;
				this.current = this.newsArr[this.iterator];
			}
		}
	}
	
}

//objeto para tratar o displayer da index
var displayerHandler = function(xmlpath){
	this.loadobj = new NoticiaLoad(xmlpath);
	this.loadobj.read();

	this.displayer_titulo = document.getElementById('displayer_titulo');
	this.displayer_link = document.getElementById('displayer_link');

	this.current = function(){
		if(this.loadobj.length>0){
			this.displayer_titulo.innerHTML = this.loadobj.current.titulo;
			this.displayer_link.href = this.loadobj.current.link;
		}
	}
	this.prox = function(){
		this.loadobj.prox();
		this.current();
	}
	this.ant = function(){
		this.loadobj.ant();
		this.current();
	}
	
}
