//Images and related information to include in the marquee
//BE SURE TO UPDATE THE CSS MARQUEE BACKGROUND IN /inc/ekuShort.css TO MATCH THE FIRST IMAGE
var dataSource = [    
	{
		text: '<b>New Student Orientation</b>', 
		title: 'New Student Orientation', 
		url: 'http://www.firstyear.eku.edu/orientation/', 
		img: 'http://www.eku.edu/img/marquees/orientation2009-2.jpg' 
	},   
    {
		text: 'What if… I could distinguish myself nationally?', 
		title: 'What if… I could distinguish myself nationally?', 
		url: 'http://www.prm.eku.edu/ekunews/?module=0&article=1037', 
		img: 'http://www.eku.edu/img/marquees/fotina_lefta936x194.jpg' 
	},   
	{
		text: 'What if... I left my comfort zone to explore new places?', 
		title: 'What if... I left my comfort zone to explore new places?', 
		url: 'https://web4s.eku.edu/pls/prod/twbkwbis.P_GenMenu?name=app_menu', 
		img: 'http://www.eku.edu/img/marquees/springTreeStudents.jpg' 		
	},
	{
		text: '<span style="margin-left: -5px; width: 300px;">What if... I pushed myself further</span>', 
		title: 'What if... I pushed myself further than I ever dreamed possible?',		
		url: 'https://web4s.eku.edu/pls/prod/twbkwbis.P_GenMenu?name=app_menu', 
		img: 'http://www.eku.edu/img/marquees/afterdancetheatreconcert-spring2009-900x194-2.jpg'	
	}    
];

//Set which image to stop on when interval is finished
//Must be an integer between 0 and the dataSource array size
 var stopOn=0;
 
//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(stopOn);
		  currentHash=stopOn;
		}		
		else if(currentHash<(hashSize-1))
		{
			//show next image
			currentHash++;
			showImage(currentHash);	
		}	
		else //do nothing
		{}
	

}
function showImage(currentItem)
{
	var buttonHTML="";

	//buttonHTML+=leftButton;
	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" />';
	}
	


	//To add the fade effect exchange the two following lines of code
	//$("#marquee").fadeOut('fast', function() 
	$("#marquee").fadeIn('fast', function() 
	{
		$("#marquee").css("background-image", "url("+dataSource[currentItem]["img"]+")").fadeIn('fast');
		$("#marqueeBarLeft p").html(dataSource[currentItem]["text"]+"").fadeIn('fast');
		$("#imageDotRow").html(""+buttonHTML+"").fadeIn('fast');
		//$("#imageOptions").html(buttonHTML+"").fadeIn('fast');
		
		//Click Events for Marquee Image
		$("#clickableMarqueeLink").attr("href", dataSource[currentItem]["url"]);
		$("#clickableMarqueeLink").unbind("click");
		$("#clickableMarqueeLink").click(function () { 	
					trackThisLink=''+dataSource[currentItem]["img"].substr(dataSource[currentItem]["img"].lastIndexOf("/"))+'';	
					pageTracker._trackPageview('/marquee'+trackThisLink+'');
					window.location=""+dataSource[currentItem]["url"]+""; 																				
				});		
		$("#clickableMarqueeLink").attr("title", function () { return dataSource[currentItem]["title"]});
		
		//Remove Apply Now Click Events for Specific Marquee Image
		if(dataSource[currentItem]["img"]=="http://www.eku.edu/img/marquees/orientation2009-2.jpg")
		{
			$("#applyNowLink").hide();
			$("#clickableMarqueeLink").width("936px");
		}
		else 
		{
			$("#applyNowLink").show();
			$("#clickableMarqueeLink").width("750px");
		}
		
		
		//Click Events for Bar Text
		$("#marqueeBarLeft p").unbind("click");
		$("#marqueeBarLeft p").click(function () { 	
					trackThisLink=''+dataSource[currentItem]["img"].substr(dataSource[currentItem]["img"].lastIndexOf("/"))+'';	
					pageTracker._trackPageview('/marqueeText'+trackThisLink+'');
					window.location=""+dataSource[currentItem]["url"]+""; 																					
				});		
		$("#marqueeBarLeft p").attr("title", function () { return dataSource[currentItem]["title"]});

	});
	

}


