window.addEvent('domready',function() {

	if ($('featured_frame')) {
		
		var frame = $('featured_frame').getCoordinates();
	
	
	//$('featured_frame').s

		$('featright').addEvent('click',function() {
			
			if (!this.hasClass('ldisalbed')) {
			
				$('featleft').removeClass('ldisabled');
				$('featleft').addClass('featleft');
				
				var content = $('featured_content').getCoordinates();
				var buttonpadding = $('featured_content').getStyle('margin-left').toInt() + $('featured_content').getStyle('margin-right').toInt() ;
				
				var currentposition = (content.left - frame.left);
				
				var scrollable = ((content.width+buttonpadding-frame.width) + currentposition);
				
		
				if (scrollable > frame.width) {
					var move = (currentposition - frame.width + (buttonpadding/2)) 
				} else {
					var move = (currentposition - scrollable);
					this.removeClass('featright');
					this.addClass('rdisabled');
				}
				
				$('featured_content').tween('left', move);
			}
		
		});
	
	
		$('featleft').addEvent('click',function() {
			
			if (!this.hasClass('ldisalbed')) {
			
				$('featright').removeClass('rdisabled');
				$('featright').addClass('featright');
				
				var content = $('featured_content').getCoordinates();
				var buttonpadding = $('featured_content').getStyle('margin-left').toInt() + $('featured_content').getStyle('margin-right').toInt() ;
				var currentposition = (content.left - frame.left);
				var scrollable = (currentposition + (buttonpadding/2));
				
				if ((scrollable*-1) > frame.width) {
					var move = (currentposition + frame.width) 
				} else {
					var move = (currentposition - scrollable + (buttonpadding/2));
					this.removeClass('featleft');
					this.addClass('ldisabled');
					//alert('disabled')
				}
				
				$('featured_content').tween('left', move);
			
			}	
		});
	}	
	
	
	if ($('vscroller_frame')) {
	
		var top = $$('.vscroller_heading')[0].getPosition().y;
		var hi=0,currpos;
		var hp =new Array();
		
		$$('.vscroller_heading').each(function(h,i) {hp.push(h.getPosition().y)});
		
		
		function vs_next() {
			var pos = $('vscroller_content').getPosition().y;
			if (hi < (hp.length-1)) {
				hi=hi+1;
				$('vscroller_content').tween('top',(top - hp[hi]));
			} else {
				$('vscroller_content').tween('top',0);
				hi=0;
			}
		}
		function vs_prev() {
			var pos = $('vscroller_content').getPosition().y;
			if (hi > 0) {
				hi=hi-1;
				console.log(hi);
				$('vscroller_content').tween('top',(top - hp[hi]));
			} else {
				$('vscroller_content').tween('top',(top - hp[(hp.length-1)]));
				hi = (hp.length-1);
				console.log(hp[(hp.length-1)]);
			}
		}
		
		$('vscroller_down').addEvent('click',function() {
			window.clearInterval(start);
			vs_next();
		});
		$('vscroller_up').addEvent('click',function() {
			window.clearInterval(start);
			vs_prev();
		});
		
		var start = vs_next.periodical(5000);
		
	}

});
