function frase_run(){
	
	//$("#frase1").fadeIn("slow");
	var t=setTimeout( "frase_run1();" ,500);
	
}
function frase_run1(){
	
	$("#frase2").fadeOut('slow',function(){
		$("#frase1").fadeIn("slow");
	})
	var t=setTimeout( "frase_run2();" ,4000);
	
}
function frase_run2(){
	
	$("#frase1").fadeOut('slow',function(){
		$("#frase2").fadeIn("slow");
	})
	var t=setTimeout( "frase_run1();" ,4000);
	
}
$(function() {
	
	
	//Slides
	var ativo = $(".slide .ativo");
	var left  = $(".slide .left");
	var right = $(".slide .right");
	left.click(function(){ slide_go(-1); });
	right.click(function(){ slide_go(+1); });
	
	function slide_nav(){
		
		var atual = ativo.attr("slide");
		if(!atual) atual = 0;
		var max = 7;
		
		if(atual<2){
			//esconde esquerdo
			left.hide();
		}
		
		if(atual>=2){
			//mostra esquerdo
			left.show();
		} 
		if(atual<max){
			//mostra direito
			right.show();
			
		}
		if(atual>=max){
			//esconde direito
			right.hide();
			
		}
	}
	function slide_go(novo){
		var atual = ativo.attr("slide");
		if(!atual) atual = 0;
		x = atual -1 +1 + novo;
		//bg_style = 'url(/img/slide_'+x+'.png)';
		
		//ativo.css("background",bg_style);
		ativo.html('<img src=/img/slide_'+x+'.png>');
		ativo.attr("slide",x);
		
		slide_nav();
	}
	function slide_start(){
		slide_go(1);
	}
	
	slide_start();

	

	//Default
		$("input[default],textarea[default]").each(function(){
			var t = $(this); 
			var dfv = t.attr("default"); if(!dfv) return false;
			var dfcolor = t.css("color");
			var ofv = "";
			if(t.val()=='') {
				t.val(dfv); t.css("color","silver");
			}
			t.focus(function(){ 
				if(t.val()==dfv) {
					t.val(ofv); t.css("color",dfcolor);
				}  
			});
			t.blur(function(){
				if(t.val()==ofv) {
					t.val(dfv); t.css("color","silver");
				}
			});
		});	
	$(".toggle .open").click(function(){
		$(this).parents().parent(".toggle").find(".visible").first().hide("slow");
		$(this).parents().parent(".toggle").find(".hidden").first().show("slow");
		$(this).parents().parent(".toggle").find(".hidden :input:first").select();
		return false;
	});

	$(".toggle .visible").show();
	$(".toggle .hidden ").hide();
	
	$(".toggle .close").click(function(){
		$(this).parent(".toggle").find(".hidden").first().hide("slow");
		$(this).parent(".toggle").find(".visible").first().show("slow");
		$(this).parent(".toggle").find(".visible :input:first").select();
		return false;
	});	

	$(".toggle .open").click(function(){
		$(this).parents().parent(".toggle").find(".visible").first().hide("slow");
		$(this).parents().parent(".toggle").find(".hidden").first().show("slow");
		$(this).parents().parent(".toggle").find(".hidden :input:first").select();
		return false;
	});

	$(".toggle .visible").show();
	$(".toggle .hidden ").hide();
	
	$(".toggle .close").click(function(){
		$(this).parents().parent(".toggle").find(".hidden").first().hide("slow");
		$(this).parents().parent(".toggle").find(".visible").first().show("slow");
		$(this).parents().parent(".toggle").find(".visible :input:first").select();
		return false;
	});	

	$(".dialog_open").each(function(){
		
		$(this).click(function(){
			var target = $(this).attr("target");
			var h = $(this).attr("h"); if(!h) h = 340;
			var w = $(this).attr("w"); if(!w) w = 480;
			$(target).dialog({ width:w, height:h, modal:true});
			return false;
		});
		
	});
	
	//Frases
		frase_run();

	//Scroll
		var $scrollingDiv = $("#logo");
		var $scrollingDiv2 = $(".fundo_1");
	
		$(window).scroll(function(){
			if($scrollingDiv) {		
				$scrollingDiv
				.stop()
				.animate({"marginTop": ($(window).scrollTop() + 60) + "px"}, {duration:5000,queue:false} );
			}
	
			if($scrollingDiv2){
				$scrollingDiv2
				.stop()
				.css("marginTop" , ($(window).scrollTop()) + "px");
			}
		});
	
});
