$(document).ready(function() {
    animate();
    $('.newsBody:not(#newsFirst)').css('display', 'none').prev().children().css('background-position', 'top left');
    $('#newsFirst').prev().css('cursor', 'default');
    $('.newsHeader').click(function() {
        var next = $(this).next();
        var state = $(next).css('display');
        if(state == 'none') {
            $('.newsHeader').css('cursor', 'pointer');
            $('.newsHeader').children().css('background-position', 'top left');
            $('.newsBody').slideUp();
            $(this).css('cursor', 'default').next().slideDown();
            $(this).children().css('background-position', 'top right');
        }
    });
});


function animate() {
        
        var display = 4500;
        var transition = 1500;
        
        $('#patroni').pause(display).fadeOut(transition,function() {
            $('#sponsorzy').fadeIn(transition,function() {
                $('#sponsorzy').pause(display).fadeOut(transition,function() {
                    $('#media').fadeIn(transition,function() {
                        $('#media').pause(display).fadeOut(transition,function() {
                            $('#patroni').fadeIn(transition,function() {
                                animate();
                            });
                        });
                    });
                });
            });
        });
    }

function makelink( name, domain, desc, pre, post ) {
    if ( pre != null && pre != "" )
        document.write( pre );
    
    document.write( '<a class="link" href="mailto:' );
    document.write( name + '&#64;' );
    document.write( domain + '">' );
    
    if ( desc != null && desc != "" )
        document.write( desc )
    else
        document.write( name + '&#64;' + domain );
    
    document.write( '</a>' );
    
    if ( post != null && post != "" )
        document.write( post );
}



    // jQuery pause plugin
    (function($) {
        $.fn.extend({
            pause: function(milli,type) {
                milli = milli || 1000;
                type = type || "fx";
                return this.queue(type,function(){
                    var self = this;
                    setTimeout(function(){
                        $(self).dequeue();
                    },milli);
                });
            },
            clearQueue: function(type) {
                return this.each(function(){
                    type = type || "fx";
                    if(this.queue && this.queue[type]) {
                        this.queue[type].length = 0;
                    }
                });
            },
            unpause: $.fn.clearQueue
        });
    })(jQuery);
