
	function nextNewsItem() {
	
		$.get('rpc/', {}, function(html) {

			if ($('#news .newsItem').size()) {
				$('#news .newsItem').fadeOut('slow', function() {
					$('#news').html(html).children('.newsItem').fadeIn('slow', function() {
						setTimeout(nextNewsItem, 10000);
					});
				});
			} else {
				$('#news').html(html).children('.newsItem').fadeIn('slow', function() {
					setTimeout(nextNewsItem, 10000);
				});
			}

		});
		
	}
	
	function fixContentHeight() {

		var delta = $(window).height() - $('#container').height(); 	
		
		if (delta > 0)
			$('#content').height($('#content').height() + delta + 'px');
		
	}

	$(function() {

		// start the rotation	
		nextNewsItem();
			
		$('#news').click(function() {
			window.location = 'news.php';
		});
		
		/*
		 * buttons
		 */
		
		// replace buttons with our cooler looking ones
		
		$('button').each(function() {
			$(this).html(
				'<img src="images/button_arrow_right.gif" />' +
				'<div>' + $(this).text() + '</div>' +
				'<img src="images/button_right.gif" />'
				);
		}).mousedown(function() {
			$(this).css({top: '1px', left: '1px'});
		}).mouseup(function() {
			$(this).css({top: '0', left: '0'});
		}).mouseout(function() {
			$(this).css({top: '0', left: '0'});
		}).bind('selectstart', function() {
			return false;
		}).bind('mousedown', function() {
			return false;
		}).click(function() {

			$('button.toggle').not(this).removeClass('toggle');
			$(this).toggleClass('toggle');

			// hide other lists
			$('button img:first-child').attr('src', 'images/button_arrow_right.gif');
			
			if ($(this).attr('rel')) {

				$('#content button.toggle img:first-child').attr('src', 'images/button_arrow_down.gif');

				$('#content .section').hide();
				if ($(this).is('.toggle'))
					$($(this).attr('rel')).fadeIn('slow', function() {
						$('#content .section').not(this).hide();
					});
				else
					$('#content #default').fadeIn('slow', function() {
						$('#content .section').not(this).hide();
					});
			
			} else if ($(this).next().is('ul')) {
			
				$('#content button.toggle img:first-child').attr('src', 'images/button_arrow_down.gif');
			
				// toggle this lists sliding
				$('#content ul:visible').not($(this).next()).slideUp();
				$(this).next().slideToggle();
				
			}
			
		});
		
		if ($.browser.mozilla) {
			$('button').each(function() {
				$(this).css({
					marginLeft: (parseInt($(this).css('marginLeft')) - 3) +'px',
					marginRight: (parseInt($(this).css('marginRight')) - 3) +'px'
				});
			});
		}

	});

	$(window).load(function() {		
		$('button').each(function() {
			if ($(this).css('width') != 'auto')
				$(this).children('div').width(parseInt($(this).width()) - 40 + 'px');
			else if ($(this).css('width') == 'auto' && $.browser.msie)
				$(this).width(parseInt($(this).children('div').width()) + 29 + 'px');
		});
	});
	
	
		