window.addEvent('domready', function() {
									 
		////////////////////////////////nav

		var links = $('nav-buttons').getElements('a');
		var row = $$('.row');
		var nextPage = $('next-page');
		var selectors = $$('.selector');
		var currentPosition = 0;
		var end = selectors.length;

		//	var scrollFx = new Fx.Scroll(window, {offset: {'x': -150,'y':-40}, duration: 1});
			var scrollFx = new Fx.Scroll(window, {offset: {'x': -150,'y':-40}, duration: 400, transition: Fx.Transitions.linear, fps: 10});

		//Prevous
		var gotoPreviousSeperator = function(){
			currentPosition--;
			if(currentPosition <=0) {currentPosition = 0}
			// animation
			scrollFx.toElement(selectors[currentPosition]);	
		}

		//Next
		var gotoNextSeperator = function(){
				currentPosition++;
				if (currentPosition >= end) {
					currentPosition = end; 
	//				document.location = nextPage.innerHTML;
				} else {
					scrollFx.toElement(selectors[currentPosition]);
				}
		}

		// evaluate key
		var getKey = function(e){
	//		e.preventDefault(); // this prevented any key entry into forms
			var key = e.event.keyCode;
			if(key == 40) {gotoNextSeperator()}
			if(key == 38) {gotoPreviousSeperator()}
		}
		
		/********************************************
		* KRIS-6:
		 * Added the lines below
		 * Size the foot div to be the exact same dimensions 
		 * as the row div, this should define the window 
		 * scrolling size to be the size of the row.
		 ********************************************/
		var rowDim = row[0].getSize();
		$("foot").set('styles', {
			height: rowDim.y + 'px',
			width: rowDim.x + 'px'
		});

		// scrollFx.toElement(selectors[0]);

		// links
	//	if (links[0]) links[0].addEvent('click',gotoPreviousSeperator);
	//	if (links[1]) links[1].addEvent('click',gotoNextSeperator);

		// Key pressed
		if (selectors[1]) {     
			document.addEvent('keydown', getKey);
		}

		var enableArrowScrolling = function(){
			document.addEvent('keydown', getKey);
		}

		var disableArrowScrolling = function(){
			document.removeEvent('keydown', getKey, false);
		}

		var inputfield = $$('input');
		for(i=0;i<inputfield.length;i++) {
			var type = inputfield[i].getAttribute('type');
			var name = inputfield[i].getAttribute('name');
			if (type == 'text' && name != null) {
				inputfield[i].addEvent('focus',disableArrowScrolling);
				inputfield[i].addEvent('blur',enableArrowScrolling);
			}
		}
		var textarea = $$('textarea');
		for(i=0;i<textarea.length;i++) {
			textarea[i].addEvent('focus',disableArrowScrolling);
			textarea[i].addEvent('blur',enableArrowScrolling);
		}

	////////////////////////////////horizontal scroll with mousewheel

		document.addEvent('mousewheel', function(event) {	
	//		event.preventDefault();
			event = new Event(event);
	//		tweenMenu('30px')
			/* Mousewheel UP */
			if (event.wheel > 0) {
				window.scrollBy(0,-1000);
			} 
			/* Mousewheel DOWN*/
			else if (event.wheel < 0) {
				window.scrollBy(0,100);			
			}
		});


});
