// JavaScript Document
$(document).ready(init);
var items, CurrentImage, CurrentTitle, CurrentDescription, Next, Previous, CurrentLink;
var index, maxIndex;
var images, titles, descriptions, links;
function init()
{
	//Set up arrays
	var items = $('.simpleSlideShow div');
	items.hide();
	index = 0;
	maxIndex = items.length;
	images = $('.simpleSlideShow div .full');
	titles = $('.simpleSlideShow div h1');
	descriptions = $('.simpleSlideShow div p');
	links = $('.simpleSlideShow div a');
	
	//Add containers
	$('.simpleSlideShow').append('<div id="NextDiv"><a id="Next">Next</a></div>');
	Next = $('#Next');
	Next.bind('click', moveNext);
	$('.simpleSlideShow').append('<div id="PreviousDiv"><a id="Previous">Previous</a></div>');
	Previous = $('#Previous');
	Previous.bind('click', movePrevious);
	$('.simpleSlideShow').append('<div id="CurrentTitle"></div>');
	CurrentTitle = $('#CurrentTitle');
	$('.simpleSlideShow').append('<div id="CurrentDescription"></div>');
	CurrentDescription = $('#CurrentDescription');
	$('.simpleSlideShow').append('<div id="CurrentImageDiv"><a id="CurrentLink"><img id="CurrentImage" /></a></div>');
	CurrentImage = $('#CurrentImage');
	CurrentLink = $('#CurrentLink');
	
	//initialize to first element
	set();
	
}

function set()
{
	CurrentImage.get(0).src = images.get(index).src;
	CurrentTitle.get(0).innerHTML = titles.get(index).innerHTML;
	CurrentDescription.get(0).innerHTML = descriptions.get(index).innerHTML
	CurrentLink.get(0).href = links.get(index).href;
	if (index == maxIndex-1)
		Next.addClass("disabled");
	if (index > 0)
		Previous.removeClass("disabled");
	if (index == 0)
		Previous.addClass("disabled");
	if (index < maxIndex - 1)
		Next.removeClass("disabled");
	$('.simpleSlideShow').fadeIn(1000);
}

function moveNext()
{
		if (index < maxIndex-1)
		{
			index++;
			$('.simpleSlideShow').fadeOut(1000, set);
			
		}
}

function movePrevious()
{
		if (index > 0)
		{
			index--;
			$('.simpleSlideShow').fadeOut(1000, set);
		}
}