
var ImgRandLoader = function(imageList, width, height){
	
	this.imageList = new Array();
	this.idx = 0;
	this.tagClass = 'img_rand_loader';
	this.tagId = 'img_rand_loader';
	
	this.width = width;
	this.height = height;
	
	this.getSrc = function()
	{
		if( this.imageList.length >= this.idx + 1 )
		{
			return this.imageList[this.idx].src;
		}
		return '';
	}
	
	this.getLink = function()
	{
		if( this.imageList.length >= this.idx + 1 )
		{
			return this.imageList[this.idx].href;
		}
		return '';
	}
	
	this.getAlt = function()
	{
		if( this.imageList.length >= this.idx + 1 )
		{
			return this.imageList[this.idx].alt;
		}
		return '';
	}
	
	this.setImageList = function(imageList)
	{
		this.imageList = imageList;
		this.idx = Math.floor(Math.random() * 100);
		this.idx = this.idx % this.imageList.length;
	}
	
	this.write = function()
	{
		var tagParams = {
			src: this.getSrc(),
			"class": this.tagClass,
			id: this.tagId,
			width: this.width,
			height: this.height,
			border: 0,
			alt: this.getAlt()
		};
		
		var tag = "";
		for(var k in tagParams)
		{
			tag += " " + k + "='" + tagParams[k] + "'";
		}
		tag = "<img " + tag + ">";
		
		var link = this.getLink();
		if(link.length)
		{
			document.write('<a href="' + link + '">' + tag + '</a>');
		}
		else
		{
			document.write(tag);
		}
	}
	
	this.setImageList(imageList);
	
}