// Fade syntax
$(function() {
	$('.wp_syntax').animate({"opacity": .1 },{duration:2000});

	$('.wp_syntax').hover(function() {
		$(this).stop().animate({ "opacity": 1 });
			}, function() {
		$(this).stop().animate({ "opacity": .1 });
	});
});

// Fade post images
$(function() {
	$('.single-post img').animate({"opacity": .1 },{duration:2000});

	$('.single-post img').hover(function() {
		$(this).stop().animate({ "opacity": 1 });
			}, function() {
		$(this).stop().animate({ "opacity": .1 });
	});
});

// Fade search button
$(function() {
	$('#sidebar-search-button').animate({"opacity": .2 },{duration:2000});

	$('#sidebar-search-button').hover(function() {
		$(this).stop().animate({ "opacity": 1 });
			}, function() {
		$(this).stop().animate({ "opacity": .2 });
	});
});

// Random Post AJAX
/* $(function() {
	$("#randompost").load("/blog.pdwd.net/random-post/");
	
	$("#another").click(function(){
	   $("#randompost")
	            .text("")
	            .load("/blog.pdwd.net/random-post/?cachebuster=" + Math.floor(Math.random()*10001));
	   return false;
	});		
}); */

// If sidebar is taller than window, loose fixed property.
$(document).ready(function() {

    function staticNav() {
        var sidenavHeight = $("#nav").height(); //Get height of sidenav
        var winHeight = $(window).height(); //Get height of viewport
        var browserIE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false; //Check for IE6

        if (browserIE6) { //if IE6...
            $("#nav").css({'position' : 'absolute'});  //reset the sidenav to be absolute
        } else { //if not IE6...
            $("#nav").css({'position' : 'fixed'}); //reset the sidenav to be fixed
        }

        if (sidenavHeight > winHeight) { //If sidenav is taller than viewport...
            $("#nav").css({'position' : 'static'}); //switch the fixed positioning to static. Say good bye to sticky nav!
        }
    }

    staticNav(); //Execute function on load

    $(window).resize(function () { //Each time the viewport is adjusted/resized, execute the function
        staticNav();
    });

});

// Equal more-posts div height
$(function() {
	var maxHeight = 0;

	$(".more-posts").each(function(){
	   if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
	});
	
	$(".more-posts").height(maxHeight);	
});