// Arquivo para chamar funções jquery automaticamente através da class ao chamar a página
$j(document).ready ( function () {   
    
    var $objOverClass='hideOnFocus'; 
    //// classe que chama o novo example 
    // basta incluir a classe e title='frase' se o value inicial for diferente
    
    var $lightBoxGroup='lightboxGroup';
    /// classe na div que envolve links de imagens (galeria lightbox)
    
	/// configuracao de tabs
	var $objTabNavigator='tabNavigator'; /// abas da tab
	var $objTabContent='tabContent'; // div dos conteudos
	var $selectedTab='tabselected'; /// aba selecionada
    
    //// nova função example ->
    $j('.'+$objOverClass).each( function () {
    
    var $obj=$j(this);
        
	if (!$obj.attr('title')){
	$obj.attr('title',$obj.val())
    }
	
	$obj.focus( function () {
		if ($obj.val()==$obj.attr('title')){
			$obj.val('');	
		}
	});
	
	$obj.blur( function () {
	   
		if ($obj.val()==''){
			$obj.val($obj.attr('title'));	
		}
	});
    
    });
	//// fim nova função example <-
    
    /// chama lightbox incluir os arquivos jquery.lightbox.js e jquery.lightbox.css ->
    if ($j('.'+$lightBoxGroup).length > 0){
      $j(function() {
	      $j('.'+$lightBoxGroup+' a').lightBox();
      });     
    }
	
	/// fim da função de lightbox <-
	
	//// funcao de tabs ->	
	
	var $objUl=$j("ul."+$objTabNavigator+" li");
	var $objCont=$j("."+$objTabContent)
	
	
	/// acha a que tem a classe selected
	$objCont.hide(); //Hide all content
	$j("ul."+$objTabNavigator+" li."+$selectedTab).show(); //Activate first tab
	var $firstSelectedTab = $j("ul."+$objTabNavigator+" li."+$selectedTab).find("a").attr("href");
	$j($firstSelectedTab).show();
	
	
	
	//On Click Event
	$objUl.click(function() {

		$objUl.removeClass($selectedTab); //Remove any "active" class
		$j(this).addClass($selectedTab); //Add "active" class to selected tab
		$objCont.hide(); //Hide all tab content

		var activeTab = $j(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$j(activeTab).fadeIn(); //Fade in the active ID content
		return false;


	});
	
	/// fim da funcao de tabs <-
    
    /// mascara de campo data 
     if ($j('.datamask').length > 0){ 
        var $dataObj=$j('.datamask');
        $dataObj.mask("99/99/9999"); 
        //$dataObj.datepicker($.datepicker.regional['pt-br']);
        
        $dataObj.datepicker({
			showOn: 'button',
			buttonImage: '/scripts/jquery/ui/css/images/cal.gif',
			buttonImageOnly: true,
            regional: 'pt-br'
		});
        
    }
    
    
    /// mascara de telefone,cep,cpf, etc
    if ($j('.telefonemask').length > 0){  $j('.telefonemask').mask("(99)9999-9999"); }
    
    if ($j('.cepmask').length > 0){  $j('.cepmask').mask("99999-999"); }
    
    if ($j('.cpfmask').length > 0){  $j('.cpfmask').mask("999.999.999-99"); }
    
    
    /// configuracao autocomplete -> class='autoComplete' rel= (type to php) - arquivo: 'autoComplete.php'
    if ($j('.autoComplete').length>0){
        
        
		function split(val) {
			return val.split(/;\s*/);
		}
		function extractLast(term) {
			return split(term).pop();
		}
		
        
        $j('.autoComplete').each (function (){
            
            var $relObj=$j(this).attr('rel');
            $j(this).autocomplete({		  	          
		   source: function(request, response) {
				$j.getJSON("/scripts/jquery/ui/autoComplete.php", {
					term: extractLast(request.term),
                    type: $relObj
				}, response);
			},
			search: function() {
				// custom minLength
				var term = extractLast(this.value);
				if (term.length < 1) {
					return false;
				}
			},
			focus: function() {
				// prevent value inserted on focus
				return false;
			},
			select: function(event, ui) {
				var terms = split( this.value );
				// remove the current input
				terms.pop();
				// add the selected item
				terms.push( ui.item.value );
				// add placeholder to get the comma-and-space at the end
				terms.push("");
				this.value = terms.join("; ");
				return false;
			}
		});            
        });
	

    }
    
    ////////////// <-
        
});
