/**
 *	Glassbox functions
 */
	var zeindex = 2000;

	function fechar(id){

		if(typeof Effect != 'undefined') {
			//2 overlay.hide();
			new Effect.Fade( id , {
				afterFinish: function() { 
					fecharremove(id);
				}
			});
			 if($( id + "_overlay" )) {
				new Effect.Fade( id + "_overlay", { 
					afterFinish: function() {
					overlay = $( id + "_overlay" );
					overlay.parentNode.removeChild( overlay );
					}
				});
			}
		} else {
			$( id ).style.display = "none";
			if($( id + "_overlay" )) {
				$( id + "_overlay" ).style.display = "none";
			}
			overlay = $( id + "_overlay" );
			overlay.parentNode.removeChild( overlay );
			//2 overlay.hide();
			fecharremove(id);
		}
	}

	function fecharremove(id){
		if($(id) && $( id + "_content" ))
			$( id ).innerHTML = $( id + "_content" ).innerHTML;
	}
	
	function janela(id,w,h,funcao,xurl,xid,sombra,skin){
		zeindex++;
		if(sombra){
			var overlay = new DialogOverlay(id);
			overlay.show();
			$(id +'_overlay').style.zIndex = zeindex;
			Event.observe($(id +'_overlay'), 'click', function() {
				fechar(id);
			});
		}
		janelafb = new GlassBox();
		janelafb.init( id, w, h, 'auto', skin, true, false);
		janelafb.lbo( false, 0.2 );
		//janelafb.draggable('');
		zeindex++;
		janelafb.zindex(zeindex);
		zeindex++;
		janelafb.appear(xurl,xid); // se xurl e xid estiverem a 0 nao ha qualquer chamada AJAX

		if(funcao){
			window[funcao]();
		}
	}

/**
 * GALERIA DE FOTOS - Goweb (c) 2010
 */
	
	Event.observe(window, 'load', function() {
		if($('slide-preview')){
			$('slide-preview').observe('mouseover', showMe);
			$('slide-preview').observe('mouseout', cima);
		}
		if($('slide-preview-info')){
			$('slide-preview-info').observe('mouseover', showMe);
			$('slide-preview-info').observe('mouseout', cima);
		}
	});

	function showControls() {
		$('slide-filtros').setStyle('display:block;');
		$('slide-setas').setStyle('display:block;');
		$('slide-panel').setStyle('background:#cccccc;');
		return false;
	}

	function hideControls() {
		$('slide-filtros').setStyle('display:none;');
		$('slide-setas').setStyle('display:none;');
		$('slide-panel').setStyle('background:#ebebe6;');
		return false;
	}

	function loadImage(url) {
		
	    var myAjax = new Ajax.Request(url,
        {
			method: 'post',
			onComplete: function(transport) {
		    	if (transport.responseText.isJSON()) {
				    $('slide-zoom').fade({afterFinish: function(){
					        $('slide-zoom').src = transport.responseJSON.imagem;
					        $('slide-zoom').alt = transport.responseJSON.titulo;
					        $('slide-zoom').title = transport.responseJSON.titulo;
					        $('slide-zoom').appear({duration: 0.1});
						}, duration: 0.3
					});
	
					$('titulo1').update(transport.responseJSON.titulo);
					$('slide-preview-info').update(transport.responseJSON.descricao);
					
					//$('portfolio_link').href = transport.responseJSON.url;
				}
	    	}
    	});
	}

	var goUp = 0;
	var goDown = 1;
	var relogio = window.setInterval('check()',200);

	function showMe(){
		goUp = 0;
		if(goDown){
			goDown = 0;
			/*
			new Effect.Move('portfolio_info', {
				duration:0.6,
				transition: Effect.Transitions.spring,
				x: 0,
				y: 150,
				afterFinish: function(){
				}
			});
			*/
			new Effect.Morph('slide-preview-info', {
				style: 'top:220px;',
				duration:0.4,
				afterFinish: function() {
					goDown = 1;
				}
			});
		}
	}

	function hideMe(){
		if(goUp){
			goUp = 0;
			new Effect.Morph('slide-preview-info', {
				style: 'top:320px;',
				duration:0.2,
				afterFinish: function() {
					goDown = 1;
				}
			});
		}
	}

	function cima(){
		goUp = 1;
		clearInterval(relogio);
		relogio = window.setInterval('check()',10);
	}

	function check(){
		hideMe();
	}

/**
 * mini paginacao
 */
	var new_actual = 1;

	function new_anterior(ver,total){
		if(new_actual!=1){
			if($('new_'+(new_actual-1))){
				$('new_'+new_actual).fade({duration:0.3}); // .style.display = "none";
				$('new_'+(new_actual-1)).appear({duration:0.3}); // .style.display = "block";
				new_actual = new_actual - 1;
				$('new_actual_num').innerHTML = (new_actual*ver);
			}
		}
	}

	function new_seguinte(ver,total){
		if(new_actual < total){
			if($('new_'+(new_actual+1))){
				$('new_'+new_actual).fade({duration:0.3}); // .style.display = "none";
				$('new_'+(new_actual+1)).appear({duration:0.3}); // .style.display = "block";
				new_actual = new_actual + 1;
				numero = (new_actual*ver);
				if(numero>total)
					numero = total;
				$('new_actual_num').innerHTML = numero;
			}
		}
	}

/**
 * menu footer
 */
				function verificar(elemento) {
					if (!elemento.hasClassName('activo')) {
						$$('#menuFooter li.activo').each(function(element) {
							if(element.hasClassName('social_random'))
								element.setStyle('background-position:0 0;');
							if(element.hasClassName('design_random'))
								element.setStyle('background-position:-143px 0;');
							if(element.hasClassName('marketing_random'))
								element.setStyle('background-position:-286px 0;');
							if(element.hasClassName('lab_random'))
								element.setStyle('background-position:-429px 0;');
						});
					}
				}
				
				function voltar(elemento) {
					if (!elemento.hasClassName('activo')) {
						$$('#menuFooter li.activo').each(function(element) {
							if(element.hasClassName('social_random'))
								element.setStyle('background-position:0 -39px');
							if(element.hasClassName('design_random'))
								element.setStyle('background-position:-143px -39px;');
							if(element.hasClassName('marketing_random'))
								element.setStyle('background-position:-286px -39px;');
							if(element.hasClassName('lab_random'))
								element.setStyle('background-position:-429px -39px;');
						});
					}
				}
