(function($) {
    
$(window).load(function() {
    $('#slider').nivoSlider({
		effect:'fade',
		slices:10,
		animSpeed:700,
		pauseTime:4000,
		directionNav:true, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true //1,2,3...
	});
    
    equalHeight($("#middle>div"));
    

}); 
    
$(document).ready(function(){
    var Logger = new function() {
        this.log = function(str) {
            try {
                console.log(str);
            } catch(e) {
            // do nothing
            }
        };
    };
    
    Cufon.replace('#menu a ', {hover:true});
    Cufon.replace('#col-alpha h2');
    Cufon.replace('#col-gamma h2');
    Cufon.replace('.menu2 a', {hover:true});    

	var active_rel = $('#menu li.active').children("a").attr('rel');
	//var active_rel_page = $('#col-gamma').attr('rel');
	var active_rel_page = $('#col-gamma').attr('title');
	
	$('#col-beta ul:not([id='+active_rel+'])').hide();
    
    current_url = window.location.href;
    $("#col-beta").find("a[href='"+current_url+"']").each(function(){
        $(this).addClass('active');
        var parent = $(this).parents("ul:first");
        parent.show();
        $("#menu li a[rel='"+parent.attr("id")+"']").addClass("active");
    });
    $("#menu li.active").children("a").addClass("active");
    
    $("#menu li a").each(function() {
        var position = $(this).position();
        var child = $(this).attr("rel")
        Logger.log(position);
        //Logger.log();
        if(child != "") {
            var selector = "#col-beta #"+child;
            $(selector).css({
                top: position.top,
                marginTop: 0});
        }
    });
    
	$("#menu li a").mouseover(function(){
			$(this).addClass('hover');
			$('#col-beta ul').hide();
			if($(this).attr('rel')) {
				$("#col-beta ul[id="+$(this).attr('rel')+"]").show();
			}
		}).mouseout(function(){
			$(this).removeClass('hover');
		}
	);
    $("#col-beta").add("#menu").mouseenter(function(){
        clearTimeout($("#col-beta").data('timeoutId'));
    }).mouseleave(function(){
        var timeoutId = setTimeout(function() {
            $('#col-beta ul').hide();
            $("#col-beta a.active").parents("ul:first").show();   
        }, 250);
        $("#col-beta").data('timeoutId', timeoutId); //set the timeoutId, allowing us to clear this trigger if the mouse comes back over
    });

    
    $("#menu li:not(.allow-click) a").click(function(){return false;});
    $(".post:last").css({border: "none"});
	
    

});

function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
    
})(jQuery)
