///////////////////////////
/// EXPANDING DIVS
///////////////////////////


i=0;
finalHeight = 0;
listHolderArray = document.getElementsByTagName('ul');
originalHeightArray = new Array();
allShowing = 0;
stepInterval = 1;
increment = 20;
slideSpeed = 4000;
	

function initialize_collapsingDivs(openDiv) {	
	for (k=0;k<listHolderArray.length;k++) {
		listHolderArray[k].style.display = "block";
		originalHeightArray[listHolderArray[k].id] = listHolderArray[k].offsetHeight;
		if (openDiv!=listHolderArray[k].id) listHolderArray[k].style.display = "none";
	}

}


function showList(whichList) {
	if (document.getElementById(whichList).style.display == "block") {
		  document.getElementById(whichList).style.opacity = 0;
		  document.getElementById(whichList).style.filter='alpha(opacity=0)';
		  closeSteps = setInterval("stepClosed('"+whichList+"')",stepInterval);
	} else {
		i=0;
		for (j=0;j<listHolderArray.length;j++) {
			listHolderArray[j].style.display = "none";
		}
		document.getElementById(whichList).style.display = "block";
		  document.getElementById(whichList).style.opacity = 0;
		  document.getElementById(whichList).style.filter='alpha(opacity=0)';
		finalHeight = originalHeightArray[whichList];
		document.getElementById(whichList).style.height =  i + "px";
		openSteps = setInterval("stepOpen('"+whichList+"')",stepInterval);
	}
}


function stepOpen(whichList) {
	if (i>=finalHeight) {
		clearInterval(openSteps);
		  document.getElementById(whichList).style.opacity = 1;
		  document.getElementById(whichList).style.filter='alpha(opacity=100)';
	} else {
		document.getElementById(whichList).style.height = i + "px";
		i = i+increment;
	}
}

function stepClosed(whichList) {
	if (i<=0) {
		document.getElementById(whichList).style.display = "none";
		clearInterval(closeSteps);
	} else {
		document.getElementById(whichList).style.height = i + "px";
		i = i-increment;
	}
}





///////////////////////////
/// SET IMAGE SIZE
///////////////////////////


function setSize(fadeMe) {
	if (document.getElementById('img_holder')) setIt(fadeMe);
	
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myHeight = document.body.clientHeight;
  }
  
	if (document.getElementById('footer')) document.getElementById('footer').style.top = myHeight - 120 +"px";
}

matteStep = 0;
function resizeMatte(goal,padding) {
	document.getElementById('img_matte').style.width = goal+"px";
}


function setIt(fadeMe) {

  mattePadding = 15;
  padding = 20;
  navWidth = document.getElementById('left_nav').offsetWidth;
  navHeight = document.getElementById('left_nav').offsetHeight;
  
  
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
  }
 // window.alert( 'Width = ' + myWidth );
 // window.alert( 'Height = ' + myHeight );
  
  if (currentPhoto<0) {
  	origPhoto = photos.length-1;
  } else {
  	origPhoto = currentPhoto;
  }
  
  
  origWidth = photoWidths[origPhoto];
  origHeight = photoHeights[origPhoto]; 
    
  myWidth = myWidth - (padding*2) - navWidth;
  myHeight = myHeight - document.getElementById('header').offsetHeight - (padding*2);
  
  goal=0;
  
  if ( origHeight/origWidth > myHeight/myWidth ) {
	myWidth = Math.round((myHeight*origWidth) / origHeight);
	goal = Math.round(myWidth-(mattePadding*2));
	resizeMatte(goal,mattePadding);
	document.getElementById('img_holder').style.width = goal+"px";
  } else {
	goal = Math.round(myWidth-(mattePadding*2));
	resizeMatte(goal,mattePadding);
	document.getElementById('img_holder').style.width = goal+"px";
  }
  
  
  if (fadeMe==1) {
  	currentOpacity=0;
	fadeIn = setInterval("fadeOpen()",2);
 }
  
}




///////////////////////////
//NEXT & PREVIOUS
///////////////////////////


function getNext() {
	if (nextSlide) clearTimeout(nextSlide);
	
	document.getElementById("img_holder").style.opacity = 0;
	document.getElementById("img_holder").style.filter='alpha(opacity = 0)';
	
	document.getElementById("previous_button").style.visibility = "visible";
	if (currentPhoto<photos.length-1) {
		currentPhoto++;
		showImage(currentPhoto);
	}
	if (currentPhoto==photos.length-1) {
		if (slideShowRunning) {
			currentPhoto=-1;
		} else {
			document.getElementById("next_button").style.visibility = "hidden";
		}
	}
	
}


function getPrev() {
	 if (nextSlide) clearTimeout(nextSlide);

	document.getElementById("img_holder").style.opacity = 0;
	document.getElementById("img_holder").style.filter='alpha(opacity = 0)';
	
	document.getElementById("next_button").style.visibility = "visible";
	if (currentPhoto>0) {
		currentPhoto--;
		showImage(currentPhoto);
	}
	if (currentPhoto==0) document.getElementById("previous_button").style.visibility = "hidden";
	
}



///////////////////////////
//SHOW DISPLAY IMAGE
///////////////////////////

showLoop = 0;
currentOpacity = 0;
slideShowRunning=0;
nextSlide = 0;
fadeIn = 0;

function showImage(newPhoto) {
	
	if (fadeIn) clearInterval(fadeIn)
	currentPhoto = newPhoto;
	isWaiting=0;
	
	document.getElementById("currentCount").innerHTML=currentPhoto+1;
	
	if (showLoop) clearInterval(showLoop);
	preloader = new Image();
	preloader.src = "/uploads/"+photos[currentPhoto]+".jpg";
	loaderWidth = 5;
	showLoop = setInterval("showMe("+currentPhoto+")",100);
		
	document.getElementById("next_button").blur();
	document.getElementById("previous_button").blur();
	
}
	
 
function showMe(currentPhoto) {
	if (loaderWidth<95) loaderWidth++;
	document.getElementById("loader").style.width=loaderWidth+"%";
	if (preloader.complete) {
		clearInterval(showLoop);
		document.getElementById("stretchy").src="/uploads/"+photos[currentPhoto]+".jpg";
		document.getElementById("loader").style.width="100%";
		currentOpacity=0;
		fadeIn = setInterval("fadeOpen()",2);
		
		if (slideShowRunning) {
			nextSlide = setTimeout("getNext()",slideSpeed);
		}
	}
}





///////////////////////////
// FADE UP
///////////////////////////

function fadeOpen() {
	
	document.getElementById("img_holder").style.opacity=currentOpacity;
	document.getElementById("img_holder").style.filter='alpha(opacity = ' + currentOpacity*100 +')';
	if (currentOpacity>=1) {
		clearInterval(fadeIn);
		
		document.getElementById("img_holder").style.opacity= 1;
		document.getElementById("img_holder").style.filter='alpha(opacity = 100)';
	} else {
		currentOpacity+=.025;
	}
	
}




///////////////////////////
// SLIDESHOW
///////////////////////////


function slideshow() {
	if (slideShowRunning) {
		clearTimeout(nextSlide);
		slideShowRunning=0;
		document.getElementById("slideshow").innerHTML = "play slideshow";
	} else {
		slideShowRunning=1;
		getNext();
		document.getElementById("slideshow").innerHTML = "pause slideshow";
	}
}

