
var simpleViewer = null;


function carregarCarrossel(tipo, carregarGaleria){	
    $.get('lista_eventos.php'
		,{'tipo': tipo}
		, function(xml){	
		    var size = 0;
			var htmlCarousel = '';
			lastEventoId = parseInt( $('evento:first id', xml).text() );			
			if(carregarGaleria){
				carregaGaleria(lastEventoId, null);				
			}			
			items = $('evento', xml);
			htmlCarousel = '<ul id="mycarousel" class="jcarousel-skin-tango" >';
			items.each(
				function(i){				                         
					htmlCarousel += "\n<li>" + $('conteudo', this).text() + "</li>";						
					size++;
				}
			);	
			htmlCarousel += "</ul>";
			$('#carrossel').empty();
			$('#carrossel').html(htmlCarousel );					
			$('#mycarousel').jcarousel(	 {size: size , vertical: true });				
		}
		,'xml'
	); 	
	
}

function dumpVar(theObj, printable){
	
	var dump = '';
	
	if(theObj.constructor == Array || theObj.constructor == Object){
		dump += "<ul>";
		for(var p in theObj){
			if(theObj[p].constructor == Array || theObj[p].constructor == Object){
				dump += "<li>["+p+"] => "+typeof(theObj)+"</li>";
				dump += "<ul>";
				dump += print_r(theObj[p], printable);
				dump += "</ul>";
			} else {
				dump += "<li>["+p+"] => "+theObj[p]+"</li>";
			}
		}
		dump += "</ul>";
		
	}
	
	return dump;
	
}

function carregaPagina(pagina) {
	$('#comentario').css('display', 'none');
    $('#quadro:first-child').text('');
    $.get(pagina, function(dadosPagina) {
        $('#quadro').html(dadosPagina);
    });

}

function carregaGaleria(evento, cabecalho) {    
    var tabela = '<table cellpading="0" cellspacing="0" >';
    tabela += '<tr>';
    tabela += '<td height="46" align="center" valign="bottom" ><img src="imagens/pix.gif" height="8">';
    tabela += '<div id="tituloEvento" style="width: 500px;" class="textopadraobranco1" ></div>';
    tabela += '</td>';
    tabela += '</tr>';
    tabela += '<tr>';
    tabela += '<td>';
    tabela += '<div id="flashcontent">';
    tabela += '</div>';
    tabela += '</td>';
    tabela += '</tr>';
    tabela += '</table>';	
    $('#quadro:first-child').html(tabela);
    simpleViewer = viewerFactory('galeria.php?evento=' + evento);
    simpleViewer.write("flashcontent");	
	$('#comentario').css('display', 'inline');
	$('#comentario').attr('href', 'javascript:popComentario("comentarios.php?id='+evento+ '");' );
    $('#tituloEvento').html(cabecalho);
}

function carregaEventos() {
    carregaGaleria($('#last_evento').attr('value'), null);
}

function getLastEvento(tipo){
	
}

function viewerFactory(galleryPath) {
    if (simpleViewer != null) {
        simpleViewer.addVariable("xmlDataPath", galleryPath);
    }
    else {
        simpleViewer = new SWFObject("viewer.swf", "viewer", "100%", "100%", "8", "#FFFFFF");
        simpleViewer.addParam("wmode", "transparent");
        simpleViewer.addVariable("xmlDataPath", galleryPath);
    }
    return simpleViewer;
}