window.addEvent('domready', function() {
	
	/* ----------Config Vars----------- */
	var slideTimer = 5000;  //time between slides (1 second = 1000), a.k.a. the interval duration
	var transitionTime = 1200; //transition time (1 second = 1000) 
	var items = $$('.slide_item');  //Get array of elements for sliding
	var numItems = items.length;  //get number of slider items
	var numNav = new Array();  //create an array to hold our dynamically created number navigation
	var prevBtn = $('prevbtn');
	var nextBtn = $('nextbtn');
	var itemNum = 0;  //initialize a variable to hold the current slide index
	/* -------- end config vars -------- */
	
	//--------- setup stuff ---------//
	items.each(function(element, index) {
		
		//since the viewer obviously has javascript on, we can remove the 'first_item' class
		if(index == 0){
			element.removeClass('first_item');
			element.setStyle('left', "0");
			element.setStyle('opacity', "1");
			element.setStyle('display', "block");
		}
		else{
			element.setStyle('left', "0");
			element.setStyle('opacity', "0");  
		}
	});
	
	//--------- end setup stuff ---------//

	//---------------------------------------------------------------------------------------------------------
	//	function: slideMove
	//	description: moves the appropriate slides in/out of view
	//	parameters:
	//		int direction - specifies type of movement (0=back, 1=forward, 2=jump to frame
	//		int passedID (optional) - index value to jump to when direction = 2
	//---------------------------------------------------------------------------------------------------------
	var slideMove = function(direction){ 
		
		//get item to slide out
		var curItem = items[itemNum];
		
		//change index based on value of 'direction' parameter
		if(direction == 1){
			if(itemNum < (numItems - 1)){
				itemNum++;
			}
			else{
				itemNum = 0;
			}
		}
		else if(direction == 0){
			if(itemNum > 0){
				itemNum--; 
			}
			else{
				itemNum = (numItems - 1);
			}
		}
		
		//now get item to slide in using new index
		var newItem = items[itemNum];
		
		var item_in = new Fx.Morph(newItem, {  
                  duration: transitionTime,   
                  transition: Fx.Transitions.Quad.easeInOut,                     
				  wait:false  
        });
		
		var item_out = new Fx.Morph(curItem, {  
                 duration: transitionTime,   
                  transition: Fx.Transitions.Quad.easeInOut,   
                  wait:false  
        });
			
		//we will set a beginning value here
		//this is so that it gives the illusion of continuous motion from one direction, even after the first cycle of items
		item_in.start({
		'opacity':[0,1],'display':['block']
		});
		
		//no beginning values needed, since we always want to push the old item out to the left
		item_out.start({
		'opacity':  [0]
		});
		
	};
	//--------------- end slideMove ---------------------

	var theTimer = 0; 

	/* control buttons */
	nextBtn.addEvent('click', function(){
			slideMove(1);
	});
	
	prevBtn.addEvent('click', function(){     
			slideMove(0);
	});

});
