
    // generic methods
    $.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };


    function getRand (n,m) {
        return (Math.floor((m-n)*Math.random() + n) + "px");
    };


    // message object
    function MessageObject(mid) {

        // variables
        this.id = mid;
        this.showing = false;

        // methods
        this.init = initMsg;
        this.show = showMsg;

        return true;
    }


    // object methods
    function initMsg() {

        var thisMsg = $("#message-text"+this.id);
        var thisDate = $("#message-date"+this.id);

        var thisWidth = $(window).width();
        var thisHeight = $(window).height();

        $.getJSON("ajax.php?"+Math.random(), function(data){
        
            thisMsg.text(data.msg);
            thisDate.text(data.date);
        });

        $("#message"+this.id).css({
            "top": getRand(32,thisHeight-300),
            "left": getRand(32,thisWidth-500)
            });
        return true;
    }


    function showMsg() {

        this.showing = true;
        $("#message"+this.id).animate({ color: "#f99" }, getTimeout(), "swing")
                             .wait()
                             .animate({ color: "#000" }, 2000, "swing");
        this.showing = false;

        return true;
    }


    // runner method
    function runIt(init) {

        
        this.id = this.id || init;

        if (this.id == 3) {
            this.id = 1;
        } else {
            this.id += 1;
        }
        
        var msg = new MessageObject(this.id);

        msg.init();
        msg.show();

        return true;
    }


    function getTimeout() {
        return ($("#slider").slider("value") * 1000);
    }

    
    function initMain() {

        $("#slider").slider({ 
            animate: true,
            min: 4,
            max: 20,
            step: 2,
            value: 10,
            change: function(event, ui) {
                clearTimeout(intervalID);
                intervalID = setInterval("runIt()", getTimeout());
                $('#slider-value').val(ui.value);
            }            
        });

        
        
        runIt(0);
        var intervalID = setInterval("runIt()", getTimeout());

        $('#messagex').mouseover(function() {
                $('.messagex').stop();
                $('.messagex').animate({color: "#fff"}, 100, "swing");
        });
    }
    
    
