$(document).ready(function(){
   var t = new ticker();
});

/*function cycle(count)
{
    setTimeout("cycle("+ (++count)+")", 3000);
}*/

function ticker()
{
    var headlines = new Array();
    var counter=0;
    $(".ticker_post").each(function(){
        headlines.push(this);
    });
    $("#news_ticker").html(headlines[0]);
    var obj = new Timer();
    obj.Interval = 10000;
    obj.Tick = timer_tick;

    function timer_tick()
    {
        // Do something..
        if(counter<headlines.length)
            counter++;
        else
            counter = 0;
        $("#news_ticker").fadeOut( 1000, function(){
            $(this).html(headlines[counter%headlines.length]);
            $(this).fadeIn(1000);
        })
        
    }
    obj.Start();

}

function cycle(t)
{
   alert(t);
}

// Declaring class "Timer"
var Timer = function()
{
    // Property: Frequency of elapse event of the timer in millisecond
    this.Interval = 1000;

    // Property: Whether the timer is enable or not
    this.Enable = new Boolean(false);

    // Event: Timer tick
    this.Tick;

    // Member variable: Hold interval id of the timer
    var timerId = 0;

    // Member variable: Hold instance of this class
    var thisObject;

    // Function: Start the timer
    this.Start = function()
    {
        this.Enable = new Boolean(true);

        thisObject = this;
        if (thisObject.Enable)
        {
            thisObject.timerId = setInterval(
            function()
            {
                thisObject.Tick();
            }, thisObject.Interval);
        }
    };

    // Function: Stops the timer
    this.Stop = function()
    {
        thisObject.Enable = new Boolean(false);
        clearInterval(thisObject.timerId);
    };

};
