var screenshots = {
	pos: 0,
	max: 0,
	init: function() {
		items = $('slider_top20').select('img');
		items.each(function(i,index){
			Event.observe(i, 'click', function() {
				//adding/removing show class name from scroller_imgs
				$$('.picked')[0].removeClassName('picked');
				items = $('slider_top20').select('li');
				items.each(function(li, liIndex){
					if (index == liIndex) {
						li.addClassName('picked');
					}
				});
				
				
				//adding/removing show class name from big_pics
				$$('.show')[0].removeClassName('show');
				imgs = $$('.mainbdy');
				imgs.each(function(img, imgIndex){
					if (index == imgIndex) {
						img.addClassName('show');
					}
				});
			});
		});
		
		screenshots.max = parseInt($$('.top_feed').length) - parseInt(1);
		screenshots.changeTopFeature();
		
	},
	shift: function(galID,direction,totalImgs,imgsPerPage) {
		var sliderID = "slider_" + galID;
		var pixelsPerImg = 198;
		var pixelsToShift = pixelsPerImg * imgsPerPage;
		var maxShift = (totalImgs * pixelsPerImg) * -1;		
		if(direction == "right"){
			var finalShift = parseInt($(sliderID).style.left) - parseInt(pixelsToShift);
			var checker = parseInt(finalShift) - parseInt(pixelsToShift);
			
			if (checker > maxShift) {
				if(finalShift > maxShift){
					$(sliderID).morph('left: ' + finalShift + "px", {duration: 1});
				}
			}
			
			
		}
		if(direction == "left"){
			var finalShift = parseInt($(sliderID).style.left) + parseInt(pixelsToShift);
			if(finalShift <= 0){
				$(sliderID).morph('left: ' + finalShift + "px", {duration: 1});
			}
		}
	},
	changeTopFeature: function() {
		window.setTimeout(function() {
			boxes = $$('.top_feed');
			boxes.each(function(i,index) {
				if (screenshots.pos == index) {
					new Effect.Opacity(i, {from: 1.0, to: 0.0, duration: 4.5});
				}
				
			});
			
			screenshots.pos++
			if (screenshots.pos > screenshots.max) {
				screenshots.pos = 0;
			}
			 
			$$('.on')[0].removeClassName('on');
			
			boxes = $$('.top_feed');
			boxes.each(function(i,index) {
				if (screenshots.pos == index) {
					i.addClassName('on');
					new Effect.Opacity(i, {from: 0, to: 1, duration: 1.5});
				}
				
			});
			
			screenshots.changeTopFeature();
		},8000);
	}	
}
	
document.observe('dom:loaded', screenshots.init);
