
	
	//
	
	var hasFlash = true;
	
	var trailerState = false;
	
	var contentWidth = "40%";
	
	var currentSection;
	
	//

	function hasNoFlash(  )
	{
		hasFlash = false;
	}
	
	function onAddressChange( event )
	{
		alert( event );
	}
	
	//
	
	function showTrailer( state )
	{
		trailerState = state;
		
		if( state )
		{
			$("#trailerContainer").html( '<object width="480" height="270" id="trailerClip"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=5054589&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=63ab29&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=5054589&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=000000&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="480" height="270" id="trailerClip"></embed></object>' );
			//$("#trailerContainer").html( '<span style="color:white">Coming Soon.</span>' );
			//
			$("#flashcontent").animate( { top: "400px" }, 500);
			$("body").css("background-color", "#000000");
			$("#trailer").show( );
			$("#trailerButton").hide();
			getID( 'flashcontent' ).pauseFlash( true );
		}
		else
		{
			trailerButtonIn = function(){ $("#trailerContainer").html( '' ); $("#trailerButton").show(); getID( 'flashcontent' ).pauseFlash( false ); }
			contentOut = function(){ $("#trailer").hide( ); $("#flashcontent").animate( { top: "0px" }, 500, trailerButtonIn ); }
			$("#trailer").fadeOut( 500, contentOut );
		}
		
	}
	
	function showContent( state, page )
	{
		if( !state )
		{
			$("#flashcontent").css( "width", "100%" );
			
			$("#content").hide( );
			
			if( trailerState )
			{
				$("#contentTrailer").hide( );
				$("#trailerButton").show();
				$("#trailer").hide( );
				$("#flashcontent").css( "top", "0px" );
				trailerState = false;
			}
			else
			{
				$("#contentTrailer").hide( );
			}
			
			getID( 'flashcontent' ).showContentButton( true );
		}
		else
		{
			trailerState = false;
			$("#trailer").hide( );
			$("#flashcontent").css( "top", "0px" );
			
			var w = getWindowWidth();
			var flashW = "66%";
			if( w*.34 < 380 )
			{
				flashW = (w-380) + "px";
			}
			
			if( page != 'home' )
			{
				$("#content").show( );
				
				$("#contentTrailer").hide( );
				
				$("#flashcontent").css( "width", flashW );
			}
			else
			{
				$("#content").hide( );
				
				$("#contentTrailer").show( );
				
				$("#flashcontent").css( "width", "100%" );
			}
			
			getID( 'flashcontent' ).showContentButton( false );
		}
	}
	
	function toggleContent( state )
	{
		/*if( !state )
		{
			$("#contentInner").hide( );
			$("#content").css("min-height", "0px");
			$("#contentHeader").html("<h4><a href='javascript:toggleContent(true)'><div class='x'>Show</div></a></h4>");
		}
		else
		{
			$("#contentInner").show( );
			$("#content").css("min-height", "120%");
			$("#contentHeader").html("<h4><a href='javascript:toggleContent(false)'><div class='x'>X</div></a></h4>");
		}*/
		showContent( state );
	}
	
	//

	function getContent( section, id, dataString )
	{ 
		currentSection = section;
		
		if( section == "home" && hasFlash)
		{
			$("#contentTrailer").show( );
			$("#content").hide( );
			return;
		}
		else
		{
			//toggleContent( true );
		}
		
		url = section;
		
		if( id != '' )
		{
			if( id.indexOf( 'pg=' ) > 0 )
			{
				url += "-ajax/?pg=" + id.substr( id.indexOf( 'pg=' )+3 );
			}
			else
			{
				id = id.substring( 1 );
				id = parseFloat( id );
				url = "ajax?article_id="+id;
				
				/*if( section == 'news' )
				{
					url += "&article_section=news";
					launchWin( '/' + url, 'NewsPopup', 600, 400, 'no' );
					url = section + "-ajax/";
					return;
				}*/
			}
		}
		else
		{
			url += "-ajax/";
		}
		//
		if( !hasFlash )
		{
			$("#noflash-content").html( "<h3>Loading</h3>" );
		
			$("#noflash-content").load( '/' + url );
		}
		else
		{
			$("#content").show( );
		
			if( dataString !='' )
			{
				$("#contentToWrite").html( dataString );
			}
			else
			{
				$("#contentToWrite").html( "<h3>Loading</h3>" );
				$("#contentToWrite").load( '/' + url,'', formatPagingLinks );
				//$("#contentToWrite").load( '/' + url );
			}
		}
		//
		//formatPagingLinks();
		//
		window.scroll(0,0);
	}
	
	function formatPagingLinks()
	{
		var older = $( "#older" ).html();
		
		if( older && older != "" )
		{
			older = older.substr( older.indexOf( "pg=" )+3 );
			$( "#older" ).html( '<a href="javascript:setContent(\'/'+currentSection+'/pg='+older+'\')">older</a>' );
		}
		
		var newer = $( "#newer" ).html();
		
		if( newer && newer != "" )
		{
			newer = newer.substr( newer.indexOf( "pg=" )+3 );
			$( "#newer" ).html( '<a href="javascript:setContent(\'/'+currentSection+'/pg='+newer+'\')">newer</a>' );
		}
	}
	
	//

	function setContent( url, title )
	{
		SWFAddress.setValue(''+url);
		
		url = url.substring( 1 );
		n = url.indexOf( '/' );
		if( n < 0 )
		{
			section = url;
			url = undefined;
		}
		else
		{
			section = url.substring( 0, n );
			url = url.substring( n );
		}
		
		/*if( section == 'news' && url != '' )
		{
			SWFAddress.setValue(''+section);
		}*/
		
		if( !hasFlash )
		{
			getContent( section, url );
		}
		
		if( title )
		{
			$("#noflash-title-header").html( title );
		}
	}

	//
	
	function getID(swfID) {
   	
   		if (navigator.appName.indexOf("Microsoft") > -1) {
     	
     		return window[swfID];
   		
   		} else {
      		
      		return document[swfID];
   		
   		}
	
	}
	
	//
	
	function getWindowHeight() {
	
		var windowHeight = 0;
		
		if (typeof(window.innerHeight) == 'number') {
		
			windowHeight = window.innerHeight;
			
		} else {
		
			if (document.documentElement && document.documentElement.clientHeight) {
			
				windowHeight = document.documentElement.clientHeight;
				
			} else {
			
				if (document.body && document.body.clientHeight) {
				
				windowHeight = document.body.clientHeight;
				
				}
				
			}
			
		}
		
		return windowHeight;
		
	}
	
	function getWindowWidth() {
	
		var windowWidth = 0;
		
		if (typeof(window.innerWidth) == 'number') {
		
			windowWidth = window.innerWidth;
			
		} else {
		
			if (document.documentElement && document.documentElement.clientWidth) {
			
				windowWidth = document.documentElement.clientWidth;
				
			} else {
			
				if (document.body && document.body.clientWidth) {
				
				windowWidth = document.body.clientWidth;
				
				}
				
			}
			
		}
		
		if( navigator.appName.indexOf("Netscape") > -1 )
		{
			windowWidth -= 19;
		}
		
		return windowWidth;
		
	}
	
	function launchWin(url, name, newWidth, newHeight,scroll) {
        newWin = open(url,name,"scrollbars=" + scroll + ",resizable=no,status=no,height=" + newHeight + ",width=" + newWidth);
        return newWin;
	}
	
	//