$(document).ready(function() {

    sildeshow();

    CallCurvycorners();

    $("#chunky a span").vAlign();

});



// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function sildeshow() {

    $('body.home .verso #slidewrapper').after('<div id="nav" class="nav" >').cycle({
        fx: 'fade',
        speed: 3000,
        timeout: 7000,
        next: '.bock-c',
        pager: '#nav',
        before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
            $('ol.toc li.selected').removeClass("selected");
            var index = parseInt(options.currSlide) + 1;
            var indexClass = "index" + index;

            $('ol.toc li.' + indexClass).addClass("selected");
        }
    });
    $('#nav').hide();
    $('.slink').click(function() {
        $('#nav a:nth-child(' + $(this).html() + ')').trigger('click');
    });

}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function CallCurvycorners() {

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    var curvyCornersVerbose = true;

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    var oSettings1 = {
        tl: { radius: 0 },
        tr: { radius: 0 },
        bl: { radius: 10 },
        br: { radius: 10 },
        antiAlias: true
    }

    //curvyCorners(oSettings1, "#content");
    //curvyCorners(oSettings1, "#footer");

    // curvyCorners messes up our double borded at the base so we have a wee
    // cleanup and put right what once went wrong
    $("#footer").css('position', 'relative'); // TODO - chain these
    $("#footer").css('top', '-1px'); // TODO - chain these
    $("#footer ul").css('position', 'relative'); // TODO - chain these
    $("#footer ul").css('top', '1px'); // TODO - chain these

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    var oSettings3 = {
        tl: { radius: 10 },
        tr: { radius: 0 },
        bl: { radius: 0 },
        br: { radius: 0 },
        antiAlias: true
    }

    curvyCorners(oSettings3, "#larch");

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    var oSettings4 = {
        tl: { radius: 0 },
        tr: { radius: 10 },
        bl: { radius: 0 },
        br: { radius: 0 },
        antiAlias: true
    }

    curvyCorners(oSettings4, "#rarch");

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    var oSettings5 = {
        tl: { radius: 10 },
        tr: { radius: 10 },
        bl: { radius: 10 },
        br: { radius: 10 },
        antiAlias: true
    }

    if (document.getElementById("#block-b"))
        curvyCorners(oSettings5, "#block-b");

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    var oSettings6 = {
        tl: { radius: 10 },
        tr: { radius: 10 },
        bl: { radius: 0 },
        br: { radius: 0 },
        antiAlias: true
    }

    if (document.getElementById("#block-b h2"))
        curvyCorners(oSettings6, "#block-b h2");


    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    var oSettings7 = {
        tl: { radius: 0 },
        tr: { radius: 0 },
        bl: { radius: 9 },
        br: { radius: 9 },
        antiAlias: true
    }

    if (document.getElementById("#articles"))
        curvyCorners(oSettings7, "#articles");
    if (document.getElementById("#articles dt"))
        curvyCorners(oSettings5, "#articles dt");

    // curvyCorners messes up our double borded at the base so we have a wee
    // cleanup and put right what once went wrong
    $("#articles").css('position', 'relative'); // TODO - chain these
    $("#articles").css('top', '1px'); // TODO - chain these

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    var oSettings8 = {
        tl: { radius: 3 },
        tr: { radius: 3 },
        bl: { radius: 3 },
        br: { radius: 3 },
        antiAlias: true
    }

    if ($('.chunky li').length > 0)
        curvyCorners(oSettings8, ".chunky li");


    var oSettings9 = {
        tl: { radius: 8 },
        tr: { radius: 8 },
        bl: { radius: 8 },
        br: { radius: 8 },
        antiAlias: true
    }

    if ($('div.date').length > 0)
        curvyCorners(oSettings9, "div.date");
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

$.fn.vAlign = function() {
    return this.each(function(i) {
        var ah = $(this).height();
        var ph = $(this).parent().height();
        var mh = (ph - ah) / 2;
        $(this).css('padding-top', mh);
    });
};

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

var utilities = {
    listHovers: function() {
        $("li.hoverIn").live("mouseout",
            function() {
                $(this).removeClass("hoverIn").addClass("hoverOut");
            });

        $("li.hoverOut").live("mouseover",
            function() {
                $(this).removeClass("hoverOut").addClass("hoverIn");
            });
    } ()
}

