
Cufon.replace('#mainMenu a, h1, h2', { hover: true })

$(document).ready(function () {
    carousel();
    footer();
    banner();

    //news title
    if ($('#body_13 .newsModItem').length == 0) {
        $('#body_13 #left h2').hide()
    }

});

$(window).resize(function () {
    footer();
});

function banner() {
    if ($('#banner').length > 0) {
        $('#bclose').click(function () {
            $('#banner').fadeOut()
        })
    }
}

function footer() {
    var windowHeight = $(window).height();
    var containerHeight = $('#container').height();
    var footerHeight = $('#footer').height();
    var totalHeight = windowHeight - (containerHeight + footerHeight) - 40;  //footer padding
    if (totalHeight >= 0) {
        $('#footer').css('top', totalHeight).fadeIn('last');
    }
    else {
        $('#footer').css('top', 0).fadeIn('last');
    }
}

function carousel() {
    var cycleInt;
    var el = $('#slideshow div').size();
   
    if (el > 1) {
    
        //pager
        for (i = 1; i < el+1; i++) {
            $('#pager').append("<a href='#' title='" + i + "'>" + i + "</a>");
        }
    
        //custom click
        $('#pager a').click(function() {
            clearInterval(cycleInt);
            if ($(this).hasClass('active')) {return }
            $('#pager a').removeClass('active');
            $(this).addClass('active');
            var aindex = $('#pager a').index($(this));
            var $manual = $('#slideshow div').eq(aindex);
            $manual.css('z-index', 1000);
            $('#slideshow div.active').stop().animate({
                    width: 'hide'
                }, 500, function() {
                    $(this)
                        .css('z-index', 999)
                        .width('100%')
                        .show()
                        .removeClass('active');
                    $manual.addClass('active').css('z-index', 1001);
                })
        })

        //start cycle
        $("#slideshow div:first").addClass('active');
        $("#pager a:first").addClass('active');
        cycleInt = setInterval("cycle()", 4500);

    }

    // show/hide image
    $('#slideshow').toggle(
        function() {
            $('#mainMenu').stop().fadeOut(200, function() {
                $('#opacity').stop().animate({
                    width: 'hide'
                }, 200)
            })
        },
        function() {
            $('#opacity').stop().animate({
                width: 'show'
            }, 200, function() {
                $('#mainMenu').stop().fadeIn(400)
            }
            )
        }
    )
    
}

//slide effect
function cycle() {
    var $obj = $("#slideshow div.active");
    var $next = $obj.next();
    var $anext = $('#pager a').eq($('#slideshow div').index($next));
    if ($next.length == 0) {
        $next = $("#slideshow div:first");
        $anext = $('#pager a:first'); 
    }
    $next.css('z-index', 1000);
    $obj.stop().animate({
            width: 'hide'
        }, 500, function() {
            $(this)
                .css('z-index', 999)
                .width('100%')
                .show()
                .removeClass('active');
            $next.addClass('active').css('z-index', 1001);
            $('#pager a').removeClass('active');            
            $anext.addClass('active');
        });
}

