// function showPic(whichpic) {
//   if (!document.getElementById("placeholder")) return true;
//   var source = whichpic.getAttribute("href");
//   var placeholder = document.getElementById("placeholder");
//   placeholder.setAttribute("src",source);
// 	var source = whichpic.getAttribute("class");
// 	var imageholder = document.getElementById("contents-image");
// 	  imageholder.setAttribute("class",source);
//   if (!document.getElementById("caption")) return false;
//   if (whichpic.nextSibling) {
//     var text = whichpic.nextSibling.childNodes[0].nodeValue;
// 	var text1 = whichpic.nextSibling.childNodes[2].nodeValue;
// 	var text2 = whichpic.nextSibling.childNodes[4].nodeValue;
//   } else {
//     var text = "";
// 	var text1 = "";
// 	var text2 = "";	
//   }
//   var title = document.getElementById("caption");
//   var desc = document.getElementById("desc");
//   var materials = document.getElementById("materials");
//   if (title.firstChild.nodeType == 3) {
//     title.firstChild.nodeValue = text;
//     desc.firstChild.nodeValue = text1;
//     materials.firstChild.nodeValue = text2;
//   }
//   return false;
// }

// function prepareGallery() {
//   if (!document.getElementsByTagName) return false;
//   if (!document.getElementById) return false;
//   if (!document.getElementById("imagegallery")) return false;
//   var gallery = document.getElementById("imagegallery");
//   var links = gallery.getElementsByTagName("a");
//   for ( var i=0; i < links.length; i++) {
//     links[i].onclick = function() {
//       return showPic(this);
// 	}
//     links[i].onkeypress = links[i].onclick;
// 	links[i].onmouseover = links[i].onclick;
//   }
// }


// function addLoadEvent(func) {
//   var oldonload = window.onload;
//   if (typeof window.onload != 'function') {
//     window.onload = func;
//   } else {
//     window.onload = function() {
//       oldonload();
//       func();
//     }
//   }
// }

// addLoadEvent(prepareGallery);

$(document).ready( function () {
    $('#imagegallery').children('li').children('a').children('img').mouseover( function() {
	var parts = $(this).attr( 'src' ).split( '-' );
	var extParts = parts[1].split( '.' );
	var imgSrc = parts[0] + '.' + extParts[1];
	var orientation = $(this).parent().attr( 'class' );

	if( $('#image-holder').children('img').attr( 'src' ) != imgSrc ) {
	  $('#image-holder').children('img').fadeTo( 'fast', 0.01, function() {
	      $('#image-holder').children('img').attr( 'src', imgSrc );

	      $('#image-holder').children('img').load( function() {
		  $('#image-holder').children('img').unbind( 'load' );
		  $('#image-holder').children('img').attr( 'class', orientation );
		  $('#image-holder').children('img').fadeTo( 'fast', 1 );
		} );
	    } );
	}
      } );
  } );
