Array.prototype.sum = function() {
	return (! this.length) ? 0 : this.slice(1).sum() + ((typeof this[0] == 'number') ? this[0] : 0);
}
//var interval = 5000;
//var speed = 400;
var cur = 1;
var tab = 1;
//var timer;

function moveArrow() {
	if( $('#bannerbuttons #bannerbutton_' + tab).hasClass('active') == false){
		$('#bannerbuttons #bannerbutton_' + cur).removeClass('active');
		$('#bannerbuttons #bannerbutton_' + tab).addClass('active');
		$('#bannerimage_' + cur).fadeOut('slow');
		$('#bannerimage_' + tab).fadeIn('slow').addClass('active');
		
		$('#bannerimage_' + cur).removeClass('active');
		cur = tab;
	}
}



$(document).ready(function () {
	//BANNERIMAGES
	$('#bannerimages div').hide();
	$('#bannerimages div:first').show();
	$('.bannerbutton a').mouseover(
		function () {
			tab = parseInt($(this).attr('tabindex'));
			moveArrow();
		}
	);
	$('.bannerbutton a').click(
		function () {
			return false;
		}
	);
	
	
	//TICKER
/*	function moveTicker () {
		$('ul#newsticker li').each(function () {
			var pos = parseInt($(this).css('left'));
			w = parseInt($(this).width() + 10);
			if (pos <= max) {
				$(this).css('left', total);
				var newpos = (parseInt($('ul#newsticker li:last').css('left')) + parseInt($('ul#newsticker li:last').width()) + 50);
				if (newpos < total) $(this).css('left', (total + 10));
				else $(this).css('left', newpos);
				$('ul#newsticker').append($('ul#newsticker li:first'));
			} else {
				$(this).css('left', (pos - 5));
			}
		});
	}
	
	var interval;
	var max = 0;
	var total = $('ul#newsticker').width();
	var speed = 80;
	
	$('ul#newsticker li').each(function (index) {
		if (index) $(this).css('left', (parseInt($(this).prev().css('left')) + parseInt($(this).prev().width()) + 60));
		else $(this).css('left', (total + 10));
		
		var t = $(this).find('a').text();
		$(this).find('a').html(t.replace(/ /ig, '&nbsp;'));
		
		if (parseInt($(this).width()) > max) max = parseInt($(this).width());
	});
	max = (max + 10) * -1;
	
	interval = setInterval(moveTicker, speed);
	$('ul#newsticker').hover(function () {clearInterval(interval);}, function () {interval = setInterval(moveTicker, speed);});
	
	
	function moveTicker () {
		$this = $('ul#' + id + ' li:first');
		var pos = parseInt($this.css('left'));
		if (curlen == 0) curlen = parseInt($this.width());
		if (pos < (curlen * -1)) {
			$this.css('left', total);
			$('ul#' + id).append($('ul#' + id + ' li:first'));
			curlen = 0;
		} else {
			$this.css('left', (pos - 2));
		}
		
	}
	
	var interval;
	var speed = 20;
	var id = 'newsticker';
	var total = parseInt($('ul#' + id).width()) + 50;
	var curlen = 0;
	
	$('ul#' + id + ' li a').each(function () {
		var t = $(this).text();
		$(this).html(t.replace(/ /ig, '&nbsp;'));
		$(this).parent().css('left', total);
	});
	
	$('ul#' + id).hover(function () {clearInterval(interval);}, function () {interval = setInterval(moveTicker, speed);});
	
	interval = setInterval(moveTicker, speed);*/
					function foo () {
					$('#newsticker a:first').fadeOut(speed, bar);
				}
				function bar () {
					$(this).next().fadeIn(speed, test);
				}
				function test () {
					$('#newsticker').append($('#newsticker a:first'));
					interval = setTimeout(foo, time);
				}
				
				var time = 4000;
				var speed = 500;
				var interval;
				
				$('#newsticker a').hover(
					function () {
						clearInterval(interval);
					},
					function () {
						interval = setTimeout(foo, 1000);
					}
				);
				
				$('#newsticker a').hide();
				$('#newsticker a:first').show();
				
				interval = setTimeout(foo, time);

});
