$.fn.blindToggle = function(height, speed, easing, callback) {
    return this.animate({ 'marginTop': parseInt(this.css('marginTop')) < 0 ? 0 : -height }, speed, easing, callback);
};

$.fn.makeTicker = function(interval) {
    var current = 0;
    var children = $(this).children();
    var count = children.hide().size();

    children.eq(current).show();

    setInterval(function() {
        children.eq(current).fadeOut("slow", function() {
            children.hide();
            current = ++current % count;
            children.eq(current).fadeIn("slow");
        });
    }, interval);
}

$.fn.addDefaultText = function() {
    $(this).focus(function() {
        if ($(this).val() == $(this).attr("title")) {
            $(this).removeClass("default");
            $(this).val("");
        }
    });

    $(this).blur(function() {
        if ($(this).val() == "") {
            $(this).addClass("default");
            $(this).val($(this).attr("title"));
        }
    });

    $(this).blur();
}

$(document).ready(function() {
    var height = 40; // Partial - 44, Full - 52
    var loginPanel = $('#login-panel');

    loginPanel.css("margin-top", -height + "px");

    $("#login").click(function() {
        loginPanel.blindToggle(height, "fast");
    });

    $("ul#ticker").makeTicker(7000);

    $(".default").addDefaultText();

    $("#timeline .scroll").css("overflow", "hidden");

    $("#timeline ul.years").localScroll({
        target: ".scroll",
        axis: "x"
    });

    $('span.password').qtip({
        style: {
            border: {
                width: 4,
                radius: 4
            },
            padding: 10,
            textAlign: 'center',
            tip: true, // Give it a speech bubble tip with automatic corner detection
            name: 'red' // Style it according to the preset 'cream' style
        },
        position: {
            corner: {
                target: 'bottomMiddle',
                tooltip: 'topMiddle'
            }
        }
    });

    $(".content").hide();
    $("#content1").show();

    // When a link is clicked  
    $("a.tab").click(function() {
        // switch all tabs off  
        $(".active").removeClass("active");

        // switch this tab on  
        $(this).addClass("active");

        // slide all elements with the class 'content' up  
        $(".content").fadeOut();

        // Now figure out what the 'title' attribute value is and find the element with that id.  Then slide that down.  
        var content_show = $(this).attr("title");
        $("#" + content_show).fadeIn();
    });
});
