/////////////////////////////////////////////////////
//CardinalCarousel v.1 
//Developed by Randy Franklin - randyf@stanford.edu
////////////////////////////////////////////////////


// Declaration of the domready function - needed by all MooTools widgets
window.addEvent('domready',function() {
	// Creation of the scroll element using Fx.Scroll - any element within the inner container can be scrolled to using scroll.toElement[elementName]   
	var scroll = new Fx.Scroll('scroll_container_inner', {
			wait: false,
			// animation of the scroll - set duration higher for a slower transition effect
			duration: 800,
			transition: Fx.Transitions.Cubic.easeInOut
	});
	var arrayScrollingContent = $$('.scroll_section');
	var numberofitems = arrayScrollingContent.length;
	var currentItem = 0;
	for (var i=0; i<numberofitems; i++) {
                var arrayScrollPlacement = $$('.scroll_button');
		var scroll_placement = $('scroll_placement');
                var image_anchor = new Element('a', {'style': 'border=1px solid green' }).injectInside(scroll_placement); 
               	var my_img = new Element('img', {'src': 'scroll_placement_button_off.gif', 'class': 'scroll_button' }).injectInside(image_anchor);		
	}	        

	var arrayScrollPlacement = $$('.scroll_button');
	arrayScrollPlacement[0].setProperty('src', 'scroll_placement_button_on.gif');
        
	 $$('.scroll_button').each(function(el) {
		el.addEvent('click', function() { 
			scroll.toElement(arrayScrollingContent[1]);
			arrayScrollPlacement.setProperty('src', 'scroll_placement_button_off.gif');
                	arrayScrollPlacement[1].setProperty('src', 'scroll_placement_button_on.gif');
 
		});
	});
	

	

	$('scroll_right_shift').addEvent('click', function(event) {
		event = new Event(event).stop();
		currentItem = currentItem + 1;
		if (currentItem > arrayScrollingContent.length - 1) { 
			(currentItem = 0) }; 
		arrayScrollPlacement.setProperty('src', 'scroll_placement_button_off.gif');

		arrayScrollPlacement[currentItem].setProperty('src', 'scroll_placement_button_on.gif');
		scroll.toElement(arrayScrollingContent[currentItem]);
	});
	$('scroll_left_shift').addEvent('click', function(event) {
		event = new Event(event).stop();
		currentItem = currentItem - 1;
		if (currentItem < 0) { 
			(currentItem = 0) };
		arrayScrollPlacement.setProperty('src', 'scroll_placement_button_off.gif');
		arrayScrollPlacement[currentItem].setProperty('src', 'scroll_placement_button_on.gif');
		scroll.toElement(arrayScrollingContent[currentItem]);	
	});
});

