/*
 * Banner & Placeholder code
 */
var cd = new Date().getTime();
var DEFAULT_TIMEOUT = 5000;
var placeholders = new Object();
function BannerObject(placeHolder,path,objectName,link,title,description,defaultVal){
	this.placeHolder = placeHolder;
	this.path = path;
	this.objectName = objectName;
	this.link = link;
	this.title = title;
	this.description = description;
	this.defaultVal = defaultVal;
	this.setBannerMethods = Array();
	this.setBannerMethods['default'] = function(bannerElement,self){
		var div = document.getElementById(placeHolder);
		if(self.link == ''){
			div.innerHTML='<img src="'+self.path+'" alt="'+self.title+' - '+self.description+'"/>';
		}else{
			div.innerHTML='<a title="'+self.description+'" href="'+self.link+'"><img src="'+self.path+'" alt="'+self.title+'"/></a>';
		}
		return;
	};
	this.setBannerMethods['banner_box'] = function(bannerElement,self){
		var div = document.getElementById(placeHolder);
		div.innerHTML='<h4>'+self.title+'</h4><img src="'+self.path+'" alt="'+self.title+'"/><p>'+self.description+'</p><p><a href="'+self.link+'">Read more</a></p>';
		return;
	};
}

function Placeholder(id,m){
	this.currentIndex = 0;
	this.id=id;
	this.activeBanners = Array();
	this.numActive = 0;
	this.bannerElem;
	this.method;
	if(typeof m == 'undefined' || m == ''){
		this.method = 'default';
	}else{
		this.method = m;
	}
	
	this.add = function(banner){
		if(banner.defaultVal){
			this.activeBanners['default'] = banner;
		}else{
			this.activeBanners[this.numActive] = banner;
			this.numActive++;
		}
	};
	
	this.setChangeTimeout = function(ms){
		var _self = this;
		setTimeout(function(ms){
			_self.changeBanner();
		},ms);
	};
	
	this.loadBanners = function(){
		this.bannerElem = document.getElementById(this.id);
		if(this.activeBanners[this.currentIndex]){
			this.activeBanners[this.currentIndex].setBannerMethods[this.method](this.bannerElem,this.activeBanners[this.currentIndex]);
		}else if(this.activeBanners['default']){
			this.activeBanners['default'].setBannerMethods[this.method](this.bannerElem,this.activeBanners['default']);
		}
		if(this.numActive > 1){
			if(typeof TIMEOUT=='undefined'){
	    	this.setChangeTimeout(DEFAULT_TIMEOUT);
	    }else{
	    	this.setChangeTimeout(TIMEOUT);
	    }
		}
	};
	
	this.changeBanner = function(){
	    this.currentIndex++;
	    if (this.currentIndex == this.numActive){
	        this.currentIndex = 0;
	    }
	    this.activeBanners[this.currentIndex].setBannerMethods[this.method](this.bannerElem, this.activeBanners[this.currentIndex]);
	    if(typeof TIMEOUT=='undefined'){
	    	this.setChangeTimeout(DEFAULT_TIMEOUT);
	    }else{
	    	this.setChangeTimeout(TIMEOUT);
	    }
	};
}
