/**
 * File with iconBox class
 *
 * @author XShady
 * @project itzone
 */


/**
 * Class for handling auto-scrolling icon-box
 *
 */
iconBox = {
	/**
	 * Constructor
	 *
	 */
	initialize:
        function(boxId, interval, speed)
        {
            this.boxId = boxId;
            this.boxContentId = this.boxId + '_content';
            this.boxInnerId = this.boxId + '_inner';
            this.interval = (interval != '') ? interval : 3;
            this.speed = (speed != '') ? speed : 30;
            // scroll if size of inner box is smaller than size of wrapper box?
            this.scrollSmallContent = false;
            this.centerSmallContent = true;
            this.smallContent = false;

			this.heartbeat = 1;
            this.wrapperSize = this.contentSize = this.scrollX = 0;
            this.timer = false;
			this.scrollDirection = '-';
			this.effect = null;
			this.loop = false;

			this.initScroll();

            return true;
        },

	/**
	 * Starts loop of scrolling
	 *
	 */
	initScroll:
	    function()
		{
			this.wrapperSize = document.getElementById(this.boxId).offsetWidth;
			this.contentSize = document.getElementById(this.boxContentId).offsetWidth;

			if (this.contentSize == 0)
			    setTimer('iconBox.initScroll()', 1000);

			this.smallContent = (this.contentSize < this.wrapperSize);
			
			// If content of box is smaller then box size
			if (this.smallContent)
			{
			    // Scroll content from one side to another and oterwise
                if (this.scrollSmallContent)
                {
            		this.scrollDirection = '+';
                	this.scrollX = this.scrollX - 10;
                	this.loop = true;
				}
				// Just scroll content to the center of wrapper and stop
                else if (this.centerSmallContent)
                {
                    this.scrollDirection = '+';
                    this.scrollX = abs((this.wrapperSize - this.contentSize) / 2);
                    this.loop = false;
				}
				else
				    return false;
			}
			else
			{
			    // Move bigger content from one side to another and back
			    // to show all content
			    this.scrollX = abs(this.contentSize - this.wrapperSize);
			    this.loop = true;
			}

			return this.doScroll();
		},

	/**
	 * Checks continualy progress of effect
	 *
	 */
	checkScrollProgress:
	    function()
	    {
	        // If scrolling finished, wait specified interval and start it again
	        if (this.effect.progress == 100)
	        {
	            Page.clearInterval(this.timer);
	            this.timer = Page.setInterval('iconBox.doScroll()', this.interval * 1000);
	            this.effect.progress = 0;
			}
		},
	/**
	 * Scrolls box content to different directions
	 *
	 */
	doScroll:
	    function()
	    {
 	        var delay = this.scrollX / this.speed;
 	        var scrollX = (this.scrollDirection == '+') ? this.scrollX : - this.scrollX;
 	        this.scrollDirection = (this.scrollDirection == '+') ? '-' : '+';

			this.effect = new scrollElement(this.boxInnerId, scrollX, 'x', delay);
			this.effect.objName = 'iconBox.effect';
			if (this.loop)
				this.effect.onFinish = 'Page.setTimer("iconBox.doScroll()", '
					+ (this.interval * 1000) + ')';
			this.effect.startScroll();

		}
}