// JavaScript Document
var luzColor = '#FFDA9F';
function luzear(el, si) {
	if (si)
	{
		el.bgcolor_bak = el.style.backgroundColor;
		el.style.backgroundColor = luzColor;
	} else
		el.style.backgroundColor = el.bgcolor_bak;
}


function pliegaEncuesta(id, anchor) {
new Ajax.Updater('tde_'+id, 'votar.php', {
			parameters: { encuesta: id},
			method: 'get',
			onComplete: function () {
				new Effect.BlindDown('tde_'+id, {duration:1});
				//anchor.href='javascript:cierraMe(\''+anchor+'\');';
				anchor.onclick = function() {
					cierraMe('tde_'+id, anchor);

				}
			}
    });
    return false;
}

function cierraMe(div, anchor) {
	Effect.BlindUp(div);
	anchor.onclick = function() {
		abreMe(div, anchor);
	}
}

function abreMe(div, anchor) {
	Effect.BlindDown(div);
	anchor.onclick = function() {
		cierraMe(div, anchor);
	}
}

function irA(id) {
	new Effect.ScrollTo(id);
}

var Banners = {};
(function() {
	
	this.start = function(el) {
		this.banners = el.immediateDescendants();
		this.banners.each(function(banner, index) {
			banner.setStyle({"zIndex": this.banners.length - index});
		}.bind(this));
		
		setInterval(this.animate.bind(this), 2000);
	};
	
	this.animate = function() {
		this.banners.push(this.banners.shift());
		
		this.banners.each(function(banner, index) {
			if (index == this.banners.length - 1) {
				banner.setStyle({"zIndex": this.banners.length + 1});
				Effect.Fade(banner, {
					duration: 1,
					afterFinish: this.restoreLastBannerStyle.bind(this)
				});
			} else {
				banner.setStyle({"zIndex": this.banners.length - index});
			}
			
		}.bind(this));
	};
	
	this.restoreLastBannerStyle = function() {
		this.banners[this.banners.length - 1].setStyle({"zIndex": this.banners.length - 1});
		this.banners[this.banners.length - 1].show();
	}
	
}).apply(Banners);

document.observe("dom:loaded", function() {
	Banners.start($$(".BANNERS")[0]);
});
