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;		
		
		$G(this.preloader).style.display = "block";
		
		FESTAS = this;
		FESTAS.block = true;
		
		$G(this.content).alphaTo(100,0,'linear',0.3, function(){
			var loaderImg = new Image();
			loaderImg.onload = function(){
				$G(FESTAS.content).src = this.src;
				
				$G(FESTAS.content).style.display = "block";
				$G(FESTAS.preloader).style.display = "none";
				
				$G('festaTitulo').innerHTML = FESTAS.arrFestas[FESTAS.atual].titulo;
				$G('festaData').innerHTML = FESTAS.arrFestas[FESTAS.atual].data;
				$G('festaHora').innerHTML = FESTAS.arrFestas[FESTAS.atual].hora;
				$G('festaCidade').innerHTML = FESTAS.arrFestas[FESTAS.atual].cidade;
				$G('festaLocal').innerHTML = FESTAS.arrFestas[FESTAS.atual].local;
				
				$G(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;
		});		
	}
};


$(document).ready(function() {
	if($('#fotoFesta').size()) FESTAS.open();
	
	if ($("#twitter").size()){		
		$("#twitter").twitter({
			userName: "hiperbalada",
			numTweets: 10,
			loaderText: "Loading tweets...",
			slideIn: false,
			showHeading: true,					
			showProfileLink: false,
			oneByOne: true,
			delay: 10000
		});
	};
	
	if ($("#content_thumbs").size()){
		GA.masc = 'masc_thumbs';
		GA.content = 'content_thumbs';
		GA.contentGrande = 'contentGrande';
		GA.preloaderGrande = 'loaderFotoGrande';
		GA.btAnt = "btAnt";
		GA.btProx = "btProx";
		GA.idFotoAtual = 'idFoto';
		GA.thumb.w = 93;
		GA.thumb.h = 63;
		GA.thumb.css ='linkThumbGaleria';
		GA.data = "/xmlGaleria/";
		vertical: true,
		GA.qtdMover = 6;
		GA.create();
	};
	
	
	$('#categoriasVideos').simpleSliderHeight();
	
	$('#btBuscar').click(function(){
		if($("#argBusca").val() != "" && $("#argBusca").val() != $("#argBusca").attr('title')) $('#cse-search-box').submit();
	});
	
	$("#argBusca").focus(function(){ if($(this).val() == $(this).attr('title')) $(this).val(""); });
	$("#argBusca").blur(function(){ if($(this).val() == "") $(this).val($(this).attr('title')); });

	
});

