﻿// ---------------------------------------------------------------------
// Description:		BraProsInfo.js
//					ClientSide Script for BraProsInfo.cs control
// 
// Autor:			Herbert Granofszky
// Date:			30.10.2007
// 
// (c) by team ModulAcht. All rights reserved
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Required script files:                           Common/prototype.js
//                                                  Common/scriptaculous.js
// ---------------------------------------------------------------------

var BraProsInfo = Class.create();
BraProsInfo.prototype =
{
    id : null,
    // ---------------------------------------------------------------------
    // Constructor
    // --------------------------------------------------------------------- 
    initialize : function(argElementId)
    {
        this.id = argElementId;
        this._element = $(argElementId);
        this._imageCell = $(argElementId + '_imgcell');
        this._infoCell = $(argElementId + '_textcell');
        this._infoDiv = null;
        this._images = new Array();
    },
    
    addImage : function(argImage, argHead, argText)
    {
        this._images.push({img: argImage, head: argHead, txt: argText});    
    },
    
    initImages : function()
    {
        this._wrp = $(Builder.node('div', {id: 'slideshow', className:'slideshow'}));
        this._imageCell.appendChild(this._wrp);
        this._wrp = $(this._wrp.id);
        for (var i=0; i < this._images.length; i++)
        {
            var img = Builder.node('div', {className:'slide'}, 
                        Builder.node('img', {style:'margin:0px', src:this._images[i].img}));    
            this._wrp.appendChild(img);                        
        }        
    },
    
    startSlideShow : function(argDelay)
    {
        if ($('slideshow') != null)
        {
            new Slideshow('slideshow', argDelay, this._onNextSlide.bind(this));
        }
        this._infoDiv = $(this._createInfoNode(0));
        this._infoCell.appendChild(this._infoDiv);
    },
    
    _createInfoNode : function(argSlideNr)
    {
        var infoNode = $(Builder.node('div', {className: 'braproinfo_text'},
                            [
                                Builder.node('h1', {className: 'braproinfo_head'}, this._images[argSlideNr].head),
                                this._images[argSlideNr].txt]
                             
                            ));
        return infoNode;
    },
    
    _onNextSlide : function(argCurrentSlide)
    {
        setTimeout(this._changeTextInfo.bind(this, argCurrentSlide), 600);
    },
    
    _changeTextInfo : function(argCurrentSlide)
    {
       var tempNode = this._createInfoNode(argCurrentSlide);
       this._infoDiv.remove();
       this._infoCell.appendChild(tempNode);
       this._infoDiv = tempNode;
    }                  
};
