function BannerScroller( target, data ) {
    /* ------------------------------------------------------------ */
    /* Private variables                                            */
    /* ------------------------------------------------------------ */
    var c_elem;       //object; reference to element that contains scroller
    var c_banners;    //array; holds references to banner images
    var c_index;      //number; index of currently displayed banner (zero-based)
    var mode;       //number; keeps track of scroller's current activity; 0 = waiting, 1 = changing
    var int_scroll;   //number; interval index for automatic scrolling
    var c_timer;        //number; number of segments for which scroller has been running
    var c_displayTime;  //number: number of segments that a banner will be shown
    var stack_height; //current z-index of highest banner
    var ref;          //reference to object

    /* ------------------------------------------------------------ */
    /* Public properties                                            */
    /* ------------------------------------------------------------ */
    this.element = function() {
        return c_elem;
	}

    this.elementID = function() {
        return c_elem.getAttribute( "id" );
	}

    this.currentSlide = function() {
        return c_index;
	}

    this.banners = function() {
        return c_banners;
    }

    this.banner = function( index ) {
        return c_banners[ index ];
    }

    this.timer = function() {
        return c_timer;
    }

    this.displayTime = function() {
        return c_displayTime;
    }

    /* ------------------------------------------------------------ */
    /* Public Methods                                               */
    /* ------------------------------------------------------------ */
    this.showNext = showNext;
    this.showPrevious = showPrevious;
    this.showPrev = showPrevious;
    this.incrementTimer = incrementTimer;
    this.setIndex = setIndex;
    this.setTimer = setTimer;

    /* ------------------------------------------------------------ */
    /* Constructor                                                  */
    /* ------------------------------------------------------------ */
    c_banners = new Array();
    stack_height = 0;

    setIndex( data.length - 1 );
    setTarget( target );
    c_timer = 799;
    c_displayTime = 800;
    this.mode = 0;

    for( var i = 0; i < data.length; i++ ) {
        addBanner( data[ i ] );
	}

    ref = this;
    int_scroll = setTimeout( function() { updateScroller( ref ) }, 10 );

    /* ------------------------------------------------------------ */
    /* Private Methods                                              */
    /* ------------------------------------------------------------ */
    function updateScroller() {
        var self = ( arguments.length > 0 ) ? arguments[ 0 ] : this;
        var ban = self.banners();
        var b = self.banner( self.currentSlide() );
        var index = ( self.currentSlide() < ban.length - 1 ) ? ( 1 + self.currentSlide() ) : 0;

        self.incrementTimer();

        switch( self.mode ) {
            case 2: //mode: reversing
                index = ( self.currentSlide() < 1 ) ? ( ban.length - 1 ) : ( self.currentSlide() - 1 );
            case 0: //mode: waiting
                if( self.timer() % self.displayTime() == 0 ) { //time to switch to the next banner
                    //move next banner to top
                    b = self.banner( index );
                    b.setOpacity( 0 );
                    b.img().style.zIndex = ++stack_height;
                    self.setIndex( index );

                    self.mode = 1;
                }

                break;
            case 1: //mode: advancing
                var o = b.getOpacity();

                if( o < 99 ) { //if banner hasn't finished fading up
                    b.setOpacity( o + 5 );
                } else {
                    self.mode = 0;
                }

                break;
            default:
                break;
        }

        int_scroll = setTimeout( function() { updateScroller( self ) }, 10 );
    }

    function debug( msg ) {
        if( document.getElementById( "debug" ) ) {
            if( arguments.length > 1 ) {
                if( arguments[ 1 ] == true ) {
                    while( document.getElementById( "debug" ).firstChild ) {
                        document.getElementById( "debug" ).removeChild( document.getElementById( "debug" ).firstChild );
                    }
                }
            }

            document.getElementById( "debug" ).appendChild( document.createTextNode( msg ) );
            document.getElementById( "debug" ).appendChild( document.createElement( "br" ) );
        } else {
            alert( "DEBUG: " + msg );
        }
    }

    function setTarget( t ) {
        var type = typeof t;

        c_elem = ( type == "string" ) ? document.getElementById( t ) : t;
        c_elem.style.overflow = "hidden";
        c_elem.style.cursor = "pointer";
        c_elem.style.position = "relative";
    }

    function setIndex( i ) {
        c_index = ( isNaN( parseInt( i ) ) ) ? 0 : ( i > -1 ) ? i : 0;
	}

    function addBanner( d ) {
        var b;
        var img = document.createElement( "img" );
        var images;
        var u;

        img.setAttribute( "src", d[ 1 ] );
        img.setAttribute( "id", "banner" + c_banners.length );
        img.style.position = "absolute";
        img.style.left = "0px";
        img.style.top = "0px";
        img.style.zIndex = ++stack_height + "";

        u = d[ 0 ] + ( ( d[ 0 ].indexOf( "?" ) < 0 ) ? "?" : "&" ) + "source=banner";
        if( u.indexOf( "#" ) > -1 ) {
            u = u.substring( 0, u.indexOf( "#" ) ) + u.substring( u.indexOf( "?" ) ) + u.substring( u.indexOf( "#" ), u.indexOf( "?" ) );
        }

        if( d[ 2 ] ) {
            addEvent( img, "click", function() { window.open( u, '' ); } );
        } else {
            addEvent( img, "click", function() { document.location.href = u; } );
        }

        c_elem.appendChild( img );
        b = new Banner( u, d[ 1 ], c_elem.lastChild, d[ 2 ] );
        b.setOpacity( 0 );
        c_banners.push( b );
    }

    function showNext() {
        var self = ( arguments.length > 0 ) ? arguments[ 0 ] : this;

        self.setTimer( 799 );
    }

    function showPrevious() {
        var self = ( arguments.length > 0 ) ? arguments[ 0 ] : this;

        self.mode = 2;
        self.setTimer( 799 );
    }

    function setTimer( t ) {
        c_timer = t;
    }

    function incrementTimer() {
        setTimer( c_timer + 1 );
    }
}

/* COOKIE SCRIPTS FROM quirksmode.org: http://www.quirksmode.org/js/cookies.html */
function createCookie( name, value, days ) {
    if( days ) {
        var date = new Date();
        date.setTime( date.getTime() + ( days * 24 * 60 * 60 * 1000 ) );
        var expires = "; expires=" + date.toGMTString();
    } else {
        var expires = "";
    }

    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie( name ) {
    var nameEQ = name + "=";
    var ca = document.cookie.split( ';' );

    for( var i = 0; i < ca.length; i++ ) {
        var c = ca[ i ];

        while( c.charAt( 0 ) == ' ' ) {
            c = c.substring( 1, c.length );
        }

        if( c.indexOf( nameEQ ) == 0 ) {
            return c.substring( nameEQ.length, c.length );
        }
    }

    return null;
}

function eraseCookie( name ) {
    createCookie( name, "", -1 );
}
/* END quirksmode.org SCRIPTS */

function setScroller() {
    scroller = new BannerScroller( "div_scroller", d );
}

//Item order: target URL, image URL, spawn new window?
var d = [ [ "/Applications/ExpandedQuote/Default.aspx", "/images/bnr_Auto.jpg", false ]];
var scroller;

if( readCookie( "returnVisitor" ) == null ) {
    d.unshift( [ "about/History.aspx", "images/bnr_History.jpg", false ] );
    createCookie( "returnVisitor", "true", 14 );
} else {
    d.push( [ "about/History.aspx", "images/bnr_History.jpg", false ] );
}

addEvent( window, "load", setScroller );
