$(document).ready(function()
{
	if ( $('#box-highlight').length > 0 )
	{
		$.get ( 'xml.php', { o: 11961 }, function ( response, status )
		{
			var xsl = null;
			$.get ( 'xsl/highlights.xsl.xml', {}, function ( response, status ) { xsl = response; }, 'xml' )
			
			var highlights = {};
			var highlightsRaw = $(response).find('childnode');
			var prevId = null;
			var highlightId = null;
			
			function display ( xml )
			{
				$('#target').xslt
				(
					{ doc: xml },
					{ doc: xsl },
					function ( ) { $(this).children().fadeIn('slow'); },
					function ( ) { $(this).children().fadeOut(); }
				);
			}
			
			function load ( )
			{
				while ( highlightId == null || highlightId == prevId ) highlightId = $($(highlightsRaw).get(Math.floor(Math.random()*highlightsRaw.length))).attr('id');
				prevId = highlightId;
				
				if ( ! highlights[ highlightId ] )
				{
					$.get ( 'xml.php', { o: highlightId }, function ( response, status )
					{
						highlights[ highlightId ] = response;
						display ( highlights[ highlightId ] );
			
					}, 'xml' );
				}
				else
				{
					display ( highlights[ highlightId ] );	
				}					
			}
			
			var interval = window.setInterval ( load, 4000 );
			load ( );
			
		}, 'xml' );
	}				
});