/* ||||||||||||||||||||||||||||||||||||||||||||||||| PIECE UNORDERED LIST ||||||||||||||||||||||||||||||||||||||||||||||||| */

function establishFolio( ulID ) {

	//Process each element within the unordered list
	for(var count = 0; count < this.document.getElementById(ulID).children.length; count++) {
		this.caseStudy = this.document.getElementById(ulID).children[count].children[0];
		this.count = count;
		this.caseStudy.setAttribute('alt', 'Study #' + this.count);
		
		this.caseStudy.onmouseover = 
			function() { 
				this.alt = this.getAttribute('alt').substr(7,2);
				changeFolioState("onmouseover", this.alt, this.nextSibling);
				};
			
		this.caseStudy.onmouseout = 
			function() { 
				this.alt = this.getAttribute('alt').substr(7,2);
				changeFolioState("onmouseout", this.alt, this.nextSibling);
				};
		}
	}
	
function changeFolioState( mouseEvent, idNumber, whiteDiv ) {
	this.caseStudy = whiteDiv;
	this.count = idNumber;
	
	if (mouseEvent === "onmouseover") {  $(this.caseStudy).stop().animate({opacity: 0}, 150, "swing"); }
	else {  $(this.caseStudy).stop().animate({opacity: 1}, 150, "swing"); }
	}
	

/* ||||||||||||||||||||||||||||||||||||||||||||||||| SLIDESHOW ||||||||||||||||||||||||||||||||||||||||||||||||| */

function nextSlide() {
	var $active = $('#slideshow IMG.active');

	if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
	var $next =  $active.next().length ? $active.next()
	: $('#slideshow IMG:first');

	$active.addClass('last-active');
	$next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 400, "swing", function() { $active.removeClass('active last-active'); });
	}
	
function prevSlide() {
	var $active = $('#slideshow IMG.active');

	if ( $active.length == 0 ) $active = $('#slideshow IMG:first');
	var $prev =  $active.prev().length ? $active.prev()
	: $('#slideshow IMG:last');

	$active.addClass('last-active');
	$prev.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 400, "swing", function() { $active.removeClass('active last-active'); });
	}
	
function slideshow() {
	var createController = document.createElement('div');
	createController.setAttribute("id", "controller");
	createController.innerHTML = '<a href="#" id="nextslide"></a><a href="#" id="prevslide"></a>';
	document.getElementById("imgContainer").appendChild(createController);

	var revolvingSlides = setInterval( "nextSlide()", 5000 ); 

	var slideshowFormat = document.getElementById("imgContainer");
	var controller = document.getElementById("controller");
	slideshowFormat.onmouseover = function() { $(controller).stop().animate({opacity: 100}, 400, "swing"); }
	slideshowFormat.onmouseout = function() { $(controller).stop().animate({opacity: 0}, 150, "swing"); }

	var next = document.getElementById("nextslide");
	next.onclick = function() { 
		clearInterval(revolvingSlides);
		nextSlide();
		};
		
	var prev = document.getElementById("prevslide");
	prev.onclick = function() { 
		clearInterval(revolvingSlides);
		prevSlide();
		};
	}


/* ||||||||||||||||||||||||||||||||||||||||||||||||| ONLOAD ||||||||||||||||||||||||||||||||||||||||||||||||| */

window.onload = function() {
	if (document.getElementById("one-column")) { establishFolio("one-column"); }
	if (document.getElementById("two-column")) { establishFolio("two-column"); }
	if (document.getElementById("three-column")) { establishFolio("three-column"); }
	if (document.getElementById("slideshow")) { slideshow(); }
	}