window.addEvent('domready', function() { 
	$$('#nav li').addEvent('mouseover',function(){this.addClass('hover');});
	$$('#nav li').addEvent('mouseout',function(){this.removeClass('hover');});
	
	
	var wrapper = $('clipdt_carouselwrapper'); 
	var carousel = $('clipdt_carousel'); 
	var item_width = 174; 
	
	var carouselitemscount = 0;
  if (carousel){
		carousel.getElements('div.clipdestagesitem').each(function(){carouselitemscount++;});
		
		var animation = new Fx.Tween(carousel, {duration: 500});
		function next_item(pos){
				var newposition = pos - item_width;
				if (Math.abs(newposition) < carouselitemscount*item_width){
				animation.start('left', newposition);
				}
		}
		
		function previous_item(pos){
				var newposition = pos + item_width;
				if (pos < 0){
					animation.start('left', newposition);
				}
			}
		
		
		$('leftbutton').addEvent('click', function(){
			var position = parseInt(carousel.getStyle('left'));
			previous_item(position);
		});
		
		$('rightbutton').addEvent('click', function(){
			var position = parseInt(carousel.getStyle('left'));
			next_item(position);
		});
	}	
		
	
	
	var NewSlider = new Class({
		Implements: [Options, Events],
        options: {
						
		},
        initialize: function(element,options){
                if (!element){return false;}
				this.element = element;
				this.NewsBox = element.getElement('ul.news')
				this.setOptions(options);
				this.NewsItems = this.NewsBox.getElements('li');
				this.pointer = 0;
				this.slideAnimation = new Fx.Tween(this.NewsBox, {
					duration: 500,
					onComplete: function(){
						this.NewsBox.getElement('li').inject(this.NewsBox,"bottom");
						this.NewsBox.setStyle('top',0);
					}.bind(this)
					
				
				});
				this.numItems = 0;
				this.NewsItems.each(function(){this.numItems++;}.bind(this));
				if (this.numItems < 5){return true;}
				this.MySliderInterval = this.slideNext.periodical(8000,this);
				this.element.getParent().addEvent('mouseenter',function(){$clear(this.MySliderInterval);}.bind(this));
				this.element.getParent().addEvent('mouseleave',function(){this.slideNext();this.MySliderInterval = this.slideNext.periodical(8000,this);}.bind(this));
        },
		slideNext: function(){
			this.slideAnimation.start('top',this.NewsBox.getStyle('top').toInt()-this.NewsItems[this.pointer].getStyle('height').toInt()-7);
			this.pointer++;
			if (this.pointer > this.numItems-2){this.pointer = 0;}
		}
	});
	var myNewsSlider = new NewSlider($('newsboxscroll_wrapper'));
	
	
  if ($('tx_indexedsearch')){$('tx_indexedsearch').setProperty('name','tx_indexedsearch');}
}); 





