function novaJanela(l) {
	var newWindow = window.open(l, '_blank');
	newWindow.focus();
}

function temporizador() {
	clearTimeout(t);
	proximafoto();
	t = setTimeout("temporizador()", 5000);
}

function control() {
	if(c)
		parar();
	else
		play();	
}

function play() {
	$("#control").html(foto_pause);
	temporizador();	
	c = 1;
}

function parar() {
	clearTimeout(t);
	$("#control").html(foto_play);	
	c = 0;
}

function abre(id) {
	clearTimeout(t);
	$("#content").fadeOut("slow");
	$("#marilia").hide();
	$("#diego").hide();
	abreMenuHorizontal();
	abrefotos(id);
	temporizador();
	$("#control_prev").show();
	$("#control_prev").click(function() {
		if(c) {
			clearTimeout(t);
			anteriorfoto();
			t = setTimeout("temporizador()", 5000);
		} else {
			anteriorfoto();	
		}
	});
	
	$("#control_next").show();
	$("#control_next").click(function() {
		if(c) temporizador();
		else proximafoto();
	});

	$("#control").html(foto_pause);
	$("#control").show();
	
	$("#control").click(function() {
		control();
	});
	
	$("#control_prev").stop().animate({ opacity: 0.1 }, 500);
	$("#control_next").stop().animate({ opacity: 0.1 }, 500);
	$("#control").stop().animate({ opacity: 0.1 }, 500);
	
	$("#control_prev").hover(function() {
		$(this).stop().animate({ opacity: 1.0 }, 500);
	}, function() {
		$(this).stop().animate({ opacity: 0.1 }, 500);
	});
	
	$("#control_next").hover(function() {
		$(this).stop().animate({ opacity: 1.0 }, 500);
	}, function() {
		$(this).stop().animate({ opacity: 0.1 }, 500);
	});
	
	$("#control").hover(function() {
		$(this).stop().animate({ opacity: 1.0 }, 500);
	}, function() {
		$(this).stop().animate({ opacity: 0.1 }, 500);
	});
	
	$("#foto").click(function() {
		parar();
		$("#control").stop().animate({ opacity: 1.0}, 500);
	});
}

function abreMenuHorizontal() {
	$('#menu').fadeOut("slow", function() {
		$('#menu2').fadeIn("slow");	
	});
	
}

function abretexto(id) { 
	loadingtexto();
	$("#marilia").hide();
	$("#diego").hide();
	abreMenuHorizontal();
	parar();
	//$("#control").hide();
	//$("#control_prev").hide();
	//$("#control_next").hide();
	//loading(true);
	$.ajax({
	   url: "texts/index/" + id,
		dataType: "html",
		success: function(html) {
			//$("#content_loading").html('');
			$("#content_middle").html(html);	
		}
	});
	$('#content').fadeIn("slow");
}

function abreblog(id) {
	var tid;
	
	if(!id) tid = '';
	else tid = id;
	
	loadingtexto();
	$("#marilia").hide();
	$("#diego").hide();
	abreMenuHorizontal();
	parar();
	//$("#control").hide();
	//$("#control_prev").hide();
	//$("#control_next").hide();
	//loading(true);
	$.ajax({
	   url: "blogs/index/" + tid,
		dataType: "html",
		success: function(html) {
			//$("#content_loading").html('');
			$("#content_middle").html(html);	
		}
	});
	$('#content').fadeIn("slow");	
}

function abrevideos() {
	loadingtexto();
	$("#marilia").hide();
	$("#diego").hide();
	abreMenuHorizontal();
	parar();
	//$("#control").hide();
	//$("#control_prev").hide();
	//$("#control_next").hide();
	//loading(true);
	$.ajax({
	   url: "videos/index/",
		dataType: "html",
		success: function(html) {
			//$("#content_loading").html('');
			$("#content_middle").html(html);	
		}
	});
	$('#content').fadeIn("slow");	
}

function abrecontato() {
	loadingtexto();
	$("#marilia").hide();
	$("#diego").hide();
	abreMenuHorizontal();
	parar();
	//$("#control").hide();
	//$("#control_prev").hide();
	//$("#control_next").hide();
	$.ajax({
	   url: "texts/contato/",
		dataType: "html",
		success: function(html) {
			//$("#content_loading").html('');
			$("#content_middle").html(html);	
		}
	});
	$("#content").fadeIn("slow");
}

function proximafoto() {
	if(arrPhoto[i+1] == undefined)
		i = 0;
	else
		i++;
	mostrafoto(i);
}

function anteriorfoto() {
	if(arrPhoto[i-1] == undefined)
		i = arrPhoto.length - 1;
	else
		i--;
	mostrafoto(i);
}

function mostrafoto(id) {
	loadingfoto();
	$("#foto").hide();
	$("#foto").html(arrPhoto[id]);
	$("#img_foto").load(function() { $("#loading_foto").html(''); $("#foto").fadeIn("slow"); });
}

function abrefotocapa() {
	loadingfoto();
	$.ajax({
		url: "photos/index",
		dataType: "html",
		success: function(html) {
			$("#foto").hide();
			$("#foto").html(html);
			$("#img_foto").load(function() {$("#loading_foto").html(''); $("#foto").fadeIn("slow"); }); 
		}
	});
}

function abrefotos(cat) {
	loadingfoto();
	$.ajax({
	   url: "photos/list_photos/" + cat,
		dataType: "html",
		async: false, 
		success: function(html) {
			$("#foto").html(html);
		}
	});
	mostrafoto(i);
}
