function $id(id){ return document.getElementById(id);}

(function($){
	
	
	$(function(){ // ONLOAD
	
		if (document.getElementById('basic-accordian'))
		{
		new Accordian('basic-accordian',2,'header_highlight');	
		}
	
		var ran_unrounded=Math.random()*3;
		var num=Math.floor(ran_unrounded); 		
		
		if (num == 0) { num = 1 }
		
		play_banner(2,'link',5000);
		//play_banner(num,'link',5000);
		setTimeout('sair(150)',5000);		
		
		var clone = '';
		/*
		 * Para cada item li do teaser, faz-se um clone para poder ser executada a rotina de movimento do teaser
		 */
		$("#teaserMenu li").each(function(i){
				if (this.id != '' && typeof(this.id) != 'undefined') {
					clone = document.createElement("DIV");
					clone.id = 'clone_' + this.id;
					this.appendChild(clone);
					clone.className = "cloneTeaser";
					with (clone.style) {
						position = 'absolute';
						top = this.offsetTop + 'px';
						left = this.offsetLeft + 'px';
						zIndex = 10 - i;
						background = "#fff";
						filter = "alpha(opacity=0)"
						opacity = 0;
					}
					clone.onmouseover = overTeaser;
					clone.onmouseout = outTeaser;
				}
		});
		
		
	});		// ONLOAD
	

	
	
	/*
	 * Rotina que é executada quando o mouse está por cima de algum elemento do teaser
	 */
	overTeaser = function(){
		this.over = true;
		var link = '';
		var i = 1;
		var _this = this;
		setTimeout(function(){
			//Se depois do tempo definido o usuário, ainda estiver por cima do link, executa a animação
			if (_this.over == true) {
				teaser(_this, 0);
			}
		}, 10)
	}
	
	/*
	 * Rotina que é executada quando o mouse sai de cima de algum elemento do teaser
	 */
	outTeaser = function(){
		//	$id(this.id.split('_')[1]).style.height = '80px';
		//	this.style.height = '80px';
		this.over = false;
		if (this.move != null) 
			this.volta = true;
		teaser(this, 1);
	}
	
	/**
	 * Rotina que faz o movimento do teaser
	 * -----------------------------------------------------
	 * @param {Object} obj - objeto
	 * @param {Object} dir - direção (crescer ou diminuir)
	 * -----------------------------------------------------
	 */
	function teaser(obj, dir){
		clearInterval(obj.move);
		obj.move = null;
		var max = 145;
		var min = 80;
		var numVezes = 3;
		var velo = parseInt((max - min) / numVezes);
		var tam = 0;
		var primeiraVez = true;
		//Pega a altura do objeto.
		if (obj.style.height != '') {
			var _px = obj.style.height.split('px');
			tam = parseInt(_px[0]);
		}
		else {
			tam = parseInt(obj.offsetHeight);
		}
		
		switch (dir) {
			case 0: //Cresce
				obj.move = setInterval(function(){
					/*
				 * Executa a animação enquanto o item não chegou ao tamanho máximo
				 */
					if (tam < max) {
						obj.style.height = tam + 'px';
						$id(obj.id.split('_')[1]).style.height = tam + 'px';
						obj.style.top = $id(obj.id.split('_')[1]).offsetTop + 'px';
					}
					else {
						clearInterval(obj.move);
						obj.move = null;
						obj.style.height = max + 'px';
						$id(obj.id.split('_')[1]).style.height = max + 'px';
						if (acabouMovimento) 
							acabouMovimento(obj, dir, min);
						obj.volta = false;
						primeiraVez = true;
					}
					tam += velo;
				}, 1)
				break;
			case 1: //Diminui
				obj.move = setInterval(function(){
					/*
				 * Executa a animação enquanto o item não chegou ao tamanho mínimo
				 */
					if (tam > min) {
						obj.style.height = tam + 'px';
						$id(obj.id.split('_')[1]).style.height = tam + 'px';
						obj.style.top = $id(obj.id.split('_')[1]).offsetTop + 'px';
					}
					else {
						obj.style.height = min + 'px';
						$id(obj.id.split('_')[1]).style.height = min + 'px';
						
						clearInterval(obj.move);
						obj.move = null;
						obj.volta = false;
						if (acabouMovimento) 
							acabouMovimento(obj, dir);
					}
					tam -= velo;
				}, 1)
				break;
		}
		
	}
	
	
	/**
	 * Função que é executada quando acaba o movimento do teaser
	 * ----------------------------------------------------------
	 * @param {Object} obj - Objeto
	 * @param {Object} dir - direção (crescer ou diminuir)
	 * @param {Object} min - Valor minimo do teaser
	 * ----------------------------------------------------------
	 */
	function acabouMovimento(obj, dir, min){
		switch (dir) {
			case 0:
				var clone = '';
				var i = 1;
				while (clone = $id('clone_teaserLink' + i)) {
					if (obj.id != 'clone_teaserLink' + i) 
						$id('teaserLink' + i).style.height = min + 'px';
					clone.style.top = $id('teaserLink' + i).offsetTop + 'px';
					i++;
				}
				break;
			case 1:
				var clone = '';
				var i = 1;
				while (clone = $id('clone_teaserLink' + i)) {
					clone.style.top = $id('teaserLink' + i).offsetTop + 'px';
					i++;
				}
				break;
		}
		
	}
	
	/**
	 * End rotina teaser menu
	 */	
	
	
		
})(jQuery);		
		
jQuery.noConflict();		
