function Scroller_scrollDown()
{
	if (document.imageScroller)
	{
		document.imageScroller.scrollDown();
		
		return false;
	}
	else
	{
		return false;
	}
}

function Scroller_scrollUp()
{
	if (document.imageScroller)
	{
		document.imageScroller.scrollUp();
		
		return false;
	}
	else
	{
		return false;
	}
}

function ImageScroller_scrollDown()
{
	if (this.isScrollable('down'))
	{
		this.currentFirst++;

		this.update();

		return true;
	}
	else
	{
		return false;
	}
}

function ImageScroller_scrollUp()
{
	if (this.isScrollable('up')) // first image is not the first element
	{
		this.currentFirst--;
		
		this.update();
		
		return true;
	}
	else // first image is the first element
	{
		return false;
	}
}

function ImageScroller_isScrollable(direction) // 1 ~ down, -1 ~ up
{
	if (direction >= 1 || direction == 'down')
	{
		return this.currentFirst < (this.images.length - this.elements.length);
	}
	else if (direction <= -1 || direction == 'up')
	{
		return this.currentFirst > 0;
	}
	else
	{
		return false;
	}
}

function ImageScroller_update()
{
	// update images

	for (var i = 0; i < this.elements.length; i++)
	{
		var img = this.elements[i].getElementsByTagName('img')[0];
		img.src = this.images[i + this.currentFirst];
	}
	
	// update scrollers

	if (this.scrollerUp)
	{
		this.scrollerUp.style.visibility = (this.isScrollable('up')) ? 'visible' : 'hidden';
	}
	
	if (this.scrollerDown)
	{
		this.scrollerDown.style.visibility = (this.isScrollable('down')) ? 'visible' : 'hidden';
	}
}

function ImageScroller(images, elementIDs, scrollerDownID, scrollerUpID)
{
	this.images = images;
	
	this.elements = new Array();
	
	for (var i = 0; i < elementIDs.length; i++)
	{
		this.elements[i] = document.getElementById(elementIDs[i]);
	}
		
	this.currentFirst = 0;
	
	this.scrollDown = ImageScroller_scrollDown;
	this.scrollUp = ImageScroller_scrollUp;
	this.update = ImageScroller_update;
	this.isScrollable = ImageScroller_isScrollable;

	this.scrollerDown = document.getElementById(scrollerDownID);
	this.scrollerUp = document.getElementById(scrollerUpID);
	
	if (this.scrollerDown)
	{
		this.scrollerDown.onclick = Scroller_scrollDown;
	}
	if (this.scrollerUp)
	{
		this.scrollerUp.onclick = Scroller_scrollUp;
	}
	
	this.update();
}

function scroller_init()
{
	var images = new Array();
	
	images[0] = 'images/boxes/artist_1.jpg';
	images[1] = 'images/boxes/artist_2.jpg';
	images[2] = 'images/boxes/artist_3.jpg';
	images[3] = 'images/boxes/artist_4.jpg';
	images[4] = 'images/boxes/artist_5.jpg';
	images[5] = 'images/boxes/artist_6.jpg';
	images[6] = 'images/boxes/artist_7.jpg';
	
	var elementIDs = new Array('rbt_box_1', 'rbt_box_2', 'rbt_box_3', 'rbt_box_4');
	
	var scrollerDownID = 'scrollImagesDown';
	var scrollerUpID = 'scrollImagesUp';
	
	document.imageScroller = new ImageScroller(images, elementIDs, scrollerDownID, scrollerUpID)
}