// Saebekassebil 2010

$(document).ready(function() {
	function slide() {
		var boxes = $('div.sponsor-box');
		if(boxes.length === 0) {
			timer = window.clearInterval(timer);
		}
		
		$(boxes).each(function(index) {
			if($(this).css('position') !== "absolute") {
				$(this).css('top', $(this).position().top + "px");
			}
			
			var height = $(this).outerHeight(true);
			$(this).animate({
				'top': '-=' + height
			}, 1000, function() {
				if(parseFloat($(this).css('top')) <= -height) {
					$(this).toggle();
					$(this).css('top', (boxes.length-1)*height);
					$(this).fadeIn('fast');
				}
			});
		});
		
		if($(boxes[0]).css('position') !== 'absolute') {
			$(boxes).css('position', 'absolute');
		}
	}
	
	var timer = window.setInterval(slide, 6000);
});
