//Images and related information to include in the marquee
var dataSource = [   
	{
		text: 'Imagine... a cast of characters to broaden my horizons.', 		
		title: 'Imagine... a cast of characters to broaden my horizons.', 
		url: 'http://www.cas.eku.edu/', 
		img: 'http://www.cas.eku.edu/img/marquee/theatre.png',
		thumb: 'http://www.cas.eku.edu/img/photos/marquee/thumbs/theatre_thumb.png',
		top: '-52'
	},  
	
	{
		text: 'Discover... the possibilites through science.  ', 
		title: 'Discover...  the possibilities through science.', 
		url: 'http://www.cas.eku.edu/', 
		img: 'http://www.cas.eku.edu/img/marquee/chemistry.png',
		thumb: 'http://www.cas.eku.edu/img/photos/marquee/thumbs/chemistry_thumb.png',		
		top: '-49' 
	},	
	
	
	{
		text: 'Ignite... a desire for learning new things.  ', 
		title: 'Ignite... a desire for learning new things. ', 
		url: 'http://www.cas.eku.edu/', 
		img: 'http://www.cas.eku.edu/img/marquee/forensics.png',
		thumb: 'http://www.cas.eku.edu/img/photos/marquee/thumbs/microscope_thumb.png',		
		top: '-45' 
	},	
	
	{
		text: 'Express... myself through the performing arts. ', 
		title: 'Express... myself through the performing arts. ', 
		url: 'http://www.cas.eku.edu/', 
		img: 'http://www.cas.eku.edu/img/marquee/music.png',
		thumb: 'http://www.cas.eku.edu/img/photos/marquee/thumbs/guitar_thumb.png',		
		top: '-42'
	}
];

//Preload Images
var preloaded = new Array();
function preload_images() {
    for (var i = 0; i < dataSource.length; i++){
        preloaded[i] = document.createElement('img');
        preloaded[i].setAttribute('src',dataSource[i]["img"]);
    };
};
preload_images();

var hashSize=dataSource.length;
var currentHash=0;
var intval="";
var timeForInterval=10000; // 1000 = 1 second


$(function()
{    


	$("#nextRight").click(function()
    {
		//stop interval		
		if(intval!="")
		{
          window.clearInterval(intval);	
		}
        //var imageSource = $(this).children("img").attr("src");
		if(currentHash<(hashSize-1))
		{
			currentHash++;
			showImage(currentHash);	
		}
        //return false;
     });

	$("#nextLeft").click(function()
    {
		//stop interval
		if(intval!="")
		{
          window.clearInterval(intval);	
		}		
        //var imageSource = $(this).children("img").attr("src");
		if((currentHash-1)>=0)
		{
			currentHash--;	
			showImage(currentHash);	
		}
        //return false;
     });
 
});


function startRotation()
{
	showImage(0);
    intval=window.setInterval("nextImage()",timeForInterval);
}

function nextImage()
{
		//clear hash after one loop
		if(currentHash>=(hashSize-1))
		{
          window.clearInterval(intval);	
		  //showImage(0);
		  //currentHash=0;
		}		
		else if(currentHash<(hashSize-1))
		{
			//show next image
			currentHash++;
			showImage(currentHash);	
		}	
		else //do nothing
		{}
	

}
function showImage(currentItem)
{
	var buttonHTML="";

	//buttonHTML+=leftButton;
	/* Normal Routine
	for(var i=0; i<hashSize; i++)
	{
		if(currentItem==i)
			buttonHTML+='<img src="http://www.eku.edu/img/whiteMarqueeButton.png" />';
		else 
			buttonHTML+='<img src="http://www.eku.edu/img/darkMarqueeButton.png" />';
	}
	*/
	
	buttonHTML
	for(var i=0; i<hashSize; i++)
	{
		if(currentItem==i)
			buttonHTML+='<a class="marqThumbCurrent" style="float: left; background: url('+dataSource[i]["thumb"]+'); background-position: center; " onclick="showMarqThumb('+i+');"></a>';
		else 
			buttonHTML+='<a class="marqThumb" style="float: left; background: url('+dataSource[i]["thumb"]+'); background-position: center;" href="javascript:showMarqThumb('+i+');  "></a>';
	}

	//To add the fade effect exchange the two following lines of code
	//$("#marquee").fadeOut('fast', function() 
	$("#subMarquee").fadeIn('fast', function() 
	{
		$("#subMarquee").attr("src",dataSource[currentItem]["img"]).fadeIn('fast');
		$("#subMarquee").css('margin-top', dataSource[currentItem]['top']+"px");	
		//$("#subMarquee").css("background-image", "url("+dataSource[currentItem]["img"]+")").fadeIn('fast');
	
		//$("#marqueeBarLeft p").html(dataSource[currentItem]["text"]+"").fadeIn('fast');
		$("#imageDotRow").html(""+buttonHTML+"").fadeIn('fast');



		//$("#clickableMarqueeLink").attr("href", dataSource[currentItem]["url"]);
		
		//$("#clickableMarqueeLink").attr("title", function () { return dataSource[currentItem]["title"]});

		$("#subMarquee").click(function () { window.location=""+dataSource[currentItem]["url"]+"";});		
		$("#subMarquee").attr("title", function () { return dataSource[currentItem]["title"]});
		
		if(dataSource[currentItem]["url"]!="")
		{			
			$("#subMarquee").css('cursor', 'pointer');
		}

	});

}
function showMarqThumb(specificThumb)
{
	//stop interval		
	if(intval!="")
	{
        window.clearInterval(intval);	
	}
	showImage(specificThumb);
	currentHash=specificThumb;
}

