window.addEvent('domready',function(){
		
		var AutoPlay 		= true;
		var Playing			= true;
		var slideDuration 	= 6500; //microsecs
		var lightBox 		= $$('#lightbox'); //where it plays
		//var slides 		= ''; //our src images!
		var currentIndex 	= 0; //start point
        var preLoadQty		= 2;
		var interval;
		var images 		= $$('#lightbox img');
		
		
		images.each(function(img,i){ 
            
			//img.set('data-original',img.get('src') ).set('src',''); //set this for all just to be safe!
			
			if(i == 0) { //show our first image!
				img.addClass('hero');
			
			}
			//try on load event handler
			img.addEvent('load',function(){
				detectOrientation(img);
			});
			
		});
		
			
		var lazyLoad = function(i){
			//check if image already loaded?
			//how to access this.loaded?
			var t=( (i + preLoadQty) > images.length )? images.length : (i + preLoadQty);
			for (i; i < t; i++){
				images[i].set('src',images[i].get('data-original') );
//assign the correct orientation class

			}
		}
		
		var gotoPrevious = function(){
			lastIndex = currentIndex;
			if (currentIndex == 0 ) { 
			 	currentIndex = images.length -1;
			}else{
				currentIndex--;
			}
			updateLightbox(lastIndex);
			
		}
		
		var gotoNext = function(){
			lastIndex = currentIndex;
			
			if (currentIndex == (images.length - 1) ){
				currentIndex = 0;
			}else{ 
			currentIndex++;
			}
			updateLightbox(lastIndex);
			
		}
		
		var updateLightbox = function(lastIndex){
			images[lastIndex].fade(0).removeClass('hero');
//do we lazyLoad now!
						lazyLoad(currentIndex); //wait for this to load before firing the class add and fade?!
                        images[currentIndex].addClass('hero');
//check to see if image has loaded somehow?
(function(){ images[currentIndex].fade(1);}).delay(500); // slow down the fade in so all is set
			//set lightbox portrait class

		};
	
		
		var detectOrientation = function(img){
			if (Browser.Engine.trident){
				var h = img.height;
				var w = img.width;
			}else{
				var h = img.naturalHeight;
				var w = img.naturalWidth;
			}
			var r =  h / w;
			var c= ( r < 1)? 'landscape': 'portrait';
	
			img.set('alt','h is'+h+' w is '+w+ 'r is '+ r);	//comment this off when stable!		
			img.addClass(c);
		}

		this.addEvent('load',function(){
			
			
		lazyLoad(currentIndex);
			
		images[currentIndex].fade(1);
		
			if (AutoPlay == true){
			//start scrolling through
			Playing = true;
			startShow();
			//interval = gotoNext.periodical(slideDuration);
		} //slideShowPlay IF
		
		});
		

		var startShow   = function() { 
			interval    = gotoNext.periodical(slideDuration); 
		};
		
		
	});
