jQuery.fn.extend({
    VsignRender: function(options) {

        // Any options?
        if (options === undefined || options === null) {
            options = {
                direction: "none",
                width: 100,
                height: 100,
                scrollSpeed: 2,
                scaleText: false,
                fitText: false,
                scaleFactor: 1
            };
        }

        this.each(function() {
            // Scale text to fit the box
            if (options.scaleText) {
                // Go through every <span> element, and scale it accordingly.
                $("span, p", this).each(function(){
                    // Already has a font?
                    var fontSize = $(this).css("font-size");

                    $(this).css("font-size", Math.round(fontSize.replace("px", "") * options.scaleFactor));
                });
            }

            // Fit text?
            else if (options.fitText) {

                // Make sure our element has a width and height - and is display:block
                $(this).css({
                    width: options.width,
                    height: options.height,
                    display: "block"
                });

                // Remove the font-size property of all children
                $("*", this).css("font-size", "");

                // Run the Fit Text plugin
                $(this).fitText(1.75);
            }

            // Ticker?
            if (options.type == "ticker") {
                $(".article", this).css({
                    "padding-left": "4px",
                    display: "inline"
                });

                $(".VsignRssItem", this).css({
                    display: "block",
                    width: options.width
                });
            }

            // Animated somehow?
            if (options.direction == "single") {
                // Use the cycle plugin to switch between the items
                var totalDuration = options.duration * 1000;
                var itemCount = $('.VsignRssItem').size();
                var itemTime;

                if (options.durationIsPerItem)
                    itemTime = totalDuration / itemCount;
                else
                    itemTime = totalDuration;

                if (itemTime < 2000)
                    itemTime = 2000;

               // Cycle handles this for us
               $('#text').cycle({
                   fx: 'fade',
                   timeout:itemTime
               });
            }
            else if (options.direction == "left" || options.direction == "right") {
                $("p", this).css("display", "inline");
            }

            // Marquee?
            if (options.direction != "none" && options.direction != "single") {

                // Set some options on the node, before calling marquee (behaviour, direction, scrollAmount, width, height)
                $(this).attr({
                    direction: options.direction,
                    width: options.width,
                    height: options.height,
                    scrollamount: options.scrollSpeed,
                    behaviour: "scroll"
                });

                // Create a marquee out of it
                $(this).marquee();
            }
        });
    }
});