sherror = {
				'shoutbox_name'  : 	'Please enter your name',
				'shoutbox_email' :	'A valid email would be nice',
				'shoutbox_in'    :	'Say something'
		   }

var shoutpop = null;

function ShoutHover()
{
	$('.shout-item').hover(
		function(e)
		{
			if(shoutpop)
				shoutpop.remove();
			
			var popup = document.createElement('div');
			shoutpop = $(popup);
			if($(this).attr('id') == 1)
			{
				shoutpop.html($(this).attr('id') + ' person said me!');
			}
			else
			{
				shoutpop.html($(this).attr('id') + ' people said me!');
			}
			shoutpop.addClass('shout_popup');
			
			var offset = $(this).offset();
			
			
			
			shoutpop.css(
				{
					'left' 	:	(e.pageX) +'px',
					'top' 	: 	(offset.top - 5) +'px',
					'z-index': '5',
					'display' : 'none',
				}
			);
			$('body').append(shoutpop);
			shoutpop.fadeIn(100);
			
		},	
		function(e)
		{
			shoutpop.remove();
			shoutpop = null;
		}
	);
}
				
function section_shoutbox_onload()
{
	ShoutHover();
	
	$('#shoutbox_button').click(
		function(e)
		{
			valid = true;
			$('.shoutbox_input').each(
				function(a, b)
				{
					if($(this).val() == $(this).attr('alt'))
					{
						valid = false;
						$('#error').html(sherror[$(this).attr('id')]);
					}
				}
			)
			if(valid)
			{
				$.post('scripts/php/insert.php', $("#shoutbox_form").serialize(), 
					function(data) 
					{
						if(data == 'true')
						{
							$('#tagCloud').load('scripts/php/tagcloud.php', 
								function()
								{
									ShoutHover();
								}
							);
						}
						else
						{
							$('#error').html(data);
						}
					}
				);
			}
		
		}
	)

	$("#shoutbox_in").keydown(
		function(e)
		{
			var key = e.keyCode  || e.charCode;
			
			return( (key >= 65 && key <= 90) 	||
					(key >= 48 && key <= 57) 	||
					key == 8 					|| 
					key == 32 					|| 
					key == 9 					||
					key == 46 					||
					key == 16 					||
					(key >= 37 && key <= 40) 	||
					(key >= 96 && key <= 105) );
			
		}
	);

	$(".shoutbox_input, .main_news_input, .news_input, .volunteer_input").focus( 
		function()
		{
			if($(this).val() == $(this).attr('alt'))
			{
				$(this).val('');
			}
		}
	);
	
	$(".shoutbox_input, .main_news_input, .news_input, .volunteer_input").blur(
		function()
		{
			if($(this).val() == '')
			{
				$(this).val($(this).attr('alt'));
			}
			else
			{
			}
		}
	);
	
	$(".shoutbox_input, .main_news_input, .news_input, .volunteer_input").each(
		function(a, b)
		{
			$(this).val($(this).attr('alt'));
		}
	);
}

function section_shoutbox_onenter()
{
}

function section_shoutbox_onexit()
{
}
