// JavaScript Document
$(document).ready(init);
var items, CurrentImage, CurrentTitle, CurrentDescription, Next, Previous, CurrentLink;
var index, maxIndex;
var images, titles, descriptions, links;
// UPDATE FOR TIMER 11.19.2010 Todd Eberwine
var IsAutoPlay, ImageSpeed, IsLoop;
var to;
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', moveNextBtn);
	$('.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);
    
    
    if (IsAutoPlay == "True")
    {
        if (index == maxIndex - 1) {
            if (IsLoop == "True") {                
                index = 0;
                //$('.simpleSlideShow').fadeOut(1000, set);
              to =  setTimeout("moveNextLoop()", ImageSpeed);
            }
        }
        else {
          to =  setTimeout("moveNext()", ImageSpeed);            
        }
    }

}

function setVars(a, s, l) {
    
    IsAutoPlay = a;
    IsLoop = l;
    ImageSpeed = s;
    
    
    //alert(IsAutoPlay + " " + IsLoop + " " + ImageSpeed);
}

function moveNextBtn() {
    if (index < maxIndex - 1) 
    {

        clearTimeout(to);
        index++;
        $('.simpleSlideShow').fadeOut(1000, set);

    }
}

function moveNextLoop() {
    if (index < maxIndex - 1) {
        
        $('.simpleSlideShow').fadeOut(1000, set);
    }
}

function moveNext()
{
    if (index < maxIndex - 1) 
    {
        index++;
        $('.simpleSlideShow').fadeOut(1000, set);        
    }		
}

function movePrevious()
{
		if (index > 0)
		{
		    clearTimeout(to);
			index--;
			$('.simpleSlideShow').fadeOut(1000, set);
		}
}
