﻿(function($) {
    $.fn.bannerRotator = $.fn.bannerrotator = function(delay, URL) {
        delay = delay || 5000;
        initTicker = function(el, URL) {
            stopTicker(el);
            el.URL = URL;
            startTicker(el);
        };
        startTicker = function(el) {
            el.tickfn = setInterval(function() { doTick(el) }, delay)
        };
        stopTicker = function(el) {
            clearInterval(el.tickfn);
        };
        pauseTicker = function(el) {
            el.pause = true;
        };
        resumeTicker = function(el) {
            el.pause = false;
        };
        doTick = function(el) {
            if (el.pause) return;
            el.pause = true;
            //get new content
            $.get(el.URL, function(data){
              data = data.replace("<div id=\"bannerHolder\">","").replace("</div//--></div>","</div//-->");
              $(el).html(data);
              el.pause = false;
            });
        };
        this.each(
		function() {
            initTicker(this, URL);
        }
	)
	.addClass("bannerRotator")
	.hover(
		function() {
            pauseTicker(this);
        },
		function() {
            resumeTicker(this);
        }
	);
        return this;
    };

})(jQuery);

