var whos = [{who:'brat',h:200}, {who:'wee',h:150}, {who:'akuma',h:200}];
var whoToResize = [];
$(document).ready(function()
{ 
	/*
	$("#standardsCheck").click(function()
	{
		if( standards > 0 )
		{
			$("#standards").show( "slow" );
		}
		else
		{
			$("#standards").hide( "slow" );
		}
		standards *= -1;
	});
	$("#standardsCheck img").hover(function() 
	{
		$(this).attr("src","/images/standards_over.png");
	}, function() 
	{
		if( animate > 0 )
		{
			$(this).attr("src","/images/standards.png");
		}
		else
		{
			$(this).attr("src","/images/standards_over.png");
		}
	});
	*/
	bounceIn( "#braticon", function()
	{
		bounceIn( "#weeicon", function()
		{
			bounceIn( "#akumaicon", function()
			{ 
				loadCrap( whos[0].who, whos[0].h ) 
			});
		}) 
	});
});
$(window).resize(function()
{
	$("#footer").css( { "top" : "100%" } );
	for( var i=0, l=whoToResize.length; i<l; i++ )
	{
		sizeScroller( whoToResize[i].who, whoToResize[i].h );
	}
});
var sizeScroller = function( who, h )
{
	var scroll = false;
	var contentHeight = $("#" + who + "content").height();
	if( contentHeight > h )
	{
		var barHeight = Math.round( h * Math.round( h / contentHeight * 100 ) / 100 );
		$( "#" + who + "scroller .scrollbar" ).height( barHeight );
		var scrollable = h - barHeight;
		var dragged = $( "#" + who + "scroller .scrollbar" ).draggable({
			drag: function( event, ui )
			{
				var pos = ui.position.top;
				var posPercent = pos/scrollable;
				$("#" + who + "content").css( "margin-top",  -( ( contentHeight - h ) * posPercent ) + "px" );
			},
			containment: 'parent',
			axis: 'y' 
		});
		$( "#" + who + "content" ).bind( "wheel", function( event, delta )
		{
			var newPos = $("#" + who + "scroller .scrollbar").css( "top" );
			if( delta > 0 )
			{
				if( parseInt( newPos ) >= 0 
					&& parseInt( newPos ) - 10 >= 0 )
				{
					newPos = parseInt( newPos ) - 10 + "px";
				}
				else
				{
					newPos = 0 + "px";
				}
			}
			else
			{
				if( parseInt( newPos ) <= scrollable 
					&& parseInt( newPos ) + 10 <= scrollable )
				{
					newPos = parseInt( newPos ) + 10 + "px";
				}
				else
				{
					newPos = scrollable + "px";
				}
			}
			$("#" + who + "scroller .scrollbar").css( "top",  newPos );
			var posPercent = parseInt( newPos )/scrollable;
			$("#" + who + "content").css( "margin-top",  -( ( contentHeight - h ) * posPercent ) + "px" );
		});
		$( "#" + who + "scroller" ).bind( "wheel", function( event, delta )
		{
			var newPos = $("#" + who + "scroller .scrollbar").css( "top" );
			if( delta > 0 )
			{
				if( parseInt( newPos ) >= 0 
					&& parseInt( newPos ) - 10 >= 0 )
				{
					newPos = parseInt( newPos ) - 10 + "px";
				}
				else
				{
					newPos = 0 + "px";
				}
			}
			else
			{
				if( parseInt( newPos ) <= scrollable 
					&& parseInt( newPos ) + 10 <= scrollable )
				{
					newPos = parseInt( newPos ) + 10 + "px";
				}
				else
				{
					newPos = scrollable + "px";
				}
			}
			$("#" + who + "scroller .scrollbar").css( "top",  newPos );
			var posPercent = parseInt( newPos )/scrollable;
			$("#" + who + "content").css( "margin-top",  -( ( contentHeight - h ) * posPercent ) + "px" );
		}); 
		scroll = true;
	}
	return scroll;
}
var loadCrap = function( who, h )
{
	$( "#" + who ).append( "<img id=\"" + who + "loader\" src=\"/images/loading_ajax_small.gif\" />" );
	$.ajax(
	{
		url: "loadPosts.php"
		, data: "user=" + who
		, cache: false
		, success: function( html )
		{
			$( "#" + who + "loader" ).hide();
			$( "#" + who ).append( "<div id=\"" + who + "content\">" 
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ html  
				+ "</div>" );
			var scroller = sizeScroller( who, h );
			if( scroller )
			{
				$( "#" + who + "scroller .scrollbar" ).fadeIn( "slow", function()
				{
					$( "#" + who + "scroller" ).css( "background-image", "url( '/images/mr.png' )" );
				});
			}
		}
		, complete: function()
		{
			whoToResize.push( whos.shift() );
			if( whos.length > 0 )
			{
				loadCrap( whos[0].who, whos[0].h );
			}
		}
	});
}
var bounceIn = function( who, cb )
{
	$(who).animate(
	{ 
	  top: "100%"
	  , marginTop: "-95px"
	}
	, 300
	, "easeInQuad"
	, function()
	{
		$(who).animate(
		{
			width: "150px"
			, height: "50px"
			, marginTop: "-45px"
			, left: "-30px"
		}
		, 100
		,"swing"
		, function()
		{
			$(who).animate(
			{
				width: "100px"
				, height: "98px"
				, marginTop: "-95px"
				, left: "5px"
			}
			, 200
			, "swing" 
			,function(){ cb(); } )
		})
	});
}
