/**
 * @author alfredollanos
 */

var menu, inicio, startStop, Ajax=false;
var curHot=0, hotInterval, pauseHot;
var arr = new Array();

function ajaxRequest(){
	Ajax = false;
	try{
       Ajax = new XMLHttpRequest();
	}catch(ee){
       try{
               Ajax = new ActiveXObject("Msxml.XMLHTTP");        
       }catch(e){
	   		try{
               Ajax = new ActiveXObject("Msxml.XMLHTTP");        
       		}catch(e){
               try{
                       Ajax = new ActiveXObject("Microsoft.XMLHTTP");                
               }catch(E){
			   	Ajax = false;
               }
       		}
	   }
	 }		
}

function limpiar(b){
	var kids = b.childNodes;
	var numkids = kids.length;		
	for(var i=numkids-1; i>=0; i--){
	b.removeChild(kids[i]);
	}		
}

function hotStop(){	
	clearInterval(hotInterval);
}

function hotStart(){
	montaHot();
}

function Animation(){	
	var hotNews = document.getElementById('text-tdsticker');	
	if(curHot<arr.Link.length){
		limpiar(hotNews);
		var phot = document.createElement('p');			
		var titleText = document.createTextNode(arr.Date[curHot]+ ' - '+arr.Title[curHot]);
		var hotLink = document.createElement('a');
		//hotLink.onmouseover = "hotStop();";
		//phot.onmouseout = "hotStart()";
		//phot.setAttribute('onmouseover', 'hotStop();');
		//phot.setAttribute('onmouseout', 'hotStart();');
		phot.className = "ptext-tdsticker";
		hotLink.setAttribute('href', arr.Link[curHot]);
		hotLink.appendChild(titleText);
		phot.appendChild(hotLink);
		hotNews.appendChild(phot);
		curHot++;	
	} else {
		curHot = 0;
	}
}

function montaHot(){
	//Crea el ticker
	//llamamos a la animacion
	hotInterval = setInterval('Animation()', 2000);
}

function showHot(){
	arr.Title = new Array();
	arr.Link = new Array();
	arr.Date = new Array();
	if(Ajax.readyState==4){
		if(Ajax.status==200){
			var xml = Ajax.responseXML;
			if(xml.hasChildNodes()){
				var nod = xml.getElementsByTagName("blog");				
				for(var i =0; i<nod.length; i++){					
					var nd = nod[i];					
					arr.Title[i] = nd.getElementsByTagName("title")[0].firstChild.nodeValue;
					arr.Link[i] = nd.getElementsByTagName("link")[0].firstChild.nodeValue;														
					arr.Date[i] = nd.getElementsByTagName("date")[0].firstChild.nodeValue;
				}
				montaHot();
			}	
		}
	} else {
					arr.Title[i] ="";
					arr.Link[i] = "";												
					arr.Date[i] = "";
	}
}

function hotnews(){	
	ajaxRequest();
	if(!Ajax){
		alert('Problema con AJAX | Problem');
		return;
	} else {
	
	}
	//Ajax.open('GET', 'xml/ajax.datasample.php');
	Ajax.open('GET', 'tds_ticker_mini/xml/ticker.php');	
	//Ajax.open('GET', 'http://localhost/~alfredollanos/_utiles/tds_ticker/xml/ticker.php');
	Ajax.onreadystatechange = showHot;
	Ajax.send(null);
}


window.addEventListener?window.addEventListener("load",ticker_init,false):window.attachEvent("onload",ticker_init);

var d=document, imgs = new Array(), zInterval = null, pause=false, cOpacity=1.00, nOpacity=0;//current=2,
var menu, nIndex, fadeInterval, backCourse=false;

function ticker_init() {	
	var hotNews = document.getElementById('text-tdsticker');
	var phot = document.createElement('p');
	phot.className = "ptext-tdsticker";			
	var titleText = document.createTextNode('Cargando...');
	phot.appendChild(titleText);
	hotNews.appendChild(phot);
	nIndex = current;
	hotnews();
	so_init();
}