//slideshow functionality
function slideSwitch(switchSpeed) {
    var $active = $('#slideshow A.active');

    if ($active.length == 0) $active = $('#slideshow A:last');

    var $next = $active.next('A').length ? $active.next('A')
        : $('#slideshow A:first');

    $active.addClass('last-active');
    $next.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, switchSpeed, function() {
            $active.removeClass('active last-active');
        });
}

//tooltip news functionality
this.tooltip = function() {
    xOffset = 0;
    yOffset = 20;
    $("a.tooltip").hover(function(e) {
        this.t = this.title;
        this.title = "";
        var nws = this.t.split('|');
        $("body").append("<div id='newstip'><h4>" + nws[0] + "</h4><div style='padding:2px'>" + nws[1] + "</div></div>");
        $("#newstip")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px")
			.css("z-index", "1001")
			.fadeIn("fast");
    },
	function() {
	    this.title = this.t;
	    $("#newstip").remove();
	});
    $("a.tooltip").mousemove(function(e) {
        $("#newstip")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px");
    });
};

$(document).ready(function() {
    setInterval("slideSwitch(1000)", 3000);
    tooltip();
    var li = $('#nav li');
    li.mouseover(function () {
        $(this).addClass('hover');
    });
    li.mouseout(function () {
        $(this).removeClass('hover');
    });
});

//clock functionality
/*
* jQuery jclock - Clock plugin - v 2.3.0
* http://plugins.jquery.com/project/jclock
*
* Copyright (c) 2007-2009 Doug Sparling <http://www.dougsparling.com>
* Licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*/
(function($) {
    $.fn.jclock = function(options) {
        // options
        var opts = $.extend({}, $.fn.jclock.defaults, options);

        return this.each(function() {
            $this = $(this);
            $this.timerID = null;
            $this.running = false;

            // Record keeping for seeded clock
            $this.increment = 0;
            $this.lastCalled = new Date().getTime();

            var o = $.meta ? $.extend({}, opts, $this.data()) : opts;

            $this.seedTime = o.seedTime;
            $this.timeout = o.timeout;
            $this.language = o.language;
            $this.format = ($this.language == 'NL') ? "%a %d-%m-%Y | %H:%M:%S" : "%a %m/%d/%Y | %H:%M:%S"            
            
            // %a
            $this.daysAbbrvNames = new Array(7);
            $this.daysAbbrvNames[0] = ($this.language == 'NL') ? "zo": "Sun";
            $this.daysAbbrvNames[1] = ($this.language == 'NL') ? "ma": "Mon";
            $this.daysAbbrvNames[2] = ($this.language == 'NL') ? "di": "Tue";
            $this.daysAbbrvNames[3] = ($this.language == 'NL') ? "wo": "Wed";
            $this.daysAbbrvNames[4] = ($this.language == 'NL') ? "do": "Thu";
            $this.daysAbbrvNames[5] = ($this.language == 'NL') ? "vr": "Fri";
            $this.daysAbbrvNames[6] = ($this.language == 'NL') ? "za": "Sat";
            $.fn.jclock.startClock($this);
        });
    };

    $.fn.jclock.startClock = function(el) {
        $.fn.jclock.stopClock(el);
        $.fn.jclock.displayTime(el);
    }

    $.fn.jclock.stopClock = function(el) {
        if (el.running) {
            clearTimeout(el.timerID);
        }
        el.running = false;
    }

    $.fn.jclock.displayTime = function(el) {
        var time = $.fn.jclock.getTime(el);
        el.html(time);
        el.timerID = setTimeout(function() { $.fn.jclock.displayTime(el) }, el.timeout);
    }

    $.fn.jclock.getTime = function(el) {
        if (typeof (el.seedTime) == 'undefined') {
            // Seed time not being used, use current time
            var now = new Date();
        } else {
            // Otherwise, use seed time with increment
            el.increment += new Date().getTime() - el.lastCalled;
            var now = new Date(el.seedTime + el.increment);
            el.lastCalled = new Date().getTime();
        }

        var timeNow = "";
        var i = 0;
        var index = 0;
        while ((index = el.format.indexOf("%", i)) != -1) {
            timeNow += el.format.substring(i, index);
            index++;

            var property = $.fn.jclock.getProperty(now, el, el.format.charAt(index));
            index++;

            timeNow += property;
            i = index
        }

        timeNow += el.format.substring(i);
        return timeNow;
    };

    $.fn.jclock.getProperty = function(dateObject, el, property) {
        switch (property) {
            case "a": // abbrv day names
                return (el.daysAbbrvNames[dateObject.getDay()]);
            case "d": // day 01-31
                return ((dateObject.getDate() < 10) ? "0" : "") + dateObject.getDate();
            case "H": // hour as a decimal number using a 24-hour clock (range 00 to 23)
                return ((dateObject.getHours() < 10) ? "0" : "") + dateObject.getHours();
            case "m": // month number
                return (((dateObject.getMonth() + 1) < 10) ? "0" : "") + (dateObject.getMonth() + 1);
            case "M": // minute as a decimal number
                return ((dateObject.getMinutes() < 10) ? "0" : "") + dateObject.getMinutes();
            case "S": // second as a decimal number
                return ((dateObject.getSeconds() < 10) ? "0" : "") + dateObject.getSeconds();
            case "Y": // full year
                return (dateObject.getFullYear());
            case "%":
                return "%";
        }
    }

    // plugin defaults (24-hour)
    $.fn.jclock.defaults = {
        format: '%H:%M:%S',
        seedTime: undefined,
        language: 'NL',
        timeout: 1000 // 1000 = one second, 60000 = one minute
    };

})(jQuery);
