/*
	funções de suporte ao inweb 2.5
*/
$(document).ready(function() {
    
    // Eventos AJAX
    $().ajaxStart(function() { $('#loading').show(); });
    $().ajaxStop(function() { $('#loading').hide(); });
    
	// colocar a coluna do menu com a mesma altura do conteúdo - jquery.equalize.js
	$("#centroMenu, #centroConteudo").equalizeCols();

	// TABS e eventos associados. jquery.tabs.js e jquery.tabs.css
	if ( currentPage == "pesquisa" || currentPage == "ajuda") {
		$('#container ul').tabs({
			click: function(e,b) {
				var a=$("#curTab")[0];
				a.value = b.id;
				$.ajax({
				   type: "GET",
				   url: "altera.aspx",
				   data: "quit=1&tab="+b.id
				});
///	alert(currentPage);	
				   
				if ( currentSearch == "orientada" )
					reloadExemplos(b.id);
					
				if ( currentSearch == "especifica" )
					colocaCamposSelect(b.id);
					
				if ( currentSearch == "guiada")
					guiadaLoadContent(b.id);
				   
				currentTab = b.id;
			}
		});
	}	
	if ( currentPage != "ficha")
	{
		// Colocar os exemplos e actualizar o formulário
		if ( currentSearch == "orientada")
			reloadExemplos(currentTab);

		// ACTUALIZAR OS CAMPOS da pesquisa especifica 
		if ( currentSearch == "especifica")
			colocaCamposSelect(currentTab);
		
		// Reload dos items da guiada
		if ( currentSearch == "guiada")
			guiadaLoadContent(currentTab);
	}	
	// Imagens - jquery.jcarousel.js e jquery.carousel.css e skin (tango)
	jQuery('#mycarousel').jcarousel({vertical:true});
	$('a.lightbox').lightBox();
	
    // Exibir os tooltips jquery.tips.js e jquery.tips.css
    // $(".showtip").showTip('#ECECEC','#333333');
});

///////////////////////////////////////////////////////////////////////////////////////////////////////// PESUISA ORIENTADA
var ExemplosOrientada = { 
    "fea" : [  
        { "quem"    : "Bernardes, Policarpo de Oliveira", 
          "oque"    : "Credence",
          "como"    : "",
          "quando"  : "14th / 15th" 
        }
    ]
} 

function reloadExemplos(tab) {
    var obj = eval("ExemplosOrientada."+tab)[0];
    if ( typeof obj != "undefined" ) {  
        
        if ( obj.quem != "" ) {
            $("#exemplo_quem").html(obj.quem);
            $("#tab_quem").show() ;
        } else {
            $("#tab_quem").hide() ;
        }
        a = $(".quem:first")[0];
        a.value = "";

        if ( obj.oque != "" ) {
            $("#exemplo_oque").html(obj.oque);
            $("#tab_oque").show() ;
        } else {
            $("#tab_oque").hide() ;
        }
        a = $(".oque:first")[0];
        a.value = "";

        if ( obj.como != "" ) {
            $("#exemplo_como").html(obj.como);
            $("#tab_como").show() ;
        } else {
            $("#tab_como").hide() ;
        }
        a = $(".como:first")[0];
        a.value = "";

        if ( obj.quando != "" ) {
            $("#exemplo_quando").html(obj.quando);
            $("#tab_quando").show() ;
        } else {
            $("#tab_quando").hide() ;
        }
        a = $(".quando:first")[0];
        a.value = "";
    }
} 

function actualizaExemplo(area) {
	// valor da tab default
    var curTab  = $("#curTab")[0];     
    if ( curTab.value == "" ) 
        curTab.value = currentTab;	
    
    var obj     = eval("ExemplosOrientada."+curTab.value)[0];
    var valor   = eval("obj." + area);
    var box     = $("."+area)[0];
    box.value   = valor;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////// PESUISA ESPECIFICA
var CamposEspecifica = { 
    "fea" : [          
        { "Num_Inventario"          : "Inventory nr.", 
          "ta_DesignacaoObjecto"  : "Object name",
          "obj_Autoria"					: "Author",
          "Titulo"							: "Title" 
        }
    ]
} 

function  colocaCamposSelect(tab) {
    var obj = eval("CamposEspecifica."+tab)[0];
    if ( typeof obj != "undefined" ) {
        var firstItem = true;
        $(".selCampos" ).each(function() {
            // Limpar todos os elementos
            this.options.length=0;
            
            selInsereItem(this,"----", "-");
            // Inserir os novos campos
            for ( key in obj ) 
                selInsereItem(this, obj[key], key);
            
            this.selectedIndex = firstItem ? 1 : 0;
            firstItem = false;
        });
    } 
}

function selInsereItem(objSel, texto, valor)
{
  
	var elOptNew = document.createElement('option');

	elOptNew.text = texto;

	elOptNew.value = valor;
  
	
	try {
  
		objSel.add(elOptNew, null); 

	} catch(ex) {
 
		objSel.add(elOptNew); // IE only
	}

}

///////////////////////////////////////////////////////////////////////////////////////////////////////// PESUISA GUIADA
var contentLoaded = new Array();
//$.taconite.debug = true; 
function guiadaLoadContent(tab) {
    if ( contentLoaded[tab] == 1 )
        return;
    $.ajax( { url: 'guiada.ashx?tab='+tab } ); 
}

