/***************************************************************************************************************\
// ==JavaScript===
// @name			bannerR.js
// @author			Jerone JS Productions
// @namespace		About Jeroen
// @homepage		http://jervw.freehostia.com
// @description		Banner Rotator
// @version			v1.5
// @copyright		2007
// @browser			IE7, FF2, Opera9, NS9
// @include
// ==/JavaScript==
|***************************************************************************************************************|
ToC:
- Banner,
- Node,
- add,
- toString,
- start,
- addTime
- timer,
- changeBanner.
|***************************************************************************************************************|
THIS  SCRIPT  IS  PROVIDED BY THE AUTHOR `AS IS' AND ANY EXPRESS OR IMPLIED
WARRANTIES,  INCLUDING, BUT  NOT  LIMITED  TO, THE  IMPLIED  WARRANTIES  OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
EVENT  SHALL  THE  AUTHOR  BE  LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;  LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER  CAUSED  AND  ON  ANY THEORY OF LIABILITY,
WHETHER  IN  CONTRACT, STRICT  LIABILITY, OR  TORT  (INCLUDING NEGLIGENCE OR
OTHERWISE)  ARISING  IN  ANY  WAY  OUT  OF  THE  USE OF THIS SCRIPT, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\***************************************************************************************************************/

function Banner(objName){
	this.obj = objName;
	this.aNodes = [];
	this.currentBanner = 0;
};

function Node(bnrName, bnrType, bnrPath, bnrDuration, bnrHeight, bnrWidth, bnrLink) {
	this.bnrName = bnrName;
	this.bnrType = bnrType.toUpperCase();
	this.bnrPath = bnrPath;
	this.bnrDuration = bnrDuration;
	this.bnrHeight = bnrHeight
	this.bnrWidth = bnrWidth;
	this.bnrLink = bnrLink;
	this.addTimer = false;
//console.log(bnrName +"|" + bnrType +"|" + bnrPath +"|" + bnrDuration +"|" + bnrHeight +"|" + bnrWidth + "|" + bnrLink);
};

Banner.prototype = {
	add: function(bnrType, bnrPath, bnrDuration, bnrHeight, bnrWidth, bnrLink) {
		this.aNodes[this.aNodes.length] = new Node(this.obj +"_"+ this.aNodes.length, bnrType, bnrPath, bnrDuration, bnrHeight, bnrWidth, bnrLink);
	},
	toString: function() {
		var str = ""
		str = str + '<div class="timerDiv" id="'+this.obj+'_timerDiv">Adbanner</div>';
		for (var iCtr=0; iCtr < this.aNodes.length; iCtr++){
			str = str + '<span name="'+this.aNodes[iCtr].bnrName+'" '
			str = str + 'id="'+this.aNodes[iCtr].bnrName+'_span" ';
			str = str + 'class="bannerR_hide" >';
			if (this.aNodes[iCtr].bnrLink != ""){
				str = str + '<a href="'+this.aNodes[iCtr].bnrLink+'" ';
				str = str + 'id="'+this.aNodes[iCtr].bnrName+'_link" ';
				str = str + 'target="_blank" >';
			}
				
			if (this.aNodes[iCtr].bnrType == "FLASH"){
				str = str + '<OBJECT '
				str = str + 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
				str = str + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '
				str = str + 'id="'+this.aNodes[iCtr].bnrName+'_flash" '
				str = str + 'HEIGHT="'+this.aNodes[iCtr].bnrHeight+'" '
				str = str + 'WIDTH="'+this.aNodes[iCtr].bnrWidth+'" '
				str = str + 'VIEWASTEXT>'
				str = str + '<PARAM NAME=movie VALUE="'+ this.aNodes[iCtr].bnrPath + '">'
				str = str + '<PARAM NAME=quality VALUE=high>'
				str = str + '<PARAM NAME=bgcolor VALUE=#FFFCDA>'
				str = str + 	'<EMBED ';
				str = str + 	'src="'+this.aNodes[iCtr].bnrPath+'" '
				str = str + 	'quality=high '
				str = str + 	'WIDTH="'+this.aNodes[iCtr].bnrWidth+'" '
				str = str + 	'HEIGHT="'+this.aNodes[iCtr].bnrHeight+'" '
				str = str + 	'NAME="bnr_'+this.aNodes[iCtr].bnrName+'" '
				str = str + 	'TYPE="application/x-shockwave-flash" '
				str = str + 	'PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">'
				str = str + 	'</EMBED>'
				str = str + '</OBJECT>'
			}
			else if (this.aNodes[iCtr].bnrType == "IMAGE"){
				str = str + '<img src="'+this.aNodes[iCtr].bnrPath+'" ';
				str = str + 'id="'+this.aNodes[iCtr].bnrName+'_image" '
				str = str + 'height="'+this.aNodes[iCtr].bnrHeight+'" ';
				str = str + 'width="'+this.aNodes[iCtr].bnrWidth+'" ';
				str = str + 'alt="'+this.aNodes[iCtr].bnrName+'" />';
			}
			else if (this.aNodes[iCtr].bnrType == "IFRAME"){
				str = str + '<iframe src="'+this.aNodes[iCtr].bnrPath+'" ';
				str = str + 'id="'+this.aNodes[iCtr].bnrName+'_iframe" '
				str = str + 'height="'+this.aNodes[iCtr].bnrHeight+'" ';
				str = str + 'width="'+this.aNodes[iCtr].bnrWidth+'" ';
				str = str + 'name="'+this.aNodes[iCtr].bnrName+'" ';
				str = str + 'scrolling="no" ></iframe>';
			}

			if (this.aNodes[iCtr].bnrLink != ""){
				str = str + '</a>';
			}
			str += '</span>';
		}
		return str;
	},
	start: function(){
		$gi(this.aNodes[this.currentBanner].bnrName+'_span').className = "bannerR_show";
		this.timer(this.aNodes[this.currentBanner].bnrDuration);
	},
	addTime: function(){
		this.addTimer = true;
	},
	timer: function(time){
		if (time >= 0){
			if (this.addTimer){
				$ih($gi(this.obj+"_timerDiv"),(this.currentBanner+1) + ' / ' + this.aNodes.length + ' | ' + time);
			}
			
			if (time>=1){
				time--;
				window.setTimeout(this.obj+".timer(" + time + ")",1000);
			}
			else {
				this.changeBanner();
				this.timer(this.aNodes[this.currentBanner].bnrDuration);
			}
		}
	},
	changeBanner: function(){
		var thisBanner;
		var prevBanner = -1;
		if (this.currentBanner < this.aNodes.length){
			thisBanner = this.currentBanner+1;
			if (this.aNodes.length > 1){
				if (thisBanner > 0){
					prevBanner = thisBanner - 1;
				}
				else{
					prevBanner = this.aNodes.length - 1;
				}
			}
			
			if (this.currentBanner < this.aNodes.length - 1){
				this.currentBanner = this.currentBanner + 1;
			}
			else{
				this.currentBanner = 0;
			}
			
			if (thisBanner > this.aNodes.length-1){
				thisBanner = 0
			}
		}

		if (prevBanner >= 0){
			$gi(this.aNodes[prevBanner].bnrName+'_span').className = "bannerR_hide";
		}
		$gi(this.aNodes[thisBanner].bnrName+'_span').className = "bannerR_show";
	}	
};
