$(document).ready(function() {
//-------------------------------------------------------------------------------------onload
$('div#busca').css({ 'box-shadow':'0px 0px 25px 3px #fff','-webkit-box-shadow' : '0px 0px 25px 3px #fff','-moz-box-shadow' : '0px 0px 25px 3px #fff'});
var hash = location.hash;
if(hash == '#contato'){
	$('.wraper>div:eq(0)').fadeIn();
	$('.profile>a:eq(0)').addClass('selected');
} else if (hash == '#livros'){
	$('.wraper>div:eq(1)').fadeIn();
	$('.profile>a:eq(1)').addClass('selected');
} else if (hash == '#sites'){
	$('.wraper>div:eq(2)').fadeIn();
	$('.profile>a:eq(2)').addClass('selected');
} else if (hash == '#apps'){
	$('.wraper>div:eq(3)').fadeIn();
	$('.profile>a:eq(3)').addClass('selected');
} else if (hash == '#roteiros' || hash == '#reise-reise' || hash == '#rosenrot' || hash == '#truste'){
	$('.wraper>div:eq(4)').fadeIn();
	$('.profile>a:eq(4)').addClass('selected');
} else if (hash == '#7h06' || hash == '#afterlife' || hash == '#poison-x' || hash == '#saudoso-futuro' || hash == '#warld'){
	$('.wraper>div:eq(1)').fadeIn();
	$('.profile>a:eq(1)').addClass('selected');
	var content = '<div id="'+hash.slice(1)+'" class="livro L1">'+$(hash).html()+'</div>';
	$.fancybox(content,{'titleShow':false,'overlayColor':'#000','onClosed':function(){
		document.title = 'Fagner JB.';
		location.hash = '';
	}});
} else if (hash == '#404' || hash == '#503'){
	var text;
	if(hash == '#404') text = 'Página não encontrada';
	if(hash == '#503') text = 'Servidor sobrecarregado';
	document.title = document.title + " - " + text;
	var content = '<div id="error-'+hash.slice(1)+'" class="error">'+text+'</div>';
	$.fancybox(content,{'titleShow':false,'scrolling':'no','overlayColor':'#000','onClosed':function(){
		document.title = 'Fagner JB.';
		location.hash = '';
		$('.wraper>div.home').fadeIn();
		$('#searchform input').focus();
		$('.icones').fadeTo(400,0.6);
		$('.profile').fadeTo(400,0.6);		
	}});
} else {
$('.wraper>div.home').fadeIn();
$('#searchform input').focus();
$('.icones').fadeTo(400,0.6);
$('.profile').fadeTo(400,0.6);
}
	
//-------------------------------------------------------------------------------------menu
$('.profile a').click(function(e){
	var clicked = $('.profile a').index(this);
	$('.profile>a').removeClass('selected');
	if( $('.wraper>div:eq(' + clicked + ')').is(':hidden') ) {
	$('.wraper>div').hide();
	$('.wraper>div:eq(' + clicked + ')').fadeIn();
	$('.profile>a:eq('+clicked+')').addClass('selected');
	} else {
	e.preventDefault();
	location.hash = '#home';
	$('.wraper>div').hide();
	$('.wraper>div.home').fadeIn();
	}
}).mouseenter(function(){
	$('.alerta').html($('.profile a:eq(' + $('.profile a').index(this) + ')').attr("title"));
	$('.alerta').show();
}).mouseleave(function(){
	$('.alerta').hide();
});

//---------------------------------------------------------------------put title in scripts
var byfjb = "<br>por<br>Fagner JB.<br><br><b>EM BREVE</b>";
for(i=0;i<$('a.roteiros').length;i++){
var nome = $('a.roteiros:eq('+i+')').attr("title")	
$('a.roteiros:eq('+i+')').html( nome + byfjb );
}
//-----------------------------------------------------------------------galeria
$('a.livro').fancybox({'cyclic':true,'showNavArrows':false,'titleShow':false,'overlayColor':'#000'});
$('a.preview').fancybox({'width': '80%','height':'90%','autoDimensions':false,'scrolling':'no','titleShow':false,'overlayColor':'#000'});

//social
$('.icones a').mouseenter(function(){
	$('.alerta').html('<p>Perfil no ' + $('.icones a:eq(' + $('.icones a').index(this) + ')').attr("title") + '</p>');
	$('.alerta').show();
}).mouseleave(function(){
	$('.alerta').hide();
})

//busca
$("#searchform").submit(function(e){
	e.preventDefault();
	lookup(this.text.value);
});

$("#searchform input").blur(function(){
	$('#suggestions').fadeOut();
	$("#searchform").fadeTo(400,0.6);
	$('.icones').fadeTo(400,1);
	$('.profile').fadeTo(400,1);
}).focus(function(){
	$('#suggestions').fadeIn();
	$("#searchform").fadeTo(400,1);
	$('.icones').fadeTo(400,0.4);
	$('.profile').fadeTo(400,0.4);
});

});
//---------------------------------------------------------------------------------------- fim on load

function putlink(){
	$('.alivro').fancybox({'cyclic':true,'showNavArrows':false,'titleShow':false,'overlayColor':'#000'});
}

/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/
function lookup(inputString) {
	if(inputString.length == 0) {
		$('#suggestions').fadeOut();
	} else {
		$.post("js/rpc.php", {queryString:""+inputString+""}, function(data) {
			$('#suggestions').fadeIn();
			$('#suggestions').html(data);
			putlink();
		});
	}
}
