/*==================================================*
 $Id: dinbanner.js,v 1.00 2007/6/13  $
 Copyright 2007 Oscar Kuchuk
 http://www.cyberwolf.com

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *==================================================*/

// There are two objects defined in this file:
// "DinBanner" - contains all the information for a single banner
// "BannerPlayer" - consists of multiple DinBanners which change its content's 
//   one at a time after specified timeout

//==================================================
// slide object
//==================================================

function DinBanner(){	
	this.banners=new Array();
	this.count=0;
	this.idx=0;

	this.addBanner = function (bid){
		this.banners[this.count++]=bid;
	}
	this.start = function(){
		if (this.idx>-1)
			this.hide(this.idx);
		this.idx=0;
		this.show(this.idx);
	}
	this.next = function(){
		this.hide(this.idx++);
		if(this.idx>=this.count){
			this.idx=0;
		}
		this.show(this.idx);
	}
	this.hide= function (idx){
		e=document.getElementById(this.banners[idx]);
		e.style.display='none';
	}
	this.show = function (idx){
		e=document.getElementById(this.banners[idx]);
		e.style.display='block';
	}
}

function BannerPlayer(Name,timeout){
	this.timeout=timeout;
	this.timeoutid=0;
	this.count=0;
	this.current=0;
	this.name=Name;
	this.banners=new Array();
	this.add=function(banner){
		this.banners[this.count++]=banner;
	}
	this.start=function(){
		for(i=0;i<this.count;i++){
			this.banners[i].start();
		}
		this.current=0;
		this.play();
	}
	this.play = function(){
		this.pause();
		this.timeoutid=setTimeout(this.name + ".loop()", this.timeout);
	}
	this.loop = function(){
		this.banners[this.current++].next();
		if(this.current>=this.count)
			this.current=0;
		this.play();
	}
	this.pause = function (){
		if (this.timeoutid != 0) {
			clearTimeout(this.timeoutid);
			this.timeoutid = 0;
		}
	}
}
