
jQuery(document).ready(function($){

    //my jQuery
    //Archives
    $('.archive_list .archive_item').mouseover(function(){
        $(this).find('.archive_post_comments a, h2 a').css('color', '#137bbd');
    });

    $('.archive_list .archive_item').mouseout(function(){
        $(this).find('.archive_post_comments a').css('color', '#333333');
    });
	
	    $('.archive_list .archive_item').mouseout(function(){
        $(this).find('h2 a').css('color', '#d9d9d9');
    });
	
    //Sidebar
    $('.sidebar_head').toggle(function(){
        $(this).children('h2').removeClass("minus_button");
        $(this).children('h2').addClass("plus_button");
    }, function () {
        $(this).children('h2').removeClass("plus_button");
        $(this).children('h2').addClass("minus_button");
    });

    $('.sidebar_head').click(function()
    {
        $(this).next('#sidebar div').slideToggle("slow");
    });
	
	//Opacity Fades
	$('.button, .wp-pagenavi span, #social_links img').hover(function() {
		$(this).stop().fadeTo(250, 1);
	}, function() {
		$(this).stop().fadeTo(250, .80);
	});
	
	//Contact Form
	$('form#contactForm label').hide();
	
	  $('form#contactForm input[type="text"]').focus(function() {
        if (this.value == this.defaultValue)
			this.value = '';
    });
	
	$('form#contactForm input[type="text"]').blur(function() {
        if (this.value == '')
			this.value = (this.defaultValue ? this.defaultValue : '');
	});
	
	$('form#contactForm').submit(function() {
		$('form#contactForm .error').remove();
		var hasError = false;
		$('.requiredfield').each(function() {
			$(this).removeClass('red_border');
			if( jQuery.trim($(this).val()) == '' || jQuery.trim($(this).val()) == $(this).next('label').text() ) {
				var labelText = $(this).next('label').text();
				if(labelText != '')
				{
				$(this).parent().hide().append('<span class="error">'+labelText+' required</span>').fadeIn(500);
				}
				$(this).addClass('red_border');
				hasError = true;
			} else if($(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim($(this).val()))) {
					var labelText = $(this).next('label').text();
					$(this).parent().hide().append('<span class="error">invalid '+labelText+'</span>').fadeIn(500);
					hasError = true;
				}
			}
		});
		if(!hasError) {
			$('form#contactForm .submit_button').fadeOut('normal', function() {
				$(this).parent().append('<img src="/wp-content/themes/Massivo/images/loader.gif" alt="Loading…" height="32" width="32" />');
			});
			var formInput = $(this).serialize();
			$.post($(this).attr('action'),formInput, function(data){
				$('#slide_up').slideUp("fast", function() {
					$(this).before('<div class="thanks"><h2>Obrigado.</h2><p>O seu e-mail foi enviado com sucesso. Obrigado.</p></div>');
				});
			});
		}
		return false;
	});
	
	 //TopNavMenu
	$("ul.nav li ul").hide();
	
    $("ul.nav>li").mouseover(function() {
		var speed = 55 * ($(this).find('ul.sub').children().length);
        $(this).find('ul.sub').stop(true,true).slideDown(speed).show();
    });
	
	$("ul.nav>li").mouseleave(function() {
     	$(this).find('ul.sub').stop(true,true).slideUp(200);
    });
	
    //my jQuery - END

    //Smooth Scrolling
    $('#wrapper').localScroll();

    //FancyBox
    $("#content a[href$=.jpg], #content a[href$=.png], #content a[href$=.gif]").fancybox({
        'overlayOpacity' : '0.50',
        'overlayColor' : '#000'

    });

    //Lazyload
    $("#main_content img").lazyload({
        effect:"fadeIn",
        placeholder: "http://massivo.net/wp-content/themes/Massivo/images/pixel.gif",
        failurelimit : 200
    });

    //NivosSlider
    jQuery(window).load(function() {
        jQuery('#slider').nivoSlider({
            effect:'random',
            slices:10,
            animSpeed:800,
            pauseTime:3500,
            startSlide:0, //Set starting Slide (0 index)
            directionNav:true, //Next and Prev
            directionNavHide:true, //Only show on hover
            controlNav:false, //1,2,3...
            keyboardNav:true, //Use left and right arrows
            pauseOnHover:true, //Stop animation while hovering
            manualAdvance:false, //Force manual transitions
            captionOpacity:0.8 //Universal caption opacity
        });
    });

    //To the Top Plugin
    jQuery.fn.topLink = function(settings) {
        settings = jQuery.extend({
            min: 1,
            fadeSpeed: 200
        }, settings);
        return this.each(function() {
            var el = $(this);
            el.hide();

            $(window).scroll(function() {
                if($(window).scrollTop() >= settings.min)
                {
                    el.fadeIn(settings.fadeSpeed);
                }
                else
                {
                    el.fadeOut(settings.fadeSpeed);
                }
            });
        });
    };

    //set the link
    $('#top-link').topLink({
        min: 400,
        fadeSpeed: 500
    });

    //Fading Colors
    jQuery.fn.dwFadingLinks = function(settings) {
        settings = jQuery.extend({
            color: '#5f707d',
            duration: 500
        }, settings);
        return this.each(function() {
            var original = $(this).css('color');
            $(this).mouseover(function() {
                $(this).animate({
                    color: settings.color
                },settings.duration);
            });
            $(this).mouseout(function() {
                $(this).animate({
                    color: original
                },settings.duration);
            });
        });
    };

    /* Fading Links Usage */
    $('.sidebar_popular a').dwFadingLinks({
        color: '#5f707d',
        duration: 350
    });

    $('ul.topnav li a').dwFadingLinks({
        color: '#a0c7f3',
        duration: 350
    });

    $('#updates_wrapper a').dwFadingLinks({
        color: '#FFF',
        duration: 500
    });

    //smoothscroll
    $('#top-link').click(function(e) {
        e.preventDefault();
        $.scrollTo(0,750);
    }); //end - To the Top

  //Tooltip
    $('#main_content *, #sidebar *, #topTitle a').tipTip();({});

}); //end



