	dojo.require("dijit.dijit");
	dojo.require("dijit.Dialog");
	
	var photoURLS = [
	  				"1-20100517.jpg",  	"2-20100517.jpg",  	"3-20100517.jpg",  	"4-20100517.jpg",  	"6-20100517.jpg",
	  				"7-20100517.jpg",  	"8-20100517.jpg",  	"9-20100517.jpg",  	"10-20100517.jpg",  "11-20100517.jpg",
	  				"12-20100517.jpg",  "13-20100517.jpg",  "14-20100517.jpg",	"15-20100517.jpg",	"16-20100517.jpg",
	  				"17-20100517.jpg", 	"1.jpg",  					"2.jpg",  					"3.jpg",  					"4.jpg",  					"5.jpg",	"Door.jpg",
	  				"Glade.jpg",  			"RipRapTrees.jpg",	"Tree.jpg",  				"sumac.jpg",  			"6.jpg",  					"7.jpg",
	  				"7a.jpg",  			    "8.jpg",  					"9.jpg",  					"10.jpg",  					"11.jpg",  					"12.jpg",	"12a.jpg",
	  				"13.jpg",  			    "14.jpg",  					"15.jpg",  					"16.jpg",  					"17.jpg",  					"18.jpg",	"19.jpg",
	  				"20.jpg",  					"21.jpg",  					"22.jpg",  					"23.jpg",  					"24.jpg",  					"25.jpg",	"26.jpg",
	  				"27.jpg", 					"28.jpg",  					"29a.jpg",  				"30a.jpg",  				"31a.jpg",  				"32a.jpg",	"33a.jpg",
	  				"29.jpg", 					"30.jpg",  					"31.jpg",  					"32.jpg",  					"34.jpg",  					"35.jpg",	"36.jpg",
	  				"37.jpg",  					"39.jpg",  					"40.jpg"
		];
		
	function showPhotoDialog(imageFile) {
		photoDialog.attr("content", "<img src='images/" + imageFile + "'>");
		photoDialog.show();
	};
	
	function hideAll(){
		allContainers = [
			"photoContainer",
			"aboutContainer",
			"supportContainer",
			"contactContainer",
			"exhibitionContainer",
			"instructContainer"
		];	
		
		for(i=0; i<allContainers.length; i++){
			dojo.byId(allContainers[i]).style.display = "none";
		};
	};
	
	function showContainer(container){
		hideAll();
		dojo.byId(container+'Container').style.display = "block";
	};

	function showInstruct(){
		hideAll();
		dojo.byId('mainTable').style.display = "block";
		document.body.style.backgroundColor = 'black';
		showContainer('instruct');
	};
	
	generateNavigation = dojo.hitch(this, function(){
		var html = "<center> <table> <tr> "
		for(i=0;i<this.photoQueue.getCount();i++){
			html += 
			"<td id='navItem_" + i + "' " 
				+ "style='border-left: 1px solid #777777; border-right: 1px solid #777777; width: 10px; height: 10px;'"
				+ "onClick='showPhoto(" + i + ");'>"
			+ "</td> ";
		}
		html += " <tr> <table> </center>";
		return html;
	});
	
	function getPictureHeight(){
		pictureHeight = dijit.getViewport().h - 70;
		if (pictureHeight < 480){
			return 480;
		} else if (pictureHeight > 577) {
			return 577;
		}
		
		return pictureHeight;	  
	}
	
	dojo.addOnLoad(dojo.hitch( this, function(){
		
		photoDialog = new dijit.Dialog();
		photoQueueParentNode = document.getElementById("photos");
    this.slider = dojo.byId('slider');

    pictureHeight = null;
    photoProperties = null;
		sliderFadeMs = 2 * 1000; //2 seconds
		sliderStayMs = 4 * 1000;
		    
		photoProperties = {
			onclick: function(){
				window.showNextPhoto();
			},
			style: {
				height: pictureHeight
			}
		};
		
		this.photoQueue.initialize(photoQueueParentNode, photoURLS, photoProperties, "images/gallery/");

    // set up slider
		this.slider.innerHTML = generateNavigation();
		this.fadeOutSlider = dojo.fadeOut({node: "slider",duration: sliderFadeMs});
		this.fadeInSlider = dojo.fadeIn({node: "slider",duration: sliderFadeMs});
		this.fadeInOutSlider = function(){
			clearTimeout(this.sliderFadeTimeoutId);
		 	this.fadeInSlider.play();
			this.sliderFadeTimeoutId = setTimeout(function(){
				this.fadeOutSlider.play();
			}, sliderStayMs);
		};				
		dojo.byId('navItem_' + this.photoQueue.getCurrentIndex()).style.backgroundColor = "#777777";
		dojo.byId('navTableSpaceMaker').style.height = getPictureHeight() + 48 - 345;
		
		this.showNextPhoto = dojo.hitch(this, function(){
			dojo.byId('navItem_' + this.photoQueue.getCurrentIndex()).style.backgroundColor = "black";
			this.photoQueue.advance();
			dojo.byId('navItem_' + this.photoQueue.getCurrentIndex()).style.backgroundColor = "#777777";
		});

		this.showPreviousPhoto = dojo.hitch(this, function(){
			dojo.byId('navItem_' + this.photoQueue.getCurrentIndex()).style.backgroundColor = "black";
			this.photoQueue.rewind();
			dojo.byId('navItem_' + this.photoQueue.getCurrentIndex()).style.backgroundColor = "#777777";
		});

		showPhoto = dojo.hitch(this, function(index){
			dojo.byId('navItem_' + this.photoQueue.getCurrentIndex()).style.backgroundColor = "black";
			this.photoQueue.jump(index);
			dojo.byId('navItem_' + this.photoQueue.getCurrentIndex()).style.backgroundColor = "#777777";
		});

		// mouse move shows slider for a bit
		document.onmousemove = dojo.hitch(this, function(){
			this.fadeInOutSlider();
		});
		
		// key event triggers slider
		dojo.connect(document, "onkeypress", this, function(event){
			var keyCode = event.keyCode || event.keyChar;
			switch(keyCode){
				
				// go to next slide if possible for down or right arrow keys
				case 39:
					if (dojo.byId('photoContainer').style.display != "none"){
						this.fadeInOutSlider();
						this.showNextPhoto();
					}
					break;
					
				// go to previous slide if possible for up or left arrow keys
				case 37:
					if (dojo.byId('photoContainer').style.display != "none"){
						this.fadeInOutSlider();
						this.showPreviousPhoto();
					}
					break;
					
			}
		});
		
    this.photoQueue.jump(0);

	 }));
