//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: 'Equipment Build', 
		title: 'Custom Corner Turn Conveyor', 
		url: 'http://www.relinc.net/products/design_build_equipment.php?page=2', 
		img: '../Pictures/slideshow/cornerturnconveyor.jpg' 
	},   
	{
		text: 'MO-7000', 
		title: 'PipeTurning',		
		url: 'http://www.relinc.net/products/mo7000.php?page=2', 
		img: '../Pictures/slideshow/mo7000.jpg'	
	} ,   
	{
		text: 'Matrix brakes', 
		title: 'Lightweight Braking option', 
		url: 'http://www.relinc.net/AdvancedMaterials/MMC/lightweight_matrix_brakes.php?page=1', 
		img: '../Pictures/slideshow/matrixbrakes.jpg' 		
	},
    {
		text: 'Scanning Electron Microscope', 
		title: 'Scanning Electron Microscope- JEOL JSM-820', 
		url: 'http://www.relinc.net/AdvancedMaterials/Analysis/scanningElectronMicroscope.php?page=1', 
		img: '../Pictures/slideshow/scanningelectronmicroscope.jpg' 
	}, 
	{
		text: 'Plates of Aluminum Alloys', 
		title: 'Plates of Aluminum Composites', 
		url: 'http://www.relinc.net/products/Al_Alloys.php?page=2', 
		img: '../Pictures/slideshow/24inchpanels.jpg'
	} ,	
	{
		text: 'Split Hopinson Pressure Bar-High strain rate testing',
		title: 'Split Hopkinson Pressure Bar',
		url: 'http://www.relinc.net/AdvancedMaterials/Analysis/splitHopkinsonBar.php?page=1',
		img: '../Pictures/slideshow/hopkinsonbar.jpg'
	},
	{
		text: 'Flourescent Penetrant Inspection',
		title: 'Non Destructive testing-FPI',
		url: 'http://www.relinc.net/AdvancedMaterials/Analysis/flourescentPenetrantInspection.php?page=1',
		img: '../Pictures/slideshow/flourescentpenetrantinspection.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=5000; // 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()
{
	//start at 0 again.
		if(currentHash>=(hashSize-1))
		{
		  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;
	for(var i=0; i<hashSize; i++)
	{
		if(currentItem==i)
			buttonHTML+='<img src="http://www.relinc.net/Pictures/slideshow/dotBlue.png" />';
		else 
			buttonHTML+='<img src="http://www.relinc.net/Pictures/slideshow/dotDark.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"]});
		
	});}


