/*
	Total Ban : Plugin for GuppY 4.6
	under CeCILL v2 Free Software Agreement
	Copyright (C) 2006-2009 by  HPSAM
	Web site = http://www.hpsam.info
*/
function totalBan(/*Object*/boxInfos) {
	var oThis = this;
	this.boxInfos = boxInfos;
	this.banId = -1;
	this.changeSpeed = 15; // CHANGE SPEED : MIN = 1, MAX = 30
	this.boxDomNode = document.getElementById('boxban'+this.boxInfos.id);	
	this.banDomNode = null;
	this.opacity = 0;
	this.opacityCss = (this.boxInfos.fade == true) ? 'filter:alpha(opacity=0);opacity:0' : '';

	// Random id or next id
	this.getBanId = function() {
		if (this.boxInfos.random) {
			return Math.round(Math.random() * this.boxInfos.endPosition);
		} else {
			this.banId = (this.banId == this.boxInfos.endPosition) ? 0 : ++this.banId;
			return this.banId;
		}
	};
	// Return html code for image
	this.getImgHtml = function(/*Object*/image) {
		return '<img src="'+image.src+'" onclick="oTotalBan'+this.boxInfos.id+'.goTo(\''+image.url+'\',\''+image.target+'\');return(false);" '
	    		+'border="0" alt="'+image.alt+'" title="'+image.url+'" style="cursor:pointer;'+this.opacityCss+'" />';
	};
	// Return html code for flash
	this.getFlashHtml = function(/*Object*/flash) {
		return '<!--[if !IE]> -->'
			+'<object type="application/x-shockwave-flash"'
			+'  data="'+flash.src+'" width="'+flash.width+'" height="'+flash.height+'">'
			+'<!-- <![endif]-->'
			+'<!--[if IE]>'
			+'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
			+'  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"'
			+'  width="'+flash.width+'" height="'+flash.height+'">'
			+'  <param name="movie" value="'+flash.src+'" />'
			+'<!--><!--dgx-->'
			+'  <param name="loop" value="true" />'
			+'  <param name="menu" value="false" />'
			+flash.alt
			+'</object>'
			+'<!-- <![endif]-->';
	};
	// Change the banner opacity
	this.changeOpacity = function() {
		if (this.banDomNode.filters) {
			this.banDomNode.filters.alpha.opacity = this.opacity;
		} else {
			this.banDomNode.style.opacity = this.opacity / 100;
		}
	};
	// Increase the banner opacity
	this.increaseOpacity = function() {
		this.opacity += this.changeSpeed;
		this.changeOpacity();
		
		if(this.opacity >= 100) {
			this.opacity = 100;
			setTimeout(function() { oThis.decreaseOpacity(); }, this.boxInfos.timer);
		} else {
			setTimeout(function() { oThis.increaseOpacity(); }, 50);
		}
	};
	// Decrease the banner opacity
	this.decreaseOpacity = function() {
		this.opacity -= this.changeSpeed;
		this.changeOpacity();		
		 
		if(this.opacity <= 0) {			
			this.opacity = 0;
			this.changeBan();
		} else {
			setTimeout(function() { oThis.decreaseOpacity(); }, 50);
		}
	};
	// Change the banner html code
	this.changeBan = function() {
	    var banId = this.getBanId();
	    var html = '';
		
	    if (this.boxInfos[banId].type == 'img') {
	    	html = this.getImgHtml(this.boxInfos[banId]);
	    } else {
	    	html = this.getFlashHtml(this.boxInfos[banId]);
	    }
	    this.boxDomNode.innerHTML = html;
		
		if (this.boxInfos.fade && this.boxInfos[banId].type == 'img') {
			this.banDomNode = this.boxDomNode.firstChild;
			this.increaseOpacity();
		} else {
			setTimeout(function() { oThis.changeBan(); }, this.boxInfos.timer);
		}
	};
	// Go to an url in a target
	this.goTo = function(/*String*/url, /*String*/target) {
		switch(target) {
			case "_blank":
			    window.open(url, "");
				break;
			case "_top":
				parent.window.location = url;
				break;
			case "_self":
				window.location = url;
				break;
			default:
				parent.frames[target].window.location = url;
		}
	};
}

