
/*Image fade plugin*/

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1500, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 4000 );
});


/*Cookies plugin*/



jQuery.cookie = function(name, value, options) {

    if (typeof value != 'undefined') { // name and value given, set cookie

        options = options || {};

        if (value === null) {

            value = '';

            options.expires = -1;

        }

        var expires = '';

        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {

            var date;

            if (typeof options.expires == 'number') {

                date = new Date();

                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));

            } else {

                date = options.expires;

            }

            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE

        }

        // CAUTION: Needed to parenthesize options.path and options.domain

        // in the following expressions, otherwise they evaluate to undefined

        // in the packed version for some reason...

        var path = options.path ? '; path=' + (options.path) : '';

        var domain = options.domain ? '; domain=' + (options.domain) : '';

        var secure = options.secure ? '; secure' : '';

        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');

    } else { // only name given, get cookie

        var cookieValue = null;

        if (document.cookie && document.cookie != '') {

            var cookies = document.cookie.split(';');

            for (var i = 0; i < cookies.length; i++) {

                var cookie = jQuery.trim(cookies[i]);

                // Does this cookie string begin with the name we want?

                if (cookie.substring(0, name.length + 1) == (name + '=')) {

                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));

                    break;

                }

            }

        }

        return cookieValue;

    }

};



/*Iterate over the cookies and create an associative array with all the cookies name and values*/

function getAllCookies() {



    var cookies = { };



    if (document.cookie && document.cookie != '') {

        var split = document.cookie.split(';');

        for (var i = 0; i < split.length; i++) {

            var name_value = split[i].split("=");

            name_value[0] = name_value[0].replace(/^ /, '');

            cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);

        }

    }



   return cookies;

   

}

/*Delete all the cookies starting from an associative array containing all the names of the cookies*/

function deleteAllCookies(){

	

		var cookies = getAllCookies();

		

		for(var name in cookies) {

		$.cookie(cookies[name], null);

		}

}







/*News rotation*/



function headline_rotate() {

    

   current_headline = (old_headline + 1) % headline_count;

   

    $('#scrollup').height($("div.headline:eq(" + current_headline + ")").height()+10);

   $("div.headline:eq(" + old_headline + ")").animate({top: -203},"slow", function() {

     $(this).css('top','208px');

   });

   $("div.headline:eq(" + current_headline + ")").show().animate({top: 5},"slow");  

   old_headline = current_headline;

 }


