
function initMenu(){

	$(function () {
		$('.dropdown').each(function () {
			$(this).parent().eq(0).hover(function () {
				$('.dropdown:eq(0)', this).show();
			}, function () {
				$('.dropdown:eq(0)', this).hide();
			});
		});
	});

}

function initSlider(){
	
	$('#slider').nivoSlider({
		effect: 			'boxRain',
		directionNav:		false,
		captionOpacity:		0.7,
		controlNav:			false
	});
	 
}

function _trocaFoto( img ){
	
	if( $("#img-projeto > img").attr('src') == img )
		return;
	
	$("#img-projeto > img").fadeOut('slow',function(){
		$("#img-projeto > img").attr('src',img);
	});
	
	$("#img-projeto > img").load( function(){
		$("#img-projeto > img").fadeIn('slow');
	});
	
	
	
}

function initProjeto(){

	$("#grid-thumbs").find("li:last").addClass('selected');

	// por addr (sem ajax)
    $.address.change(function(event) {
    
        var n = event.value.replace('/','');
        var img = $("a[href=#"+n+"]").attr('rel');
    	if( img != "" && img != undefined ){
    		$("#grid-thumbs > li").removeClass('selected');
    		$("a[href=#"+n+"]").parent().addClass('selected');
	    	//$("#img-projeto > img").attr('src',img);
	    	_trocaFoto( img );
	    }
        
    });
    
    // por ajax (via class)
    $(".ajaxClique").click(function(){
    	
    	var img = $(this).attr('rel');
    	if( img != "" && img != undefined ){
    		$("#grid-thumbs > li").removeClass('selected');
    		$(this).parent().addClass('selected');
	    	//$("#img-projeto > img").attr('src',img);
	    	_trocaFoto( img );
	    }

    	
    });
    
    $("#btnPremiado").mouseenter(function(e){
    	$("#txtPremiado").fadeIn('fast');
    });
    
    $("#btnPremiado").mouseleave(function(e){
    	$("#txtPremiado").fadeOut('fast');
    });
    
}

function initHome(){

	// Projetos
	// Torna botoes em ajax openers
	$("#projetos-home > li > a").click(function() {
		$.fancybox({
				'scrolling'		: 'no',
				'padding'		: 20,
				'margin'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'fade',
				'transitionOut'	: 'fade',
				'overlayColor'	: '#ccc',
				'width'			: 900,
				'height'		: 550,
				'href'			: this.href.replace( "/projeto/", "/projeto-ajax/" ),
				'type'			: 'iframe'
			}); 
	
		return false;
	});
	
	// Cadastro de e-mail
	$("#cadastro").click(function(e){
	
		$("#cadastro-div > p").fadeOut().remove();
		$("#cadastro-div").append('<p class="wait">Aguarde...</p>');
	
		$.get( _url + "index/email/addr/"+$("#email").val(),function(data){

			$("#cadastro-div > p").remove();
			if( data.tipo == 1 ){
				$("#cadastro-div").append('<p class="error">'+data.msg+'</p>');
			}else{
				$("#cadastro-div").append('<p class="ok">'+data.msg+'</p>');
			}
			
		},"json");
		
	});
	
}

function initPortfolio(){

	// Torna botoes em ajax openers
	$(".btnProjetos").click(function() {
		$.fancybox({
				'scrolling'		: 'no',
				'padding'		: 20,
				'margin'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'fade',
				'transitionOut'	: 'fade',
				'overlayColor'	: '#ccc',
				'width'			: 900,
				'height'		: 550,
				'href'			: this.href.replace( "/projeto/", "/projeto-ajax/" ),
				'type'			: 'iframe'
			}); 
	
		return false;
	});

}

function initBoletim(){
	
	// Torna botoes em ajax openers
	$(".btnBoletim").click(function() {
		$.fancybox({
				'scrolling'		: 'auto',
				'padding'		: 20,
				'margin'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'fade',
				'transitionOut'	: 'fade',
				'overlayColor'	: '#ccc',
				'width'			: 750,
				'height'		: 450,
				'href'			: this.href,//this.href.replace( "/projeto/", "/projeto-ajax/" ),
				'type'			: 'iframe'
			}); 
	
		return false;
	});
	
}

function init(){
	
	// Slider
	initSlider();
	
	// Menu (subs)
	initMenu();
	
	// InitProjeto
	initProjeto();
	
	// home
	initHome();
	
	// Portfolio
	initPortfolio();
	
	// Boletim
	initBoletim();
	
}

$(document).ready( function(){
    init();
});

var _url = 'http://www.marcelmonacelli.com.br/';
