	window.onload=function(){

		//reset timeline width based on number of pannels 
		if (document.getElementById("caseStudiesContainer")) {
			document.getElementById("caseStudiesContainer").style.width = (400*getElementsByClassName('caseStudyHomePageItem').length) + "px";
			museumScroll = new fx.divScroll('caseStudiesContainer', {duration: 1000, whichDiv: 'caseStudiesContainer'}); //width of the image must be set !important!

			if (document.getElementById('prevCaseStudy'))
				document.getElementById('prevCaseStudy').className = "visHidden";

			if (getElementsByClassName('slideCaption'))
				getElementsByClassName('slideCaption')[0].style.display = "block";

			if (getElementsByClassName('caseStudyHomePageItem').length > 1)
				document.getElementById("caseStudyNavigation").style.display = "block";
		}

	}

	/*
		Written by Jonathan Snook, http://www.snook.ca/jonathan
		Add-ons by Robert Nyman, http://www.robertnyman.com
	*/
	
	function getElementsByClassName(className, tag, elm){
		var testClass = new RegExp("(^|\s)" + className + "(\s|$)");
		var tag = tag || "*";
		var elm = elm || document;
		var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
		var returnElements = [];
		var current;
		var length = elements.length;
		for(var i=0; i<length; i++){
			current = elements[i];
			if(testClass.test(current.className)){
				returnElements.push(current);
			}
		}
		if (returnElements.length > 0) { 
			return returnElements;
		} else {
			return false;
		}
	}
	

	// Function to slide the next/previous case study into place
	// Then update the current case study number
	function changeCurrentPage(slideWidth) {

		//Retrieve the total number of case studies
		var totalCaseStudies = getElementsByClassName('caseStudyHomePageItem').length;

		//Display the total number of case studies
		document.getElementById('totalCaseStudies').innerHTML = totalCaseStudies;


		//Retrieve the previous and next page button link info
		var previousPage = document.getElementById('prevCaseStudy');
		var nextPage = document.getElementById('nextCaseStudy');

	
		//Assign an onclick value to the previous and next buttons
		//The integer is the amount of pixels the div will slide along
		previousPage.onclick=function(){updatePageNumber(slideWidth, totalCaseStudies);};
		nextPage.onclick=function(){updatePageNumber(-slideWidth, totalCaseStudies);};	

	}

	function updatePageNumber(changeCaseStudy, totalCaseStudies) {
		// Store the current case study and make it an integer
		var currentCaseStudy = (document.getElementById("currentCaseStudy").innerHTML * 1)

		// Check if the changeCaseStudy variable is positive or negative
		// NOTE: The changeCaseStudy value is the amount of pixels to slide the div left or right
		// The previous will always be positive and the next will always be negative
		if ((changeCaseStudy < 0) && (currentCaseStudy < totalCaseStudies)) {

			document.getElementById('nextCaseStudy').className = "visHidden";
			document.getElementById('prevCaseStudy').className = "visHidden";

			//If so increment the current case study by 1 and slide to the next DIV
			document.getElementById("currentCaseStudy").innerHTML = currentCaseStudy + 1;
			museumScroll.scroll(changeCaseStudy);

			// Show the new caption
			if (getElementsByClassName('slideCaption').length > 0) {
				getElementsByClassName('slideCaption')[currentCaseStudy-1].style.display = "none";
				getElementsByClassName('slideCaption')[currentCaseStudy].style.display = "block";
			}

			if((currentCaseStudy + 1) < totalCaseStudies)
			{
				setTimeout('document.getElementById("nextCaseStudy").className = "visNotHidden"',1250);
			}
			setTimeout('document.getElementById("prevCaseStudy").className = "visNotHidden"',1250);

		} else if ((changeCaseStudy > 0) && (currentCaseStudy > 1)) {
			document.getElementById('nextCaseStudy').className = "visHidden";
			document.getElementById('prevCaseStudy').className = "visHidden";

			document.getElementById("currentCaseStudy").innerHTML = currentCaseStudy - 1;
			museumScroll.scroll(changeCaseStudy);

			// Show the new caption
			if (getElementsByClassName('slideCaption').length > 0) {
				getElementsByClassName('slideCaption')[currentCaseStudy-1].style.display = "none";
				getElementsByClassName('slideCaption')[currentCaseStudy-2].style.display = "block";
			}

			if(currentCaseStudy != 2)
			{
				setTimeout('document.getElementById("prevCaseStudy").className = "visNotHidden"',1250);	
			}
			setTimeout('document.getElementById("nextCaseStudy").className = "visNotHidden"',1250);


		}

	}

function TestFileType( fileName, fileTypes ) {
	if (!fileName) return;
	
	dots = fileName.split(".")
	//get the part AFTER the LAST period.
	fileType = "." + dots[dots.length-1];
	
	if (fileTypes.join(".").indexOf(fileType) == -1) {
		alert("Please only upload files that end in types:  \n\n" + (fileTypes.join(" .")) + "\n\nPlease select a new file and try again.");
		return false;
	}
}