var ajaxTimbuk2 = new ajax({
	'method': 'GET',
	'url': '/produtosTimbuk/',
	'oncomplete': function() {
		//$('galerias').innerHTML = this.text;
		
		var html = '<table cellpadding="0" cellspacing="5" border="0" width="164" align="center">';
		
		this.setChildName('produto');
		for(var i = 0; i<parseInt(this.getCountItens()); i++){
			html += '<tr><td align="left" colspan="2"><div class="arial11pxBranca" style="background-color:#463d2c;padding:2px 5px 2px 5px;"><a href="'+this.getAttByName('slug',i)+'" class="arial11pxBranca" style="text-decoration:none;" target="_blank">'+this.getAttByName('titulo',i)+'</a></div></td></tr>';
            html += '<tr><td style="width:40px; height:40px;" valign="top"><a href="'+this.getAttByName('slug',i)+'" target="_blank"><img src="'+this.getAttByName('foto',i)+'" width="50" height="41" /></a></td><td align="left" class="arial11pxCinza">';
            valor = this.getAttByName('valor',i);			
			if (parseInt(this.getAttByName('valorPromo',i)) > 0 ){
            	valor = this.getAttByName('valorPromo',i);
			}
			
			valor = valor.toCurrency();
			
			html += '<a href="'+this.getAttByName('slug',i)+'" class="arial11pxCinza" style="text-decoration:none;" target="_blank"><b><span style="color:#7d9c27;">Pre&ccedil;o:</span> R$'+valor+'</b><br />';
			html += this.getAttByName('resenha',i)+'</a>';
            html += '</td></tr>';
		}
		
		html += '</table>';
		
		$('timbuk2').innerHTML = html;
		delete ajaxTimbuk2;
	}
});

var FESTAS = {
	// Versao 1.0 B
	// By Gabriel Galiaso
	'content': 'fotoFesta',
	'preloader': 'loaderFotos',
	'alphaCreated': false,
	'block': false,
	'data': '/festasHome/?nocache='+nocache(),
	'arrFestas': new Array(),
	'timeOut': null,
	'time':6000,
	'atual':0,
	'open': function(){
		if(!this.alphaCreated){
			this.alphaCreated = true;
			new alpha(this.content);
		}
		
		FESTAS = this;
		
		var ajaxFestas = new ajax({
			'method': 'GET',
			'url': this.data,
			'oncomplete': function() {
				this.setChildName('festa');
				
				for(var i = 0; i<parseInt(this.getCountItens()); i++){
					var obj = new Object();
					obj.titulo = this.getAttByName('titulo',i);
					obj.slug = this.getAttByName('slug',i);
					obj.data = this.getAttByName('data',i);
					obj.hora = this.getAttByName('hora',i);
					obj.cidade = this.getAttByName('cidade',i);
					obj.local = this.getAttByName('local',i);
					obj.capap = this.getAttByName('capap',i);
					obj.capag = this.getAttByName('capag',i);
					
					FESTAS.arrFestas.push(obj);
				}				
				
				FESTAS.atual = -1;
				FESTAS.mudaFesta(1);
				
				delete ajaxFestas;
			}
		});
		ajaxFestas.open();
	},
	'abrirFesta': function(){
		location = '/festa/'+this.arrFestas[this.atual].slug;
	},
	'mudaFesta': function(id){
		if(this.block) return false;
		
		if(this.timeOut) clearTimeout(this.timeOut);
		
		this.atual  += parseInt(id);
		if(this.atual > this.arrFestas.length-1) this.atual = 0;
        if(this.atual < 0) this.atual = this.arrFestas.length-1;		
		
		$(this.preloader).style.display = "block";
		
		FESTAS = this;
		FESTAS.block = true;
		
		$(this.content).alphaTo(100,0,'linear',0.3, function(){
			var loaderImg = new Image();
			loaderImg.onload = function(){
				$(FESTAS.content).src = this.src;
				
				$(FESTAS.content).style.display = "block";
				$(FESTAS.preloader).style.display = "none";
				
				$('festaTitulo').innerHTML = FESTAS.arrFestas[FESTAS.atual].titulo;
				$('festaData').innerHTML = FESTAS.arrFestas[FESTAS.atual].data;
				$('festaHora').innerHTML = FESTAS.arrFestas[FESTAS.atual].hora;
				$('festaCidade').innerHTML = FESTAS.arrFestas[FESTAS.atual].cidade;
				$('festaLocal').innerHTML = FESTAS.arrFestas[FESTAS.atual].local;
				
				$(FESTAS.content).alphaTo(0,100,'linear',0.3, function(){
					FESTAS.block = false;
					FESTAS.timeOut = setTimeout("FESTAS.mudaFesta(1);", FESTAS.time);
				});
			}
			loaderImg.src = FESTAS.arrFestas[FESTAS.atual].capag;
		});		
	}
}


var PARCEIROS = {
	// Versao 1.0 B
	// By Gabriel Galiaso
	'content': 'parceriros',
	'preloader': 'loaderParceiros',
	'alphaCreated': false,
	'block': false,
	'data': '/parceirosHome/?nocache='+nocache(),
	'arrPARCEIROS': new Array(),
	'timeOut': null,
	'time':6000,
	'atual':0,
	'open': function(){
		if(!this.alphaCreated){
			this.alphaCreated = true;
			new alpha(this.content);
		}
		
		PARCEIROS = this;
		
		var ajaxFestas = new ajax({
			'method': 'GET',
			'url': this.data,
			'oncomplete': function() {
				this.setChildName('parceiro');
				
				for(var i = 0; i<parseInt(this.getCountItens()); i++){
					var obj = new Object();
					obj.titulo = this.getAttByName('titulo',i);
					obj.url = this.getAttByName('url',i);
					obj.foto = this.getAttByName('foto',i);
					
					PARCEIROS.arrPARCEIROS.push(obj);
				}				
				
				PARCEIROS.atual = -1;
				PARCEIROS.muda(1);
				
				delete ajaxFestas;
			}
		});
		ajaxFestas.open();
	},
	'muda': function(id){
		if(this.block) return false;
		
		if(this.timeOut) clearTimeout(this.timeOut);
		
		this.atual  += parseInt(id);
		if(this.atual > this.arrPARCEIROS.length-1) this.atual = 0;
        if(this.atual < 0) this.atual = this.arrPARCEIROS.length-1;		
		
		$(this.preloader).style.display = "block";
		
		PARCEIROS = this;
		PARCEIROS.block = true;
		
		$(this.content).alphaTo(100,0,'linear',0.3, function(){
			var loaderImg = new Image();
			loaderImg.onload = function(){
				$(PARCEIROS.content).src = this.src;
				
				$(PARCEIROS.content).style.display = "block";
				$(PARCEIROS.preloader).style.display = "none";
				
				var html = '<table cellpadding="0" cellspacing="5" border="0" width="164" align="center" style="margin-left:18px; margin-top:5px;"><tr><td height="57"><a href="'+PARCEIROS.arrPARCEIROS[PARCEIROS.atual].url+'" target="_blank"><img src="'+PARCEIROS.arrPARCEIROS[PARCEIROS.atual].foto+'" width="120" height="50" style="border:solid 3px #1f556b;" /></a></td></tr></table>'
				
				$('parceirosSrc').innerHTML = html;
				
				$(PARCEIROS.content).alphaTo(0,100,'linear',0.3, function(){
					PARCEIROS.block = false;
					PARCEIROS.timeOut = setTimeout("PARCEIROS.muda(1);", PARCEIROS.time);
				});
			}
			loaderImg.src = PARCEIROS.arrPARCEIROS[PARCEIROS.atual].foto;
		});
		
	}
}

window.onload = function(e){
	mostraFlash("logo", "/media/swf/logo.swf", 118, 108);
	mostraFlash("menu", "/media/swf/menu.swf", 986, 39);
	
	FESTAS.open();
	
	PARCEIROS.open();
}
