function flashy_image ( src, title, desc, href ) {
	this.src = src;
	this.title = title;
	this.desc = desc;
	this.href = href;
}

var flashy = new function () {
	this.oSrc = null;
	this.oTitle = null;
	this.oDesc = null;
	this.oCircle = null;
	this.oBox = null;
	this.oLink = null;
	this.images = [];
	this.current = -1;
	this.time = -1;
	this.counter = 0;
	this.raising = false;

	this.push = function ( image ) {
		this.images.push( image );
	};
	
	this.init = function ( idSrc, idTitle, idDesc, idCircle, idBox, idDiv, idLink ) {
		this.oSrc = document.getElementById(idSrc);
		this.oTitle = document.getElementById(idTitle);
		this.oDesc = document.getElementById(idDesc);
		this.oCircle = document.getElementById(idCircle);
		this.oBox = document.getElementById(idBox);
		this.oLink = document.getElementById(idLink);
		document.getElementById(idDiv).style.display = "block";
				
		if( this.images ) {
			this.current = 0;
			this.showImage();
		}
	};
	
	this.startAnimation = function ( ) {
		this.time = -1;
		this.counter++;
		this.raising = !this.raising;
		this.animate(this.counter);
	}
	
	this.animate = function ( counter )
	{
		if( this.counter == counter )
		{
			var timeToSwitch = 8000;
			var heightToFill = 56;
			var interval = 10;
			this.time = (this.time == -1) ? 0 : (this.time + interval);
			if( this.time >= timeToSwitch )
			{
				this.next();
			}
			else
			{
				var height  = Math.round((this.time/timeToSwitch) * heightToFill);
				if( !this.raising)
				{
					height = heightToFill - height;
				}
				this.oBox.style.height = height+'px';
				setTimeout( "flashy.animate("+this.counter+")", interval );
			}
		}
	}
	
	this.next = function ( )
	{
		if( this.current == -1 ) 
		{ 
			return null; 
		}
		this.current++;
		if( this.current == this.images.length )
		{
			this.current = 0;
		}
		this.showImage();
	};
	
	this.previous = function ( )
	{
		if( this.current == -1 )
		{
			return null;
		}
		this.current--;
		if( this.current == -1 )
		{
			this.current = this.images.length - 1;
		}
		this.showImage();
	};
	
	this.showImage = function ()
	{
		if( this.current == -1 )
		{
			return null;
		}
		var img = this.images[this.current];
		this.oSrc.src = img.src;
		this.oLink.href = img.href;
		if (img.href == "") this.oLink.removeAttribute("href");
		this.oTitle.innerHTML = img.title;
		this.oDesc.innerHTML = img.desc;
		this.oCircle.className = "state"+(this.current+1);
		this.startAnimation();
	};
}
