    /**
     * ImageSwitcher class
     *
     * @class ImageSwitcher
     */
    function ImageSwitcher ()
    {
        this.currentPage       		= -1;
        this.contentList        	= [];
        this.intervalHandler    	= null;
        this.intervalDelay      	= 5000;
        this.fadeDuration       	= 1000;
        this.pagingInfoLanguage 	= ['Seiten'];
        this.controlsId         	= '#contentNavigation';
		this.controlsId_pause_class = "contentNavigation_pause";
		this.controlsId_pages_class = "contentNavigation_pages";
		this.controlsId_pause       = this.controlsId + " ." + this.controlsId_pause_class;
		this.controlsId_pages   	= this.controlsId + " ." + this.controlsId_pages_class;
        this.controlsLanguage   	= ['Pause', 'Weiter'];
        this.isPaused           	= false;
        this.contentPagePrefix  	= 'content-page-';
        this.contentPageWrap    	= '#jquery';
    }



    /**
     * Init function, calls the required functions for initialization
     */
    ImageSwitcher.prototype.init = function ()
    {
        if ( this.getImages() )
        {
            this.currentPage = 0;
			this.initPagingInfo();
            this.setInitValuesForContent();
            this.hideExcept( -1 );
            this.show( 0, false );
            this.startInterval( true, true );
            
            this.showStatus();
            this.showPagingInfo();
			$( this.controlsId ).mouseover(
				function ()
				{
					$(this).css('cursor', 'default');
				}
			);
        }
    }


	ImageSwitcher.prototype.initPagingInfo = function ()
	{
		var htmlContent = '<div class="' + this.controlsId_pages_class + '_wrap"><strong>' + this.pagingInfoLanguage[0]  + ':</strong> <span class="' + this.controlsId_pages_class + '"></span></div>';
		htmlContent += '<div class="' + this.controlsId_pause_class + '"></div>';
		$( this.controlsId ).html( htmlContent );
	}
	
    /**
     * Shows the paging info
     */
    ImageSwitcher.prototype.showPagingInfo = function ()
    {
        var htmlContent = '';

        for (var i = 0; i < this.contentList.length; i++)
        {
            if (this.currentPage == i)
            {
                htmlContent += '<strong>' + (i+1) + '</strong> ';
            }
            else
            {
                htmlContent += '<a href="" onclick="return imageSwitcher_setPage('+ i + ');">' + (i+1) + '</a> ';
            }
        }
		
        $( this.controlsId_pages ).html( htmlContent );
    }



    /*
     * Shows the control status
     */
    ImageSwitcher.prototype.showStatus = function ()
    {
        var arrayId = (!this.isPaused) ? 0 : 1;
        var htmlContent = '<a href="">' + this.controlsLanguage[arrayId] + '</a>';
        $( this.controlsId_pause ).html( htmlContent );
		$( this.controlsId_pause + " a" ).click(
			function ()
			{
				return imageSwitcher_toggle();
			}
		);
    }


    /**
     * Sets initialization values for the content elements
     */
    ImageSwitcher.prototype.setInitValuesForContent = function ()
    {
        for (var i = 0; i < this.contentList.length; i++)
        {
            $( this.getContentId(i) ).css( 'position', 'absolute' );
            $( this.getContentId(i) ).width( 600 );
            $( this.getContentId(i) ).height( 300 );
        }
    }



    /**
     * Toggles between paused and running mode
     */
    ImageSwitcher.prototype.toggle = function ()
    {
        if (this.isPaused)
        {
            this.startInterval();
        }
        else
        {
            this.stopInterval();
        }

        this.showStatus();
    }



    /**
     * Gets the next picture in the list. Called by the interval handler
     */
    ImageSwitcher.prototype.nextImage = function ()
    {
        var nextImage = (this.currentPage == (this.contentList.length - 1)) ? 0 : (this.currentPage + 1);
        this.changeImageTo( nextImage );
    }



    /*
     * Starts the interval
     */
    ImageSwitcher.prototype.startInterval = function ()
    {
        this.stopInterval();
        this.intervalHandler = window.setInterval( 'imageSwitcherHandler.nextImage()', this.intervalDelay );

        this.isPaused = false;
        
        return true;
    }



    /**
     * Stops the interval
     */
    ImageSwitcher.prototype.stopInterval = function ()
    {
        if (this.intervalHandler != null)
        {
            window.clearInterval( this.intervalHandler );
            this.intervalHandler = null;
        }

        this.isPaused = true;

        return true;
    }



    /*
     * Resets the interval
     */
    ImageSwitcher.prototype.resetInterval = function ()
    {
        this.startInterval( false, false );
        return true;
    }



    /**
     * Searches for matching content elements and adds them to the content list
     */
    ImageSwitcher.prototype.getImages = function ()
    {
        $( this.contentPageWrap + ' div[id^=\'' + this.contentPagePrefix + '\']' ).each(
            function ()
            {
                imageSwitcherHandler.contentList.push( '#' + this.id );
            }
            
        );

        return (this.contentList.length > 1);
    }



    /**
     * Hides all images except the one specified
     */
    ImageSwitcher.prototype.hideExcept = function ( listNr )
    {
       if ((listNr >= 0 && listNr < this.contentList.length) || (listNr == -1))
       {
           for (var i = 0; i < this.contentList.length; i++)
           {
               if (i != listNr)
               {
                   $( this.getContentId(i) ).hide();
               }
           }
           
           return true;
       }

       return false;
    }



    /**
     * Show the content
     */
    ImageSwitcher.prototype.show = function ( listNr, animate )
    {
        if (animate)
        {
            $( this.getContentId(listNr) ).fadeIn( this.fadeDuration );
        }
        else
        {
            $( this.getContentId(listNr) ).show();
        }
    }



    /**
     * Hides the content
     */
    ImageSwitcher.prototype.hide = function ( listNr, animate )
    {
        if (animate)
        {
            $( this.getContentId(listNr) ).fadeOut( this.fadeDuration );
        }
        else
        {
            $( this.getContentId(listNr) ).hide();
        }
    }



    /**
     * Gets the id of the content page at position listNr
     *
     * @param listNr position in the list
     * @return <bool/string> either false in case of error, otherwise the content element's id
     */
    ImageSwitcher.prototype.getContentId = function ( listNr )
    {
        if (listNr < 0 || listNr >= this.contentList.length)
        {
            return false;
        }
        else
        {
            return this.contentList[ listNr ];
        }
    }



    /**
     * Changes the image to the required one. Calls the animation functions
     *
     * @return <bool> if the change was successfull
     */
    ImageSwitcher.prototype.changeImageTo = function ( nextImage )
    {
        if (nextImage == this.currentPage)
        {
            return false;
        }

        this.hide( this.currentPage, true );
        this.show( nextImage, true );
        
        // so the content will not switch immediately again
        if (!this.isPaused && (nextImage - this.currentPage != 1))
        {
            this.resetInterval();
        }

        this.currentPage = nextImage;
        this.showPagingInfo();

        return true;
    }



    /**
     * the global ImageSwitcher object
     */
    var imageSwitcherHandler = new ImageSwitcher();



    /**
     * Autostart imageSwitcher
     */
    $(document).ready(
        function ()
        {
            imageSwitcherHandler.init();
        }
    );


    // ------------------------------------------------------------------------------------------
    // wrapping functions
    function imageSwitcher_setPage ( nextPage )
    {
        imageSwitcherHandler.changeImageTo( nextPage );
        return false;
    }

    function imageSwitcher_toggle ()
    {
        imageSwitcherHandler.toggle();
        return false;
    }
