var slide = {};
slide.delay = 4000;
var scroll = {};
scroll.speed = 1;
scroll.interval = 100;
function scrollIt() {
	if (scroll.pause) return;
	scroll.div.scrollTop += scroll.speed;
	var scrollMax = scroll.div.scrollHeight - scroll.div.offsetHeight;
	if (scroll.div.scrollTop == scrollMax) {
		scroll.div.scrollTop = 0;
		//$('div#testscroll').append($('div#testscroll div:first'));
		//clearInterval(scroll.timer);
	}
	if (scroll.div.scrollTop >= scroll.repeat) {
		scroll.div.scrollTop = scroll.div.scrollTop - scroll.repeat;
	}
}
$(function(){
	// set up news scroll
	scroll.div = document.getElementById('news-scroll');
	scroll.div.scrollTop = 0;
	
	// insert repeat - two items
	var insertHtml = '<div class="item repeat">' + $('div#news-scroll div.item:first').html() + '</div>';
	$('div#news-scroll').append(insertHtml);
	insertHtml = '<div class="item">' + $('div#news-scroll div.item:eq(1)').html() + '</div>';
	$('div#news-scroll').append(insertHtml);
	
	// get repeat position
	scroll.repeat = $('div#news-scroll div.repeat').offset();
	scroll.repeat = scroll.repeat.top;
	var topPos = $('div#news-scroll div:first').offset();
	scroll.repeat -= topPos.top;
	
	// set up item action
	$('div#news-scroll div.item').mouseover(function(){
		scroll.pause = true;
		$(this).addClass('active');
	});
	$('div#news-scroll div.item').mouseout(function(){
		scroll.pause = false;
		$(this).removeClass('active');
	});
	
	// start scrolling
	scroll.timer = setInterval('scrollIt()', scroll.interval);
	
	
	// set up slideshow
	slide.count = $('div#flash div.pic').length;
	slide.index = 1;
	slide.run = function() {
		var prevIndex = this.index - 1;
		if (prevIndex < 0) prevIndex = this.count - 1;
		$('div#flash div.pic:eq('+prevIndex+')').fadeOut('slow');
		$('div#flash div.pic:eq('+this.index+')').fadeIn('slow');
		this.index++;
		if (this.index == this.count) this.index = 0;
	};
	setInterval('slide.run()', slide.delay);
	$('div#flash div.pic:eq(0)').fadeIn('slow');
});