$(document).ready(function(){
    Cufon.replace('.cufon',{hover:true});
    
    $('.date').mask("99/99/9999");
    $('.cpf').mask("999.999.999-99");
    $('.rg').mask("99.999.99");
    $('.cep').mask("99999-999");
    $('.phone').mask("(99) 9999-9999");

    clearInputs();

    $("a[rel=aside-gallery]").fancybox({'transitionIn':'elastic','transitionOut':'elastic','easingIn':'easeOutBack','easingOut':'easeInBack','titleShow': false});
    $('a[rel=external]').attr('target','_blank');
	moveTo();
/*	
	$('.bt-services').click(function(){
	    showServices();
	})
    $('.bt-hide-services').click(function(){
        showServices();
    })
*/  
	$('.bt-team').click(function(){
	    showTeam();
	})
    $('.bt-hide-team').click(function(){
        showTeam();
    })
})

function moveTo(){
	var i = 0;
	var controllers = $('.case-list a');
	var cases = $('.case-frame li');
	var cases_frame = $('.case');
	$('.case-list li').each(function(){
		$(controllers[i]).addClass('case'+i);
		$(cases[i]).attr('id','case'+i);
		$(cases_frame[i]).attr('id','ca'+i);
		i++;
	})

	$('.case-list a').click(function(){
		var aux = $(this).attr('class');
		var parent = $(this).parent().parent().parent().attr('id');
		if($(this).parent().hasClass('current') == false){
		    $('#'+parent+' .case-frame ul li').fadeOut();
		    $('#'+parent+' .case-frame ul #'+aux).fadeIn();
            // $('#'+parent+' .case-frame ul li').removeClass('visible');
            // $('#'+parent+' .case-frame ul #'+aux).addClass('visible');
            // $('#'+parent+' .case-frame ul').scrollTo($('#'+aux),500);
    		$('#'+parent+' .case-list li').removeClass('current');
    		$(this).parent().addClass('current');
		}
	})
	
    var params = {
		menu : 'false',quality : "best",wmode: 'transparent'
	};
    swfobject.embedSWF('dot/../swf/preloader.swf', 'flash', '880', '300', '9.0.45','',{},params);

}

function showServices(){
    if($('#services').hasClass('open') == true){
       $('#services').fadeOut();
        $('#hd').animate({height:'140px'},500,function(){
           $('#services').removeClass('open');
        });
    }else{
        $('#hd').animate({height:'335px'},500,function(){
			$('#team').fadeOut().removeClass('open');
			$('#services').fadeIn().addClass('open');
        });
    }
}

function showTeam(){
    if($('#team').hasClass('open') == true){
       $('#team').fadeOut();
        $('#hd').animate({height:'140px'},500,function(){
           $('#team').removeClass('open');
        });
    }else{
        $('#hd').animate({height:'335px'},500,function(){
			$('#services').fadeOut().removeClass('open');
			$('#team').fadeIn().addClass('open');
        });
    }

}

function clearInputs(){
    $('.section-home #name').focus(function(){
        $('.section-home #name').val('');
    })

    $('.section-home #name').blur(function(){
        if($('.section-home #name').val() == ''){
            $('.section-home #name').val('Informe seu nome');
        }
    })
    
    $('.section-home #email').focus(function(){
        $('.section-home #email').val('');
    })
    
    $('.section-home #email').blur(function(){
        if($('.section-home #email').val() == ''){
            $('.section-home #email').val('Informe seu e-mail');
        }
    })
}
