$( function()
{
	$( 'a' ).each(
		function()
		{
			if( this.rel == 'external' ) this.target = '_blank';
		}
	);

	if( getQueryString( 'display' ) ) addScript( getQueryString( 'display' ) +'.js' );

	$( '#headlines .mainlink' ).click( function() 
	{
		var item = this;
		var id = this.id.replace( /link$/, '' );

		if( id != 'news' ) addScript( id +'.js' );

		var open = true;
		if( this.parentNode.className.match( 'headlineopen' ) )
		{
			open = false;
		}

		$( '#headlines .headlineopen' ).each(
			function()
			{
				var $this = $( this );

				/* Friggin fukin IE! */
				if( $.browser.msie && $.browser.version < 7 ) $this.find( 'div a' ).css( 'position', 'static' );
				$this.animate( { height: 24 }, 'fast', 'easein', function() { $( this ).removeClass( 'headlineopen' ); } );
			}
		);

		var parent = $( this.parentNode );
		if( open )
		{
			parent.animate( { height: parent.find( 'div' ).height() + 33 }, 'fast', 'easein', 
				function()
				{
					var $this = $( this );

				$this.addClass( 'headlineopen' ).css( 'height', 'auto' ).css( 'overflow', 'hidden' );
				}
			);
		}

		return false;
	} );

	
	
} );


function getQueryString( key ) 
{
	var query = window.location.search.substring( 1 );

	var vars = query.split( '&' );
	for( var i = 0, l = vars.length; i < l; i++ ) 
	{
		var pair = vars[i].split( '=' );
		if( pair[0] == key ) 
		{ 
			return pair[1];
		}
	}
	return false;
} 

function addScript( url )
{
	var script = document.createElement( 'script' )
	script = $( script );
	script.attr( 'src', 'js/'+ url );
	script.attr( 'type', 'text/javascript' );
	$( 'head' ).append( script );
}