
$(document).ready(function () {
    carousel();
    nav();
    fonts();
});

function fonts() {
    Cufon.replace('h1, h2, h3, #mainMenu a, .newsModTitle', { hover: true })
    Cufon.CSS.ready(function () {
        footer();
        $('#mainMenu').show();
    })
}

$(window).resize(function () {
    footer();
});

function footer() {
    var windowHeight = $(window).height();
    var containerHeight = $('#content').height();
    var footerHeight = $('#footer').height();
    var totalHeight = windowHeight - (containerHeight + footerHeight) - 60;  //footer padding
    if (totalHeight >= 0) {
        $('#footer').css('top', totalHeight).show();
    }
    else {
        $('#footer').css('top', 0).show();
    }
}

function nav() {
    $('#mainMenu').menuTree({
        animation: true,
        handler: 'toggle',
        anchor: 'a[href="#"]',
        speed: 'fast',
        trace: false
    });
    if ($('#mainMenu li ul.collapsed li.subMenuSel').length == 1) {
        var el = $('#mainMenu li ul.collapsed li.subMenuSel');
        $(el).parent().removeClass('collapsed').css('display', 'block');
        $(el).parent().prev().addClass('expanded');
    }
}

function carousel() {

    //single image
    if ($('#cycle img.sigleImg').length > 0) {
        $('#cycle img.sigleImg').show().css('display', 'block')//.css('cursor', 'default');
        $('#nxtCycle, #prvCycle').hide();
        //return
    }

    $('#cycle').cycle({
        fx: 'fade',
        speed: 500,
        timeout: 4500,
        next: '#prv',
        prev: '#nxt',
        after: onAfter,
        before: onBefore
    });

    $("#prv, #nxt, #cycle img").click(function () {
        $('#cycle').cycle('pause');
    })

    function onAfter(curr, next, opts) {
        var cpt = $(this).attr('cpt');
        if (cpt.length > 0) {
            $('#capt').fadeIn('fast', function () {
                if (jQuery.browser.msie) { this.style.removeAttribute("filter") }
            });
            $('#capt').html(cpt);
        }

    }

    function onBefore(curr, next, opts) {
        $('#capt').fadeOut('fast', function () {
            $(this).empty();
        });
    }

}

