// Dom Scripting, Jeremy Keith, Friends of Ed 2005 / http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
// - - - - - - - - - -


$(document).ready(
	function() {
		// hide the placeholders
		$('#soundlinesimages').css("opacity",0);		
	}			  
);

var usedIndices = new Array();

function onLoaded(){
	// JavaScript Document
	var allImages = new Array();
	
	for(i=0; i<40; i++){
		var imgString = imageSource(i+1);
		allImages[i] = imgString;
	}
	
	// randomly populate with new images
	$('#soundlinesimages').find('img').each(function(index) {
		var newImgIndex = getUnusedImageIndex();
		var newImage = imageSource(newImgIndex);
		
		usedIndices[index] = newImgIndex;
		$(this).attr("src", newImage);
	});
	// fade in the images
	$('#soundlinesimages').delay(500).fadeTo(500,1);

	
	

};

function getUnusedImageIndex() {
	newIndex = Math.ceil(Math.random()*40);
	while($.inArray(newIndex, usedIndices)>=0){
		newIndex = Math.ceil(Math.random()*40);
	}
	return newIndex;
};

function imageSource(number) {
	return "images/1_" + number + ".jpg";
}

addLoadEvent(onLoaded);
