var speed = 2000;
$(window).load(function() {
    var visible = 1;    

    $('#slider').nivoSlider({
        animSpeed: 500,
        pauseTime: 10000,
        effect: 'fade',
        afterChange: function(){
            var current = ($("#slider").data('nivo:vars').currentSlide+1);
            $.post("getnews",{"slide":current},function(data){
                if (data.indexOf("ERROR") < 0){
                    if (visible == 2) { //second is visible, put text in first & toggle
                        $(".first").hide();
                        $(".first").html(data);
                        $(".first").fadeIn(speed);
                        $(".second").fadeOut(speed);
                        visible = 1;
                    } else { //first is visible, put text in second & toggle
                        $(".second").hide();
                        $(".second").html(data);
                        $(".second").fadeIn(speed);
                        $(".first").fadeOut(speed);
                        visible = 2;
                    }
                }
            });
        }
    });
    
    var current = ($("#slider").data('nivo:vars').currentSlide+1);
    $.post("getnews",{"slide":current},function(data){
        $(".first").html(data);
        $(".first").fadeIn(100);
    });
    
});

function enableSUNDAYS(date) {
    var day = date.getDay();
    return [(day == 0), ''];
}

function disableSUNDAYS(date) {
    var day = date.getDay();
    return [(day >= 1 && day <= 6), ''];
}

$(document).ready(function() {    

    $(".canopen:not(:first)").slideUp();

    $(".actuallink").hover(function(){
        $(this).removeClass("regularlink");
        $(this).addClass("hoverlink");
    }, function(){
        $(this).removeClass("hoverlink");
        $(this).addClass("regularlink");
    });

    $(".clickable").click(function(){
        $(".canopen").slideUp("slow");
        $(this).next().slideDown("slow");
    });

    $(".window").click(function(){
        $(this).hide();
    });

    $("a").click(function(){
        if($(this).parent().parent().is(".canopen")){
            var url = $(this).attr("href");
            $(".window").hide();
            $("#windowimage").attr("title","Click on the image to close");
            $("#windowimage").attr("src",url);
            $(".window").center();
            $(".window").show("fast");
            return false;
        } else {
            return true;
        }
    });
});

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}
