function controller() {
    /* ------------------------------------------------------------ */
    /* Private variables                                            */
    /* ------------------------------------------------------------ */
    var cItems = new Array();
    var cCurSlide;

    /* ------------------------------------------------------------ */
    /* Public properties                                            */
    /* ------------------------------------------------------------ */
    this.length = function() {
        return cItems.length;
    }

    function addItem( element ) {
        cItems[ cItems.length ] = element;
    }

    function removeItem( elemID ) {
        var temp = new Array();
        for( var i in cItems ) {
            if( cItems[ i ].elementId() == elemID ) {
                temp[ temp.length ] = cItems[ i ];
            }
        }
        cItems = null;
        for( var i in temp ) {
            cItems[ cItems.length ] = temp[ i ];
        }
        delete temp;
    }
    
    this.removeItem = removeItem;
    this.addItem = addItem;
    this.next = next;
    this.previous = previous;
    this.move = move;

    /* ------------------------------------------------------------ */
    /* Constructor                                                  */
    /* ------------------------------------------------------------ */
    if( controller.arguments[ 0 ] ) {
        cItems = controller.arguments[ 0 ];
    }
    if( controller.arguments[ 1 ] ) {
        cCurSlide = controller.arguments[ 1 ];
    } else {
        cCurSlide = 0;
    }
    this.items = cItems;
    this.curSlide = cCurSlide;

    if( controller.arguments[ 2 ] ) {
        showSlide();
    }
    
    /* ------------------------------------------------------------ */
    /* Methods                                                      */
    /* ------------------------------------------------------------ */
    function move( index ) {
        cCurSlide = index;
        showSlide();
        this.curSlide = cCurSlide;
    }
    
    function next() {
        if( cCurSlide <= ( cItems.length ) ) {
            move( cCurSlide + 1 );
        }
    }
    
    function previous() {
        if( cCurSlide > 0 ) {
            move( cCurSlide - 1 );
        }
    }
    
    function showSlide() {
        for( var i in cItems ) {
            var target = document.getElementById( cItems[ i ].elementId() );

            switch( cItems[ i ].elementType() ) {
                case "img":
                    target.src = cItems[ i ].value( cCurSlide );
                    break;
                case "a":
                    target.href = cItems[ i ].value( cCurSlide );
                    break;
                default:
                    target.innerHTML = cItems[ i ].value( cCurSlide );
            }
        }
    }
}