
var colors= ["#CDDBDF", "#B5C5CD", "#99AEBA", "#7897A6", "#5B8394", "#376F83", "#005D70"];

var index=null;
var pause = 6000;
var timer = 20;
var speed = 40;
var lastId = null;

function hideEco()
{
    var infoblock = document.getElementById("ecoblock");
	if (!infoblock) return false;

    if (index == null) index = colors.length-1;
    if (index == -1) {
        index = null;
        clearTimeout(timer);
        changeEco();
    } else {
       infoblock.style.color = colors[index];
       index--;
	   var timer=setTimeout("hideEco()", speed);
    }
}

function showEco()
{
    var infoblock = document.getElementById("ecoblock");
	if (!infoblock) return false;

    if (index == null) index = 0;

    if (index == colors.length) {
        index = null;
        clearTimeout(timer)
	    var timer=setTimeout("hideEco()",pause)
    } else {
       infoblock.style.color = colors[index];
       index++;
	   var timer=setTimeout("showEco()", speed);
    }
}

function changeEco(){
	var url = "/xml/eco.php?exclude="+lastId;
	if (ajaxHandler.is_idle)
	{
		 ajaxHandler.is_idle = false;
		 ajaxHandler.doBeforStart = function(){};
		 ajaxHandler.processAnswer = ecoProcessAnswer;
		 ajaxHandler.loadXMLDoc(url);
	}
	else
	{
	    index = -1;
	    var timer=setTimeout("hideEco()", speed);
	}
}

function ecoProcessAnswer(xml){
	var advertise = xml.getElementsByTagName('advertise');
	var _elem = document.getElementById("ecoblock");
	lastId = advertise[0].getAttribute("id");
	var text = advertise[0].getAttribute("text");
    text=text.replace(/&lt;/g,"<")
    text=text.replace(/&gt;/g,">")
	text=text.replace(/&quot;/g,'"')
	text=text.replace(/&#039;/g,"'")
	_elem.innerHTML = text;
	showEco();
}
