﻿$(document).ready(function(){
	$('a[href*=#]').click(function() {
            if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
                var $target = $(this.hash);
                $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
                    if ($target.length) {
                        var targetOffset = $target.offset().top;
                        $('html,body').animate({scrollTop: targetOffset}, 1000);
                    return false;
                    }
            }
        });
		
		$("form.validate").submit(function(){
			$.each($('form .required'), function() {
				if ($(this).val() == '') { $error = 1; }
			});

			if($error > 0){
				$.each($('form .required'), function(){
					if($(this).val() == ''){
						$(this).addClass('error');
						$mensagem = "Atenção! Preencha corretamente os campos em vermelho!"
					}
					else{
						$(this).removeClass('error');
					};
				});
				$error = 0;
				alert($mensagem);
				return false;
			}
			return true;
		});

		$('form .required').bind('focusout keyup', function(){
			if($(this).val() == ''){
				$(this).addClass('error');
			} else {
				$(this).removeClass('error');
			}
		});
		
		$(function(){
			$('div.listFolio > div').hide().filter(":first, .pagination").show();					
			$('div.listFolio .pagination a').click(function(){
				$('div.listFolio > div').hide().filter(this.hash).show();				
				$('div.listFolio .pagination a').removeClass('selected');
				$(this).addClass('selected');				
			});
		});
		
		$("#twitter").getTwitter({
			userName: "jquery",
			numTweets: 3,
			loaderText: "Carregando tweets...",
			slideIn: true,
			showHeading: false,
			headingText: "Latest Tweets",
			showProfileLink: false
		});

		$('.showPortfolio ul').cycle({
			fx:      'fade',
			speed:   700,
			timeout: 5000,
			pause:   1,
			pager:   '#pagination',
			pagerEvent: 'click',
			pauseOnPagerHover: true
		});
		
		$('.services p').hide();
		$('.services img').click(function(){
			$(this).next().slideToggle(900).end();
		});
		
		$('#navInformation').slideDown('fast');
		setTimeout(function() {
			$("#navInformation").slideUp('fast');
		}, 4000);
		
  });
