function toggleDescription(descriptionDiv) {
	if (!document.getElementById('dummy_in')) {
		dummyIn = document.createElement('div');
		dummyIn.id = 'dummy_in';
	}

	if (dummyIn.parentNode != descriptionCurrentlyOn.parentNode) {
		dummyIn.style.display = 'block';
		dummyIn.realDiv = descriptionDiv;
		if (dummyIn.parentNode) {
			dummyIn.parentNode.removeChild(dummyIn);
		}
		descriptionDiv.parentNode.appendChild(dummyIn);
		
		descriptionDiv.style.zIndex = -5; //get the div out of the way before displaying it on next line
		descriptionDiv.style.display = 'block'; //needs to be block before offsetHeight returns anything other than 0
		dummyIn.divHeight = descriptionDiv.offsetHeight;
		dummyIn.divWidth = descriptionDiv.offsetWidth;
		descriptionDiv.style.display = 'none';
		descriptionDiv.style.zIndex = null;
		
		var iSlide = 0;
		slideIn(iSlide);
	} else {
		descriptionDiv.style.display = 'block';
	}		
}

function slideIn(iSlide) {
	if (iSlide < dummyIn.divHeight) {
		dummyIn.style.height = iSlide.toString();
		iSlide += 8;
		setTimeout("slideIn(" + iSlide + ")",5);
	} else {
		dummyIn.realDiv.style.display = 'block';
		dummyIn.style.display = 'none';
		dummyIn.style.height = '0px';
	}
}

var funkyI = 0;
function funkyChicken() {
	if (smallImages[funkyI].tagName.toLowerCase()=='img'){
		smallImages[funkyI].oldClassName = smallImages[funkyI].className;
		smallImages[funkyI].className += ' Hovered';
		setTimeout("resetMe('"+smallImages[funkyI].id+"')",50);
	}
	funkyI ++;
	if (smallImages[funkyI]) {setTimeout('funkyChicken()',10);} else {funkyI = 0;}
}
function resetMe(imgId) {
	document.getElementById(imgId).className = document.getElementById(imgId).oldClassName;
}

function initializePortfolio() {
	if (document.getElementById("SmallPreviewImages")) { //only execute on the portfolio page
		smallImages = document.getElementById("Left").getElementsByTagName('IMG');
		for (var i=0; i<smallImages.length; i++) {
			currentImage = smallImages[i];
			
			currentImage.onclick = function() {
				if (document.getElementById(this.id + '_large') != imageCurrentlyOn) {
					thumbnailCurrentlyOn.className = null;
					thumbnailCurrentlyOn = this;
					thumbnailCurrentlyOn.oldClassName = thumbnailCurrentlyOn.className = 'On';
					
					imageCurrentlyOn.style.display = 'none';
					imageCurrentlyOn = document.getElementById(this.id + '_large');
					imageCurrentlyOn.style.display = 'block';
					
					/*remove the old description*/
					descriptionCurrentlyOn.style.display = 'none';
					
					/*display the new description*/
					descriptionCurrentlyOn = document.getElementById(this.id + '_description');
					toggleDescription(descriptionCurrentlyOn);
					
				}
			}
			
			var bigImage = document.getElementById(currentImage.id + '_large');
			bigImage.onmouseover = function(){document.onkeypress = function(e) {
				if(!e){var e = window.event;}if((e.which == 74 || e.keyCode == 74) && e.shiftKey) {funkyChicken();}
			}}
			bigImage.onmouseout = function(){document.onkeypress=null}
			
			currentImage.onmouseover = function() {
				this.oldClassName = this.className;
				this.className += ' Hovered';
			}
			
			currentImage.onmouseout = function() {
				this.className = this.oldClassName;
			}
		}
		
		//var turnOnIndex = Math.floor(Math.random()*smallImages.length);
		var turnOnIndex = 0;
		thumbnailCurrentlyOn = smallImages[turnOnIndex];
		thumbnailCurrentlyOn.className = 'On';
		imageCurrentlyOn = document.getElementById(smallImages[turnOnIndex].id + '_large');
		imageCurrentlyOn.style.display = 'block';
		descriptionCurrentlyOn = document.getElementById(smallImages[turnOnIndex].id + '_description');
		toggleDescription(descriptionCurrentlyOn);
	}
}
initialize.extend(initializePortfolio);