/*
	w3Opacity (1.0) - 15/01/2007
	Por Leandro Vieira Pinho - http://leandro.w3invent.com.br
	
	Para informações sobre o w3Opacity viste:
	http://leandro.w3invent.com.br/labs/
	
	Dúvidas, sugestões, bugs?
	http://leandro.w3invent.com.br/labs/forum
*/
var w3Opacity = {
	/**
	 * Método que realiza o fadeOut e fadeIn
	 * @param strObjId {string} - Nome do atributo ID do objeto que receberá o efeito
	 * @param intOpacityStart {number} - Número inicial para o efeito
	 * @param intOpacityEnd {number} - Número final para o efeito
	 * @param intMillisecond {number} - Número (em milisegundos) para o tempo de duração do efeito
	 * @param fnOnFinish {} - Função a ser chamada quando o efeito terminar
	 * Exemplos:
	 * Não chamar uma função ao terminar o efeito: w3Opacity.fading("obj_id",0,100,400);
	 * Chamar uma função ao terminar o efeito: w3Opacity.fading("obj_id",100,0,400,nome_da_funcao);
	 */
	fading: function(strObjId,intOpacityStart,intOpacityEnd,intMillisecond,fnOnFinish) {
		
		
		
		var intSpeed = Math.round(intMillisecond / 100);
		var intTimer = 0;
		// Processo para o FadeOut
		if ( intOpacityStart > intOpacityEnd ) {
			for ( i = intOpacityStart; i >= intOpacityEnd; i-- ) {
				if ( intTimer == 100 && typeof(fnOnFinish) != "undefined" ) {
					setTimeout("w3Opacity.change_opacity('" + strObjId + "'," + i +"," + fnOnFinish + ")",(intTimer * intSpeed));
				
				
				
				
				} else {
					setTimeout("w3Opacity.change_opacity('" + strObjId + "'," + i +")",(intTimer * intSpeed));					
				
				
				
				}
				intTimer++;
			}
		// Processo para o FadeIn
		
		if(i < 10){  document.getElementById(strObjId).innerHTML = ""; 	}
		
		} else if ( intOpacityStart < intOpacityEnd ) {
			for ( i = intOpacityStart; i <= intOpacityEnd; i++ ) {
				if ( intTimer == 100 && typeof(fnOnFinish) != "undefined" ) {
					setTimeout("w3Opacity.change_opacity('" + strObjId + "'," + i +"," + fnOnFinish + ")",(intTimer * intSpeed));
				} else {
					setTimeout("w3Opacity.change_opacity('" + strObjId + "'," + i +")",(intTimer * intSpeed));
				}
				intTimer++;
			}				
		}
	
	
	
	
	
	},
	/**
	 * Método que verifica a opacidade do objeto e realiza um fadeOut ou fadeIn :)
 	 * @param strObjId {string} - Nome do atributo ID do objeto que receberá o efeito
	 * @param intMillisecond {number} - Número (em milisegundos) para o tempo de duração do efeito
	 * Exemplos:
	 * w3Opacity.toggle("obj_id",400);
	 */
	toggle: function(strObjId,intMillisecond) {
	


	if ( this.get_opacity(strObjId) < 1 ) {
			// fadeIn
			
						
			//box.location = "adv-" + profissional + ".php";
			base = strObjId;
			new_strObjId = base.replace( "cv-","" );
			document.getElementById(new_strObjId + "-a").innerHTML = "&#171; ocultar currículo";
						
			
			
				this.fading(strObjId,0,101,intMillisecond);	
			
			
			
			
		
		} else {
			// fadeOut
			
				
			
			
			base = strObjId;
			
			new_strObjId = base.replace("cv-","");
			//new_strObjId = new_strObjId.replace("-a","");
			document.getElementById(new_strObjId + "-a").innerHTML = "&#187; veja o currículo";
			//document.getElementById("cv-claudiozalaf").innerHTML = "";
			
				this.fading(strObjId,101,0,intMillisecond);
				//document.getElementById('cv-' + profissional).innerHTML = "";
			
				//document.getElementById(strObjId)[0].innerHTML = "> ver currículo";
			
				
		}
	},
	/**
	 * Método que define uma opacidade para o objeto
	 * @param strObjId {string} - Nome do atributo ID do objeto que receberá o efeito
	 * @param intOpacity {number} - Número inteiro que será o valor da opacidade
	 */
	set: function(strObjId,intOpacity) {
		this.change_opacity(strObjId,intOpacity);
	},
	/**
	 * Método interno, utilizado para alterar a opacidade do objeto
	 */
	change_opacity: function(strObjId,intOpacity,hasFnOnFinish) {
	

	if (typeof(hasFnOnFinish) != "undefined") {
			hasFnOnFinish();
		}
		var objStyle = this.$(strObjId).style;
		objStyle.opacity = (intOpacity / 101);
		objStyle.MozOpacity = (intOpacity / 101);
		objStyle.KhtmlOpacity = (intOpacity / 101);
		objStyle.filter = "alpha(opacity=" + intOpacity + ")";
	},
	$: function(strObjId) {
		return document.getElementById(strObjId);
	},
	get_style: function(strObjId,strStyleProperty) {
		var objToGetStyle = this.$(strObjId), styleValue;
		// Para o Internet Explorer
		if ( objToGetStyle.currentStyle ) {
			styleValue = objToGetStyle.currentStyle[strStyleProperty];
		// Para o Firefox, Opera, ...
		} else if ( window.getComputedStyle ) {
			styleValue = document.defaultView.getComputedStyle(objToGetStyle,null).getPropertyValue(strStyleProperty);
		}
		return styleValue;
	},
	get_opacity: function(strObjId) {
		var opacity;
		if ( opacity = this.get_style(strObjId,'opacity') ) {
			return parseFloat(opacity);
		}
		if ( opacity = (this.get_style(strObjId,'filter') || '').match(/alpha\(opacity=(.*)\)/) ) {
			if ( opacity[1] ) {
				return parseFloat(opacity[1]) / 100;
			} else {
				return 1.0;
			}
		// Caso não seja aplicado ao objeto um filter... será retornado undefined. Então, considero como o objeto está visível: 100
		} else {
			return 1.0;	
		}
	}
};