// Globals
var url = [];
var global_foreground_open = 0;
var global_scrolling_ip = 0;
var global_rumor_data = [];
var global_adding_comment = 0;
var global_comments_open = 0;
var global_cookies_enabled = 0;
var global_sport = '';

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function setRedirectCookie() {
	createCookie('BustARumor[Redirect]', window.location, 1);
}

function readRedirectCookie(del) {
	redir = readCookie('BustARumor[Redirect]');
	if(del)
		eraseCookie('BustARumor[Redirect]');
	if(redir == null)
		redir = '/';
	return redir;
}

function cookiesEnabled() {
	createCookie('BustARumor[CookieTest]', 'gHys86Ka', 1);
	
	if(readCookie('BustARumor[CookieTest]' == 'gHys86Ka'))
	{
		global_cookies_enabled = 1;
		eraseCookie('BustARumor[CookieTest]');
	}
}

function getQS(forceString) {
	if(forceString)
		var query = forceString.substring(1);
	else
		var query = window.location.search.substring(1);
	var params = query.split('&');
	for (var i=0; i<params.length; i++) {
		var pos = params[i].indexOf('=');
		if (pos > 0) {
			var key = params[i].substring(0,pos);
			var val = params[i].substring(pos+1);
			url[key] = val;
		}
	}
}

// Form display functions
function showFT(field) {
	var fromError = arguments[1] || 0;
	if($('#'+field+'_ft').css('display') == 'none')
		$('#'+field+'_ft').show('normal');

	if(!fromError) {
		$('#'+field+'_ft').siblings().each(function(e) {
			if(e.hasClass('ft_container'))
				e.hide();
		});
	}
}

function hideFT(field) {
	$('#'+field+'_ft').hide();
}

//Form function for changing container and input style on focus
function focusFormField(formField) {
	$(formField).parent().parent().css('borderStyle', 'solid');
	
	$(formField).addClass('ff_input_focus');
	$(formField).parent().siblings('.ff_help_container').html($(formField).attr('title'));
}

// Form function for in progress validation and style cleanup on blur
function blurFormField(formField, skipValidate, hideImg) {
	if(!skipValidate)
		skipValidate = 0;
	else if(skipValidate && !hideImg)
		$(formField).parent().css({
			'background-image': 'URL(../img/form_validation_check.gif)',
			'background-position': '95% 50%',
			'background-repeat': 'no-repeat'
		});
	
	if(!skipValidate && $(formField).val() != 0 && $(formField).val() != "")
	{
		formName = $(formField).closest('form').attr('name');
		
		$(formField).parent().css({
			'background-image' : 'URL(../img/loading_small.gif)',
			'background-position' : '95% 50%',
			'background-repeat' : 'no-repeat'
		});
		
		$.ajax({
			'url' : '/ajax/'+formName,
			'cache' : false,
			'type' : 'POST',
			'data' : 'inProgressValidateField='+$(formField).attr('name')+'&inProgressValidateValue='+$(formField).val(),
			'success' : function (responseData, textStatus) {
				// Error
				if(responseData != '') {
					$(formField).parent().css({
						'background-image' : 'URL(../img/form_validation_error.gif)',
						'background-position' : '95% 50%',
						'background-repeat' : 'no-repeat'
					});
					$('#ff_'+$(formField).attr('name')+'_container').html(responseData);
				}
				// No error
				else {
					$(formField).parent().css({
						'background-image' : 'URL(../img/form_validation_check.gif)',
						'background-position' : '95% 50%',
						'background-repeat' : 'no-repeat'
					});
					$('#ff_'+$(formField).attr('name')+'_container').html('');
				}
			},
			'error' : function (XMLHttpRequest, textStatus, errorThrown) {
			  	$(formField).parent().css('background-image', 'none');
			}
		});
	}
	
	$(formField).parent().parent().css('border', '1px dashed #c9c9c9');
	$(formField).parent().siblings('.ff_help_container').html('');
	$(formField).removeClass('ff_input_focus');
}

// Position background images
function setBackgroundHeight() {
	if(jQuery.support.cssFloat != true) {
		var documentWidth = $(document).width() - 4;
		var documentHeight = $(document).height() - 4;
	}
	else {
		var documentWidth = $(document).width();
		var documentHeight = $(document).height();
	}
	
	var documentCenter = Math.ceil(documentWidth / 2);
	
	if(global_sport == 'nhl')
	{
		$('body').css('background', 'white URL(\'../img/body_bg_nhl.jpg\') repeat fixed 0px 0px');
		
		var body_center_circle_height = '670';
		if(documentHeight < body_center_circle_height)
			body_center_circle_height = documentHeight;
		
		$('#body_center_bg').css({'height' : documentHeight+'px', 'left' : (documentCenter - 30)+'px'});
		$('#body_center_bg').show();
		
		$('#body_center_circle').css({'top' : ((documentHeight / 2) + $(document).scrollTop() - ((body_center_circle_height/2)+20))+'px', 'left' : (documentCenter - 335)+'px', 'height' : body_center_circle_height+'px', 'background-image' : 'URL("../img/centre_ice_circle.png")'});
		$('#body_center_circle').show();
	}
	else if(global_sport == 'nfl')
	{
		var bg_position_x = documentCenter - 385;
		
		$('body').css('background', 'white URL(\'../img/body_bg_nfl.jpg\') repeat fixed '+bg_position_x+'px 0px');
		
		var yard_marker_left = 0;
		var i = 1;
		var j = 1;
		while(i > 0)
		{
			yard_marker_x = documentCenter - (15 + (i*80));
			$('body').append('<div style="position: absolute; top: 60px; left: '+yard_marker_x+'px; height: 90px; width: 30px; background-image: URL(\'../img/body_bg_nfl_yard_marker.jpg\');"></div>');
			$('body').append('<div style="position: absolute; bottom: 120px; left: '+yard_marker_x+'px; height: 90px; width: 30px; background-image: URL(\'../img/body_bg_nfl_yard_marker.jpg\');"></div>');
			$('body').append('<div style="position: absolute; top: 60px; right: '+yard_marker_x+'px; height: 90px; width: 30px; background-image: URL(\'../img/body_bg_nfl_yard_marker.jpg\');"></div>');
			$('body').append('<div style="position: absolute; bottom: 120px; right: '+yard_marker_x+'px; height: 90px; width: 30px; background-image: URL(\'../img/body_bg_nfl_yard_marker.jpg\');"></div>');
			
			if(i == 4 || i == 10 || i == 16)
				i++;
			
			i++;
			
			if(yard_marker_x - 80 < 0)
				i = 0;
		}
	}
	else if(global_sport == 'mlb')
	{
		$('body').css('background', 'white URL(\'../img/body_bg_mlb.jpg\') repeat fixed 0px 0px');
		
		var body_center_circle_height = '670';
		if(documentHeight < body_center_circle_height)
			body_center_circle_height = documentHeight;
		
		$('#body_center_circle').css({'top' : ((documentHeight / 2) + $(document).scrollTop() - ((body_center_circle_height/2)+20))+'px', 'left' : (documentCenter - 335)+'px', 'height' : body_center_circle_height+'px', 'background-image' : 'URL(\'../img/body_bg_mlb_mound.png\')'});
		$('#body_center_circle').show();
	}
	else if(global_sport == 'ufc')
	{
		$('body').css('background', 'white URL(\'../img/body_bg_ufc.jpg\') repeat fixed 0px 0px');
		
		var body_center_circle_height = '670';
		if(documentHeight < body_center_circle_height)
			body_center_circle_height = documentHeight;
		
		$('#body_center_circle').css({'top' : ((documentHeight / 2) + $(document).scrollTop() - ((body_center_circle_height/2)+30))+'px', 'left' : (documentCenter - 335)+'px', 'height' : body_center_circle_height+'px', 'background-image' : 'URL(\'../img/body_bg_ufc_octagon.jpg\')'});
		$('#body_center_circle').show();
		
		$('body').append('<div style="position: absolute; top: '+((documentHeight/2) - ((248/2)+29))+'px; left: '+(documentCenter - 335 - 130 - 50)+'px; width: 130px; height: 248px; background-image: URL(\'../img/body_bg_ufc_logo_left.jpg\');"></div>');
		$('body').append('<div style="position: absolute; top: '+((documentHeight/2) - ((248/2)+29))+'px; right: '+(documentCenter - 335 - 130 - 50)+'px; width: 130px; height: 248px; background-image: URL(\'../img/body_bg_ufc_logo_right.jpg\');"></div>');
		$('body').append('<div style="position: absolute; top: 0px; left: 0px; width: 150px; height: 150px; background-image: URL(\'../img/body_bg_ufc_corner_topleft.jpg\');"></div>');
		$('body').append('<div style="position: absolute; top: 0px; right: 0px; width: 150px; height: 150px; background-image: URL(\'../img/body_bg_ufc_corner_topright.jpg\');"></div>');
		$('body').append('<div style="position: absolute; bottom: 60px; left: 0px; width: 150px; height: 150px; background-image: URL(\'../img/body_bg_ufc_corner_bottomleft.jpg\');"></div>');
		$('body').append('<div style="position: absolute; bottom: 60px; right: 0px; width: 150px; height: 150px; background-image: URL(\'../img/body_bg_ufc_corner_bottomright.jpg\');"></div>');
	}

	$('#logo').css({'top' : ((documentHeight / 2) + $(document).scrollTop() - 135)+'px', 'left' : ((documentWidth / 2) - 292)+'px'});
	$('#logo').show();
	
	$('#nav').css({'top' : (documentHeight - 60)+'px', 'width' : documentWidth+'px'});
	$('#nav').show();
}

// Preload certain images used in graphical effects
function preLoadImages() {
	var im = new Array();
	im[0] = new Image();
	im[0].src = "../img/article_bg.png";
	im[1] = new Image();
	im[1].src = "../img/article_top.png";
	im[2] = new Image();
	im[2].src = "../img/article_bottom.png";
	im[3] = new Image();
	im[3].src = "../img/quote_up_right_bg.png";
	im[4] = new Image();
	im[4].src = "../img/black_transparency_60.png";
	im[5] = new Image();
	im[5].src = "../img/nav_title_bg.png";
	im[6] = new Image();
	im[6].src = "../img/nav_title_w3_bg.png";
}

function nameToURI(sourceInput, destInputId) {
	sourceName = sourceInput.value;
	uriName = sourceName.replace(/ /g, '-').replace(/&/g, '-and-').replace(/\'/g, '').replace(/:/g, '').replace(/\//g, '-slash-').replace(/--/g, '-').toLowerCase();
	
	if(arguments.length < 2)
		$('#'+sourceInput.id+'_uri').val(uriName);
	else
		$('#'+destInputId).val(uriName);
}

//Foreground functions
function addOverlay() {
	if(global_foreground_open == 1)
	{
		closeForeground('quick');
	}
	
	width = $(document).width();
	
	$('#logo').css({'z-index' : '999'});
	
	$('body').prepend('<div id="win_overlay" class="win_overlay" style="width:'+width+'px; height:'+$(document).height()+'px;"></div>');
	$('#win_overlay').show();
	
	global_foreground_open = 1;
}

function removeOverlay() {
	$('.win_overlay').remove();
	$('#logo').css({'z-index' : '2'});
}

function closeForeground() {
	var speedArg = arguments[0] || 0;
	
	if(global_foreground_open == 1 || speedArg == 'quick')
	{
		if(speedArg == 'quick') 
			var containerCloseSpeed = 0;
		else
			var containerCloseSpeed = 500;
		
		$('.text_content').hide();
		$('.comment_container').hide();
		$('.adsense').hide();
		
		$('.full_container').hide("slide", { direction: "down" }, containerCloseSpeed, function(){
			$('.full_container').remove();
			
			removeOverlay();
			$('.text_content').hide();
			$('.comment_container').hide();
			$('.adsense').hide();
			
			global_foreground_open = 0;
			global_adding_comment = 0;
			global_comments_open = 0;
		});	
	}
}

//Display loading graphic when waiting for AJAX content
function showWaiting() {
	var msg = arguments[0] || '';
	var color = arguments[1] || 'black';
	var leftPos = ($(document).width() / 2);
	var topPos = ($(window).height() / 2) + $(document).scrollTop();
	
	if(color == 'white')
		var loading = 'loading_overlay.gif';
	else
		var loading = 'loading.gif';
	
	$('body').prepend('<div id="waiting" style="left:'+(leftPos + 236)+'px; top:'+(topPos + 20)+'px; background-image: URL(\'/img/'+loading+'\');"></div>');
	$('body').prepend('<div id="waiting_text" style="left:'+(leftPos + 60)+'px; top:'+(topPos + 29)+'px; color:'+color+'">'+msg+'</div>');
}

function hideWaiting() {
	$('#waiting').fadeOut('normal', function(){ $('#waiting').remove(); });
	$('#waiting_text').fadeOut('normal', function(){ $('#waiting_text').remove(); });
}

// Div scrolling functions
function scrollDivUp(targetSelector, distance)
{
	if(global_scrolling_ip == 0)
	{
		global_scrolling_ip = 1;
		scrollDest = $(targetSelector).scrollTop() - distance;
		$(targetSelector).animate({scrollTop: scrollDest}, 300, 'swing', function(){ global_scrolling_ip = 0; });
	}
}

function scrollDivDown(targetSelector, distance)
{
	if(global_scrolling_ip == 0)
	{
		global_scrolling_ip = 1;
		scrollDest = $(targetSelector).scrollTop() + distance;
		$(targetSelector).animate({scrollTop: scrollDest}, 300, 'swing', function(){ global_scrolling_ip = 0; });
	}
}

function scrollDivLeft(targetSelector, distance)
{
	if(global_scrolling_ip == 0)
	{
		global_scrolling_ip = 1;
		scrollDest = $(targetSelector).scrollLeft() - distance;
		$(targetSelector).animate({scrollLeft: scrollDest}, 300, 'swing', function(){ global_scrolling_ip = 0; });
	}
}

function scrollDivRight(targetSelector, distance)
{
	if(global_scrolling_ip == 0)
	{
		global_scrolling_ip = 1;
		scrollDest = $(targetSelector).scrollLeft() + distance;
		$(targetSelector).animate({scrollLeft: scrollDest}, 300, 'swing', function(){ global_scrolling_ip = 0; });
	}
}

function scrollDivRW(targetSelector)
{
	if(global_scrolling_ip == 0)
	{
		global_scrolling_ip = 1;
		scrollDest = 0;
		$(targetSelector).animate({scrollLeft: scrollDest}, 500, 'swing', function(){ global_scrolling_ip = 0; });
	}
}

function scrollDivFF(targetSelector, distance)
{
	if(global_scrolling_ip == 0)
	{
		global_scrolling_ip = 1;
		scrollDest = distance;
		$(targetSelector).animate({scrollLeft: scrollDest}, 500, 'swing', function(){ global_scrolling_ip = 0; });
	}
}

function getSnippets()
{
	showWaiting('FETCHING THE LATEST RUMORS...');

	if(jQuery.support.cssFloat != true) {
		var documentWidth = $(document).width() - 4;
		var documentHeight = $(document).height() - 4;
	}
	else {
		var documentWidth = $(document).width();
		var documentHeight = $(document).height();
	}
	
	cols = Math.floor(documentWidth / 260);
	rows = Math.floor((documentHeight - 75) / 180);

	snippet_width = Math.floor(documentWidth / cols);
	snippet_height = Math.floor((documentHeight - 75) / rows);

	num_snippets = cols * rows;

	snippet_horiz_padding = snippet_width - 216;
	snippet_vert_padding = snippet_height - 150;

	if(rows % 2 == 0)
		row_char = 'even';
	else
		row_char = 'odd';	
	
	if(cols % 2 == 0)
		col_char = 'even';
	else
		col_char = 'odd';

	// Get number of visual snippets for query
	row_multiplier = 0;
	col_multiplier = 0;
	if(rows > 2) {
		row_multiplier = 1;
		
		if(row_char == 'even') {
			row_multiplier = 2;
		}
		else
			row_multiplier = 1;
	}
	if(cols > 2) {
		col_multiplier = 1;
		
		if(col_char == 'even') {
			col_multiplier = 2;
		}
		else
			col_multiplier = 1;
	}
	if(cols > 2 && rows > 2)
		row_multiplier = 0;

	var visible_snippets = num_snippets - (row_multiplier * col_multiplier);

	$.ajax({
		'url' : '/ajax/get_snippets',
		'cache' : false,
		'type' : 'POST',
		'data' : 'num='+visible_snippets+
				'&sport='+global_sport,
		'success' : function (responseData, textStatus) {
			// Success
			if(responseData != '') {
				var responseArray = responseData.split('||');
				var responseData;
				var snippets = [];
				var snippetsTeams = [];
				var i;
				var j = 0;
				var k = 0;
				var m = 0;
				var omit_row = 0;
				var omit_col = 0;
				
				for(i = 0; i < responseArray.length; i++) {
					responseData = responseArray[i].split('|');

					snippets[i] = [];
					snippets[i]['id'] = responseData[0];
					snippets[i]['caption'] = responseData[1];
					snippets[i]['caption_uri'] = responseData[2];
					snippets[i]['rumor'] = responseData[3];
					snippets[i]['team_string'] = responseData[4];
					snippets[i]['new'] = responseData[5];

					snippetsTeams[i] = snippets[i]['team_string'].split(',');
				}

				visible_snippets = (responseArray.length < visible_snippets) ? responseArray.length : visible_snippets;
				
				// Loop through all snippets positioning them and inserting them in the page
				for(i=0; i < visible_snippets; i++)
				{
					zindex = 100 + i;
					snippet_left_pos = (j * snippet_width) + Math.floor(Math.random() * snippet_horiz_padding);
					snippet_top_pos = (k * snippet_height) + Math.floor(Math.random() * snippet_vert_padding);
					
					if(snippet_left_pos <= 10)
						snippet_left_pos += 10;
					if(snippet_top_pos <= 10)
						snippet_top_pos += 10;

					if(rows > 2) {
						if(row_char == 'even') {
							if((k == ((rows / 2)-1)) || (k == ((rows / 2))))
								omit_row = 1;
						}
						else
							if(k == Math.floor(rows / 2))
								omit_row = 1;
					}

					if(cols > 2) {
						if(col_char == 'even') {
							if((j == ((cols / 2)-1)) || (j == ((cols / 2))))
								omit_col = 1;
						}
						else
							if(j == Math.floor(cols / 2))
								omit_col = 1;
					}

					var logo = '';
					if(snippetsTeams[m].length == 1 && snippetsTeams[m][0] != '0')
						logo = '<div style="position: absolute; top: 113px; right: 1px;">'+
										'<img src="/img/teams/'+global_sport+'/'+snippetsTeams[m][0]+'.png" width="60" height="31" />'+
									'</div>';
					else if(snippetsTeams[m].length == 2)
						logo = '<div style="position: absolute; top: 113px; right: 46px;">'+
										'<img src="/img/teams/'+global_sport+'/'+snippetsTeams[m][0]+'.png" width="60" height="31" />'+
									'</div>'+
									'<div style="position: absolute; top: 113px; right: 1px;">'+
										'<img src="/img/teams/'+global_sport+'/'+snippetsTeams[m][1]+'.png" width="60" height="31" />'+
									'</div>';

					var newIcon = '';
					if(snippets[i]['new'] == '1')
						newIcon = '<div style="position: absolute; top: -10px; right: -10px;">'+
									'<img src="/img/new.png" width="50" height="23" />'+
								'</div>';
					
					if(!(omit_row && omit_col)) {
						$('body').prepend(
							'<div id="snippet_'+snippets[m]['id']+'" class="snippet_container" style="z-index: '+zindex+'; display: none; position: absolute; top: '+snippet_top_pos+'px; left: '+snippet_left_pos+'px; height: 150px; width: 214px; background-image: URL(\'/img/quote_up_right_bg.png\'); background-repeat: no-repeat; background-position: left;">'+
								'<div style="position: absolute; top: 5px; left: 5px; height: 105px; width: 190px; overflow: hidden; color: #FFF; font-size: 8pt; font-family: verdana;">'+
									'<a class="snippet_anchor" href="#'+snippets[m]['caption_uri']+'"><span style="font-weight: bold;">' + snippets[m]['caption'] + '</span> ' + snippets[m]['rumor'] +'</a>'+ 
								'</div>'+
								'<div style="position: absolute; top: 97px; right: 3px; width: 20px; overflow: hidden; color: #FFF; font-size: 7pt; font-family: verdana;">'+
									'&#8230;'+
								'</div>'+
								logo+
								newIcon+
							'</div>'
						);
						m++;
					}

					omit_row = 0;
					omit_col = 0;
							
					if((i+1) % rows == 0) {
						j++;
						k = 0;
					}
					else
						k++;
				}
				
				$('.snippet_container').each(function() {
					$(this).fadeIn(1000);
				});

				hideWaiting();

				$('.snippet_anchor').click(function () {
					var hash = this.href;
					hash = hash.replace(/^.*#/, '');
					$.historyLoad(hash);
					
					return false;
				});
			}
			// Error
			else {
				hideWaiting();
				// TODO - Add AJAX error handling
			}
		},
		'error' : function (XMLHttpRequest, textStatus, errorThrown) {
		  	// TODO - Add AJAX error handling
		}
	});
}

function showFullRumor()
{
	var caption_uri = arguments[0] || 0;
	var html_referrer = arguments[1] || 0;
	
	addOverlay();
	showWaiting('GETTING THE FULL STORY...', 'white');

    $.ajax({
		'url' : '/ajax/get_full_rumors',
		'cache' : false,
		'type' : 'POST',
		'data' : 'caption_uri='+caption_uri+
				'&sport='+global_sport,
		'success' : function (responseData, textStatus) {
			// Success
			if(responseData != '') {
				hideWaiting();
				
				var responseArray = responseData.split('|||');
				var fullRumorArray = responseArray[0].split('|');
				var commentArray = responseArray[1].split('||');
				var rumorListArray = responseArray[2].split('||');
				var verdict = responseArray[3];

				var full_height = $(window).height() - 70;
				var full_bg_height = full_height - 190;
				var full_content_height = full_height - 85;
				var text_content_height = full_content_height - 150;
				var full_left_pos = ($(document).width() / 2) - (840 / 2);
				
				var rumor = [];
				var rumorTeams = [];
				var rumor_list_height = full_content_height - 528;
				
				rumor['id'] = fullRumorArray[0];
				rumor['author'] = fullRumorArray[1];
				rumor['source'] = fullRumorArray[2];
				rumor['source_date'] = fullRumorArray[3];
				rumor['source_uri'] = fullRumorArray[4];
				rumor['caption'] = fullRumorArray[5];
				rumor['question'] = fullRumorArray[6];
				rumor['rumor'] = fullRumorArray[7];
				rumor['score'] = fullRumorArray[8];
				rumor['verdict_yes'] = fullRumorArray[9];
				rumor['verdict_no'] = fullRumorArray[10];
				rumor['team_string'] = fullRumorArray[11];
	
				rumorTeams = rumor['team_string'].split(',');
				
				// Adjust text content height if the caption is too long
				if(rumor['caption'].length > 90)
					text_content_height = text_content_height - 70;
				else if(rumor['caption'].length > 60)
					text_content_height = text_content_height - 48;
				else if(rumor['caption'].length > 30)
					text_content_height = text_content_height - 25;
				
				rumor['author'] = (rumor['author'] == '') ? rumor['author'] : rumor['author'] + ', ';
				
				if(rumor['source_uri'].length > 0)
					rumor['source_string'] = '<a style="color: #6A7073;" href="'+rumor['source_uri']+'" target="source">'+rumor['author'].toUpperCase() + rumor['source'].toUpperCase()+'</a>';
				else
					rumor['source_string'] = rumor['author'].toUpperCase() + rumor['source'].toUpperCase();
				
				var i;
				var commentItem;
				var commentString = '';
				
				if(commentArray.length == 1 && commentArray[0] == '')
				{
					commentString = '<div class="add_first_comment" style="position: relative; font-size: 9pt; color: #000; text-align: center; font-style: italic;"><br /><br /><a class="js_link" style="color: black;" onclick="addComment('+rumor['id']+');">Add the first comment!</a></div>';
				}
				else
				{
					for(i=0; i < commentArray.length; i++)
					{
						commentItem = [];
						commentItem = commentArray[i].split('|');
						
						commentString += '<div style="position: relative; font-size: 9pt; color: #000;"><span style="font-weight: bold;">'+commentItem[2]+'</span> on <span style="font-style: italic;">'+commentItem[1]+'</span><div style="padding: 5px;">'+commentItem[0]+'</div></div>';
						commentString += '<div style="width: 300px; height: 1px; padding: 0px 30px; margin: 10px auto 10px auto; background-color: #000;"></div>';
					}
				}
				
				var rumorListItem;
				var rumorList = '';
				for(i=0; i < rumorListArray.length; i++)
				{
					rumorListItem = [];
					rumorListItem = rumorListArray[i].split('|');

					if((i % 2) == 0)
						bgColor = 'transparent';
					else
						bgColor = '#000';
					
					rumorList += '<div style="font-size: 9pt; color: #FFF; padding: 4px 2px; background-color: '+bgColor+'"><a href="#'+rumorListItem[0]+'" onclick="$.historyLoad(\''+rumorListItem[0]+'\'); return false;">'+rumorListItem[1]+'</a></div>';
				}
				
				if(verdict != 'null')
				{
					verdict_select_container_display = 'none';
					verdict_img_src = '/img/'+verdict+'.png';
					verdict_img_container_display = 'block';
				}
				else
				{
					verdict_select_container_display = 'block';
					verdict_img_src = '/img/no.png';
					verdict_img_container_display = 'none';
				}

				$('body').append(
					 '<div id="full_'+rumor['id']+'" class="full_container" style="display: none; position: absolute; top: 0px; left: '+full_left_pos+'px; height: '+full_height+'px; width: 816px; z-index: 1001; padding: 0px; overflow: hidden;">'+
						'<div class="full_content" style="position: absolute; left: 15px; top: 60px; height: '+full_content_height+'px; width: 465px; padding: 0px; z-index: 1003; overflow: hidden;">'+
							'<div style="padding-bottom: 5px;"><h1>'+rumor['caption'].toUpperCase()+'</h1></div>'+
							'<h2>'+rumor['source_string']+'</h2>'+
							'<h3 style="float: left;">'+rumor['source_date'].toUpperCase()+'</h3>'+
							'<div id="share_this" style="float: right; padding: 0px 8px 1px 0px;"><a class="js_link" onclick="void(0);"><img src="/img/sharethis_icon.gif" /></a></div>'+
							'<div style="width: 300px; height: 1px; padding: 0px 30px; margin: 25px auto 10px auto; background-color: #000;"></div>'+
							'<div class="text_content" style="height: '+text_content_height+'px; display: none; font-size: 10pt; padding-bottom: 0px; overflow: auto;">'+rumor['rumor']+'<br /><br /></div>'+
							'<div style="width: 300px; height: 1px; padding: 0px 30px; margin: 10px auto; background-color: #000;"></div>'+
							'<div class="comment_container" style="position: relative; height: 20px; display: none; overflow: hidden;">'+
								'<h1 style="text-align: left; padding: 0px 0px 5px 0px; color: #000;">COMMENTS</h1>'+
								'<div style="position: absolute; top: 1px; right: 10px;"><a class="js_link" onclick="toggleComments('+text_content_height+');"><img id="comment_toggle" src="/img/show_comments.png" /></a></div>'+
								'<div class="add_comment" style="position: absolute; top: 2px; right: 205px; display: none;"><a class="js_link" onclick="addComment('+rumor['id']+');"><img src="/img/add_comment.png" /></a></div>'+
								'<div class="comments" style="position: relative; margin-top: 10px; overflow: auto;">'+
									''+commentString+''+
								'</div>'+
							'</div>'+
						'</div>'+
						'<div class="full_content" style="position: absolute; right: 12px; top: 60px; height: '+full_content_height+'px; width: 310px; padding: 0px; z-index: 1003; overflow: hidden;">'+
							'<div style="text-align: center; padding-top: 0px; height: 130px;"><img src="/img/meter_'+rumor['score']+'.jpg" /></div>'+
							'<div style="text-align: center; padding: 4px 4px 4px 4px; color: #FFF; font-weight: bold; font-size: 10pt;">'+rumor['question']+'</div>'+
							'<div class="verdicts_yes" style="position: absolute; top: 99px; left: 72px; color: #FFF; font-size: 10pt; font-weight: bold;">'+rumor['verdict_yes']+'</div>'+
							'<div class="verdicts_no" style="position: absolute; top: 99px; left: 185px; color: #F11820; font-size: 10pt; font-weight: bold;">'+rumor['verdict_no']+'</div>'+
							'<div id="verdict_select_container" style="width: 250px; height: 50px; margin: 0px auto; padding-bottom: 10px; display: '+verdict_select_container_display+'">'+
								'<a class="js_link" onclick="submitVerdict('+rumor['id']+', \'yes\');"><img style="float: left;" src="/img/yes_button.png" /></a>'+
								'<a class="js_link" onclick="submitVerdict('+rumor['id']+', \'no\');"><img style="float: right;" src="/img/no_button.png" /></a>'+
							'</div>'+
							'<div id="verdict_img_container" style="width: 250px; height: 50px; margin: 0px auto; padding-bottom: 10px; display: '+verdict_img_container_display+';">'+
								'<img id="verdict_img" style="float: right;" src="'+verdict_img_src+'" />'+
								'<div style="width: 120px; height: 34px; padding-top: 16px; font-weight: bold; font-size: 12pt; font-style: italic; color: #FFF; overflow: hidden;">Your Verdict: </div>'+
							'</div>'+
							'<div style="text-align: center; padding-bottom: 10px;">'+
								'<div style="font-size: 0.625em; color: #6A7073; text-align: center; padding-top: 1px;">ADVERTISEMENT</div>'+
								'<div class="box_ad" style="width: 300px; height: 250px; border: 1px solid black; margin: 5px auto;"></div>'+
							'</div>'+
							'<div style="position: relative; padding: 0px 0px 0px 3px;">'+
								'<h1 style="text-align: left; padding: 0px 0px 5px 0px; color: #FFF;">ALL RUMORS</h1>'+
								'<div style="position: absolute; top: 0px; right: 5px;"><a class="js_link" onclick="scrollDivDown(\'.rumor_list\', 64);"><img src="/img/scroll_down_white.png" /></a></div>'+
								'<div style="position: absolute; top: 0px; right: 30px;"><a class="js_link" onclick="scrollDivUp(\'.rumor_list\', 64);"><img src="/img/scroll_up_white.png" /></a></div>'+
								'<div class="rumor_list" style="height: '+rumor_list_height+'px; overflow: hidden;">'+rumorList+'</div>'+
							'</div>'+
						'</div>'+
						'<div style="position: absolute; right: 0px; top: 10px; height: 60px; width: 60px; z-index: 1004;"><a class="close_foreground"><img src="/img/close.png" /></a></div>'+
						'<div style="position: absolute; left: 0px; top: 40px; height: 20px; width: 816px; background-image: URL(\'/img/article_top.png\'); z-index: 1002;"></div>'+
						'<div class="full_bg" style="position: absolute; left: 0px; top: 60px; height: '+full_bg_height+'px; width: 816px; background-image: URL(\'/img/article_bg.png\'); z-index: 1002;"></div>'+
						'<div style="position: absolute; left: 0px; bottom: 0px; height: 130px; width: 816px; background-image: URL(\'/img/article_bottom.png\'); z-index: 1002;"></div>'+
					'</div>'
				);

				SHARETHIS.addEntry({
					title: ""+rumor['caption']+"",
					summary: rumor['rumor'].substring(0,160),
					url: 'http://www.bustarumor.com/#'+caption_uri},
					{button: false}).attachButton(document.getElementById("share_this"));
				SHARETHIS.onReady();
				
				$('#full_'+rumor['id']).show("slide", { direction: "down" }, 500, function() {
					$('.text_content').show();
					$('.comment_container').show();
					
					var box_ad_position = $('.box_ad').offset();
					$('.adsense').css({'top' : (box_ad_position.top+1)+'px', 'left' : (box_ad_position.left+1)+'px', 'display' : 'block'});
					
					if(html_referrer == 0)
					{
						$('.close_foreground').attr('href', '/#');
						$('.close_foreground').click(function() {
							$.historyLoad('');
							return false;
						});		
					}
					else
						$('.close_foreground').attr('href', 'http://'+location.hostname);
					
				});
			}
			// Error
			else {
				// TODO - Add AJAX error handling
			}
		},
		'error' : function (XMLHttpRequest, textStatus, errorThrown) {
		  	// TODO - Add AJAX error handling
		}
	});
}

function submitVerdict()
{
	var rumor_id = arguments[0] || '';
	var verdict = arguments[1] || '';
	
	if(verdict == 'yes' || verdict == 'no')
	{
		$('#verdict_select_container').fadeOut('slow', function(){
			if(verdict == 'yes')
				$('#verdict_img').attr('src', '/img/yes.png');
			else
				$('#verdict_img').attr('src', '/img/no.png');

			$('#verdict_img_container').fadeIn('slow');
		});

		var verdict_count = Number($('.verdicts_'+verdict).text()) + 1;
		$('.verdicts_'+verdict).text(verdict_count);
		
		$.ajax({
			'url' : '/ajax/submit_verdict',
			'cache' : false,
			'type' : 'POST',
			'data' : 'rumor_id='+rumor_id+'&verdict='+verdict,
			'success' : function (responseData, textStatus) {
				if(responseData != '') {
					alert(responseData);
				}
			}
		});
	}
	else
		return;
}

function showNews()
{
	var title_uri = arguments[0] || 0;
	
	addOverlay();
	showWaiting('SCANNING THE HEADLINES...', 'white');

    $.ajax({
		'url' : '/ajax/get_news',
		'cache' : false,
		'type' : 'POST',
		'data' : 'title_uri='+title_uri+
				'&sport='+global_sport,
		'success' : function (responseData, textStatus) {
			// Success
			if(responseData != '') {
				hideWaiting();

				var responseArray = responseData.split('|||');
				var fullNewsArray = responseArray[0].split('|');
				var newsListArray = responseArray[1].split('||');
				
				var news = [];
				var full_height = $(window).height() - 70;
				var full_bg_height = full_height - 190;
				var full_content_height = full_height - 85;
				var full_left_pos = ($(document).width() / 2) - (840 / 2);
				var news_list_height = full_content_height - 295;
				
				news['id'] = fullNewsArray[0];
				news['link'] = fullNewsArray[1];
				news['title'] = fullNewsArray[2];
				news['description'] = fullNewsArray[3];
				news['pubdate'] = fullNewsArray[4];
				
				var i;
				var newsListItem;
				var newsList = '';
				for(i=0; i < newsListArray.length; i++)
				{
					newsListItem = [];
					newsListItem = newsListArray[i].split('|');

					if((i % 2) == 0)
						bgColor = 'transparent';
					else
						bgColor = '#000';
					
					newsList += '<div style="font-size: 9pt; color: #FFF; padding: 4px 4px; background-color: '+bgColor+'"><a href="#news-'+newsListItem[0]+'" onclick="$.historyLoad(\'news-'+newsListItem[0]+'\');">'+newsListItem[1]+'</a></div>';
				}

				$('body').append(
					 '<div id="full_'+news['id']+'" class="full_container" style="display: none; position: absolute; top: 0px; left: '+full_left_pos+'px; height: '+full_height+'px; width: 816px; z-index: 1001; padding: 0px; overflow: hidden;">'+
						'<div class="full_content" style="position: absolute; left: 15px; top: 60px; height: '+full_content_height+'px; width: 465px; padding: 0px; z-index: 1003; overflow: hidden;">'+
							'<div style="padding-bottom: 5px;"><h1>'+news['title'].toUpperCase()+'</h1></div>'+
							'<h3 style="float: left;">'+news['pubdate'].toUpperCase()+'</h3>'+
							'<div id="share_this" style="float: right; padding: 0px 8px 1px 0px;"><a class="js_link" onclick="void(0);"><img src="/img/sharethis_icon.gif" /></a></div>'+
							'<div style="width: 300px; height: 1px; padding: 0px 30px; margin: 25px auto 10px auto; background-color: #000;"></div>'+
							'<div style="font-size: 10pt; padding-bottom: 20px;">'+news['description']+'</div>'+
							'<div style="font-size: 10pt; font-weight: bold;"><a style="color: black;" target="news" href="'+news['link']+'">Read Full Article</a></div>'+
						'</div>'+
						'<div class="full_content" style="position: absolute; right: 12px; top: 60px; height: '+full_content_height+'px; width: 310px; padding: 0px; z-index: 1003; overflow: hidden;">'+
							'<div style="text-align: center; padding-bottom: 10px;">'+
								'<div style="font-size: 0.625em; color: #6A7073; text-align: center;">ADVERTISEMENT</div>'+
								'<div class="box_ad" style="width: 300px; height: 250px; border: 1px solid black; margin: 5px auto;"></div>'+
							'</div>'+
							'<div style="position: relative; padding: 0px 0px 0px 3px;">'+
								'<h1 style="text-align: left; padding: 0px 0px 5px 0px; color: #FFF;">NEWS HEADLINES</h1>'+
								'<div style="position: absolute; top: 0px; right: 5px;"><a class="js_link" onclick="scrollDivDown(\'.news_list\', 96);"><img src="/img/scroll_down_white.png" /></a></div>'+
								'<div style="position: absolute; top: 0px; right: 30px;"><a class="js_link" onclick="scrollDivUp(\'.news_list\', 96);"><img src="/img/scroll_up_white.png" /></a></div>'+
								'<div class="news_list" style="height: '+news_list_height+'px; overflow: hidden;">'+newsList+'</div>'+
							'</div>'+
						'</div>'+
						'<div style="position: absolute; right: 0px; top: 10px; height: 60px; width: 60px; z-index: 1004;"><a class="close_foreground"><img src="/img/close.png" /></a></div>'+
						'<div style="position: absolute; left: 0px; top: 40px; height: 20px; width: 816px; background-image: URL(\'/img/article_top.png\'); z-index: 1002;"></div>'+
						'<div class="full_bg" style="position: absolute; left: 0px; top: 60px; height: '+full_bg_height+'px; width: 816px; background-image: URL(\'/img/article_bg.png\'); z-index: 1002;"></div>'+
						'<div style="position: absolute; left: 0px; bottom: 0px; height: 130px; width: 816px; background-image: URL(\'/img/article_bottom.png\'); z-index: 1002;"></div>'+
					'</div>'
				);

				SHARETHIS.addEntry({
					title: ""+news['title']+"",
					summary: news['description'].substring(0,160),
					url: 'http://www.bustarumor.com/#news-'+title_uri},
					{button: false}).attachButton(document.getElementById("share_this"));
				SHARETHIS.onReady();
				
				$('#full_'+news['id']).show("slide", { direction: "down" }, 1000, function() {
					
					var box_ad_position = $('.box_ad').offset();
					$('.adsense').css({'top' : (box_ad_position.top+1)+'px', 'left' : (box_ad_position.left+1)+'px', 'display' : 'block'});
					
					$('.close_foreground').attr('href', '/#');
					$('.close_foreground').click(function() {
						$.historyLoad('');
						return false;
					});
				});
			}
			// Error
			else {
				// TODO - Add AJAX error handling
			}
		},
		'error' : function (XMLHttpRequest, textStatus, errorThrown) {
		  	// TODO - Add AJAX error handling
		}
	});
}

function showRegistration()
{
	addOverlay();

	var full_height = $(window).height() - 20;
	var full_width = 616;
	var clipboard_bg_height = full_height - 30; // top close button overhang
	var full_content_height = full_height - 80; // 50 for corners, 30 for top close button overhang
	var full_content_width = full_width - 70; // 50 for corners, 20 for right close button overhang
	var full_left_pos = ($(document).width() / 2) - (full_width / 2);

	$('body').append(
		 '<div id="full_registration" class="full_container" style="display: none; position: absolute; top: 0px; left: '+full_left_pos+'px; height: '+full_height+'px; width: '+full_width+'px; z-index: 1001; overflow: hidden;">'+
			'<div class="text_content" style="position: absolute; left: 25px; top: 55px; height: '+(full_content_height-40)+'px; width: '+(full_content_width-40)+'px; background-color: white; border: 1px solid black; padding: 20px; z-index: 1003; display: none; overflow: auto;">'+
				'<div><h1 style="float: left;">Registration</h1><span style="font-size: 10pt; color: #6A7073;">&nbsp;&nbsp;| <a class="js_link" style="color: #6A7073;" onclick="$(\'.text_content\').scrollTop('+(full_content_height-40)+');">Why Register?</a></span></div>'+
				'<div style="width: 300px; height: 1px; padding: 0px 20px; margin: 20px auto 20px auto; background-color: #000;"></div>'+
				'<div style="font-size: 10pt;">'+
					'<form id="register" name="register">'+
					'<fieldset class="ff_container">'+
						'<legend>Please introduce yourself</legend>'+
						'<div><label for="username">Username: </label><input id="username" name="username" type="text" class="ff_input_blur" title="Your username cannot be changed after registration, and will be how other users identify you. Alpha-numeric characters only please." onFocus="focusFormField(this);" onBlur="blurFormField(this);" /></div>'+
						'<br />'+
						'<div><label for="email">Email: </label><input id="email" name="email" type="text" class="ff_input_blur" style="margin-left: 31px;" title="Either your email address or your username can be used when logging in. A valid email address is required to participate on this site." onFocus="focusFormField(this);" onBlur="blurFormField(this);" /></div>'+
						'<br />'+
						'<div class="ff_error_text" id="ff_username_container"></div>'+
						'<div class="ff_error_text" id="ff_email_container"></div>'+
						'<div class="ff_help_container"></div>'+
					'</fieldset>'+
					'<br />'+
					'<fieldset class="ff_container">'+
						'<legend>Please select a password</legend>'+
						'<div><label for="password">Password: </label><input id="password" name="password" type="password" class="ff_input_blur" style="margin-left: 54px;" title="Your username and email address cannot be used as your password." onFocus="focusFormField(this);" onBlur="blurFormField(this);" /></div>'+
						'<br />'+
						'<div><label for="confirm_password">Confirm Password: </label><input id="confirm_password" name="confirm_password" type="password" class="ff_input_blur" title="You know the drill." onFocus="focusFormField(this);" onBlur="blurFormField(this);" /></div>'+
						'<br />'+
						'<div class="ff_error_text" id="ff_password_container"></div>'+
						'<div class="ff_error_text" id="ff_confirm_password_container"></div>'+
						'<div class="ff_help_container"></div>'+
					'</fieldset>'+
					'<br />'+
					'<div style="position: relative; width: 420px; height: 50px; padding: 5px; color: #2e2e2e; font-size: 9pt;">'+
						'<div style="float: left; width: 235px; padding: 2px 0px;">By registering, you indicate that you agree to our <a style="font-weight: bold; color: #2e2e2e;" href="#">Privacy Policy</a> and <a style="font-weight: bold; color: #2e2e2e;" href="#">Terms of Use</a>.</div>'+
						'<a id="submit_registration" class="js_link" onclick="submitRegistration(); return false;"><img style="float: right;" src="/img/submit_button.png" /></a>'+
						'<div id="submit_registration_wait" style="display: none; position: absolute; top: 12px; right: 0px;"><img src="/img/loading_small.gif" /></div>'+
					'</div>'+
					'</form>'+
				'</div>'+
				'<div style="width: 300px; height: 1px; margin: 20px auto 10px auto; background-color: #000;"></div>'+
				'<img style="margin: 0px auto;" src="/img/why_register.gif" />'+
			'</div>'+
			'<div style="position: absolute; right: 0px; top: 10px; height: 60px; width: 60px; z-index: 1004;"><a class="close_foreground"><img src="/img/close.png" /></a></div>'+
			'<div style="position: absolute; left: 0px; top: 30px; height: 25px; width: 25px; background-image: URL(\'/img/clipboard_topleft_bg.png\'); z-index: 1002;"></div>'+
			'<div style="position: absolute; left: 0px; top: '+(clipboard_bg_height+5)+'px; height: 25px; width: 25px; background-image: URL(\'/img/clipboard_bottomleft_bg.png\'); z-index: 1002;"></div>'+
			'<div style="position: absolute; right: 20px; top: 30px; height: 25px; width: 25px; background-image: URL(\'/img/clipboard_topright_bg.png\'); z-index: 1002;"></div>'+
			'<div style="position: absolute; right: 20px; top: '+(clipboard_bg_height+5)+'px; height: 25px; width: 25px; background-image: URL(\'/img/clipboard_bottomright_bg.png\'); z-index: 1002;"></div>'+
			'<div style="position: absolute; left: 25px; top: 30px; height: '+clipboard_bg_height+'px; width: '+full_content_width+'px; background-image: URL(\'/img/clipboard_bg.gif\'); z-index: 1002;"></div>'+
			'<div style="position: absolute; left: 0px; top: 55px; height: '+(clipboard_bg_height-50)+'px; width: 25px; background-image: URL(\'/img/clipboard_bg.gif\'); z-index: 1002;"></div>'+
			'<div style="position: absolute; right: 20px; top: 55px; height: '+(clipboard_bg_height-50)+'px; width: 25px; background-image: URL(\'/img/clipboard_bg.gif\'); z-index: 1002;"></div>'+
		'</div>'
	);

	$('#full_registration').show("slide", { direction: "down" }, 1000, function() {
		$('form#register input').keypress(function (k) { if (k.which == 13) submitRegistration(); });
		
		$('.text_content').show();
		
		$('.close_foreground').attr('href', '/#');
		$('.close_foreground').click(function() {
			$.historyLoad('');
			return false;
		});
	});
}

function submitRegistration() {
	$('#submit_registration').hide();
	$('#submit_registration_wait').show();
	$('input').attr('disabled', 'disabled');

	$('form#register').children('.ff_container').children().css('background-image', 'none');
	$('form#register').children('.ff_container').children('.ff_error_text').html('');
	
	$.ajax({
		'url' : '/ajax/register',
		'cache' : false,
		'type' : 'POST',
		'data' : 'username='+$('#username').val()+
				'&email='+$('#email').val()+
				'&password='+$('#password').val()+
				'&confirm_password='+$('#confirm_password').val(),
		'success' : function (responseData, textStatus) {
			// Error
			if(responseData != '') {
				var responseArray = responseData.split('||');
				var error_fields = responseArray[0].split('|');
				var error_messages = responseArray[1].split('|');
				
				var i;
				for(i = 0; i < error_fields.length; i++) {
					$('#'+error_fields[i]).parent().css({
						'background-image' : 'URL(/img/form_validation_error.gif)',
						'background-position' : '95% 50%',
						'background-repeat' : 'no-repeat'
					});
					$('#ff_'+error_fields[i]+'_container').html(error_messages[i]);
				}

				$('#submit_registration').show();
				$('#submit_registration_wait').hide();
				$('input').attr('disabled', '');	
			}
			// No error
			else {
				window.location = 'http://www.bustarumor.com/';
			}
		},
		'error' : function (XMLHttpRequest, textStatus, errorThrown) {
		  	// TODO - Add AJAX error handling
		}
	});
}

function showLogin()
{
	addOverlay();

	var full_height = $(window).height() - 70;
	var full_bg_height = full_height - 190;
	var full_content_height = full_height - 85;
	var full_left_pos = ($(document).width() / 2) - (840 / 2);

	$('body').append(
		 '<div id="full_login" class="full_container" style="display: none; position: absolute; top: 0px; left: '+full_left_pos+'px; height: '+full_height+'px; width: 816px; z-index: 1001; padding: 0px; overflow: hidden;">'+
			'<div class="full_content" style="position: absolute; left: 15px; top: 60px; height: '+full_content_height+'px; width: 465px; padding: 0px; z-index: 1003; overflow: hidden;">'+
				'<div style="padding-bottom: 5px;"><h1>Login</h1></div>'+
				'<div style="width: 300px; height: 1px; padding: 0px 30px; margin: 20px auto 20px auto; background-color: #000;"></div>'+
				'<div style="font-size: 10pt;">'+
					'<form id="login" name="login">'+
					'<fieldset class="ff_container">'+
						'<legend>Please make yourself at home</legend>'+
						'<div><label for="username_email">Username/Email: </label><input id="username_email" name="username_email" type="text" class="ff_input_blur" title="" onFocus="focusFormField(this);" onBlur="blurFormField(this, 1, 1);" /></div>'+
						'<br />'+
						'<div><label for="password">Password: </label><input id="password" name="password" type="password" class="ff_input_blur" style="margin-left: 41px;" title="" onFocus="focusFormField(this);" onBlur="blurFormField(this, 1, 1);" /></div>'+
						'<br />'+
						'<div class="ff_error_text" id="ff_username_email_container"></div>'+
						'<div class="ff_error_text" id="ff_password_container"></div>'+
						'<div class="ff_help_container"></div>'+
					'</fieldset>'+
					'<br />'+
					'<div style="position: relative; width: 420px; padding: 5px; color: #2e2e2e; font-size: 9pt;">'+
						'<div style="float: left; width: 255px; padding: 7px 0px;">Don\'t have an account?&nbsp;<a href="#register" style="font-weight: bold; color: #2e2e2e;" onclick="$.historyLoad(\'register\'); return false;">Register Now!</a><br /><a class="js_link" style="font-weight: bold; color: #2e2e2e;" onclick="showLostPassword();">Forgot Password?</a></div>'+
						'<a id="submit_login" class="js_link" onclick="submitLogin(); return false;"><img style="float: right;" src="/img/submit_button.png" /></a>'+
						'<div id="submit_login_wait" style="display: none; position: absolute; top: 12px; right: 0px;"><img src="/img/loading_small.gif" /></div>'+
					'</div>'+
					'</form>'+
				'</div>'+	
			'</div>'+
			'<div class="full_content" style="position: absolute; right: 12px; top: 60px; height: '+full_content_height+'px; width: 310px; padding: 0px; z-index: 1003; overflow: hidden;">'+
				'<div style="text-align: center;">'+
					'<div style="font-size: 0.625em; color: #6A7073; text-align: center;">ADVERTISEMENT</div>'+
					'<div class="box_ad" style="width: 300px; height: 250px; border: 1px solid black; margin: 5px auto;"></div>'+
				'</div>'+
			'</div>'+
			'<div style="position: absolute; right: 0px; top: 10px; height: 60px; width: 60px; z-index: 1004;"><a class="close_foreground"><img src="/img/close.png" /></a></div>'+
			'<div style="position: absolute; left: 0px; top: 40px; height: 20px; width: 816px; background-image: URL(\'/img/article_top.png\'); z-index: 1002;"></div>'+
			'<div class="full_bg" style="position: absolute; left: 0px; top: 60px; height: '+full_bg_height+'px; width: 816px; background-image: URL(\'/img/article_bg.png\'); z-index: 1002;"></div>'+
			'<div style="position: absolute; left: 0px; bottom: 0px; height: 130px; width: 816px; background-image: URL(\'/img/article_bottom.png\'); z-index: 1002;"></div>'+
		'</div>'
	);

	$('#full_login').show("slide", { direction: "down" }, 1000, function() {
		$('form#login input').keypress(function (k) { if (k.which == 13) submitLogin(); });
		
		var box_ad_position = $('.box_ad').offset();
		$('.adsense').css({'top' : (box_ad_position.top+1)+'px', 'left' : (box_ad_position.left+1)+'px', 'display' : 'block'});
	
		$('.close_foreground').attr('href', '/#');
		$('.close_foreground').click(function() {
			$.historyLoad('');
			return false;
		});
	});
}

function submitLogin() {
	$('#submit_login').hide();
	$('#submit_login_wait').show();
	$('input').attr('disabled', 'disabled');

	$('form#login').children('.ff_container').children().css('background-image', 'none');
	$('form#login').children('.ff_container').children('.ff_error_text').html('');

	$.ajax({
		'url' : '/ajax/login',
		'cache' : false,
		'type' : 'POST',
		'data' : 'username_email='+$('#username_email').val()+'&password='+$('#password').val(),
		'success' : function (responseData, textStatus) {
			// Error
			if(responseData != '') {
				var responseArray = responseData.split('||');
				var error_fields = responseArray[0].split('|');
				var error_messages = responseArray[1].split('|');
				
				var i;
				for(i = 0; i < error_fields.length; i++) {
					$('#'+error_fields[i]).parent().css({
						'background-image' : 'URL(/img/form_validation_error.gif)',
						'background-position' : '95% 50%',
						'background-repeat' : 'no-repeat'
					});
					$('#ff_'+error_fields[i]+'_container').html(error_messages[i]);
				}

				$('#submit_login').show();
				$('#submit_login_wait').hide();
				$('input').attr('disabled', '');	
			}
			// No error
			else {
				window.location = '/';
			}
		},
		'error' : function (XMLHttpRequest, textStatus, errorThrown) {
		  	// TODO - Add AJAX error handling
		}
	});
}

function showAdminCP()
{
	addOverlay();
	showWaiting('HERE COMES THE BOSS...', 'white');
	
	var full_height = $(window).height() - 70;
	var full_bg_height = full_height - 190;
	var full_content_height = full_height - 85;
	var full_left_pos = ($(document).width() / 2) - (840 / 2);
	var text_content_height = full_content_height - 100;
	var rumor_list_height = full_content_height - 280;
	
	$.ajax({
		'url' : '/ajax/get_rumor_list',
		'cache' : false,
		'type' : 'POST',
		'data' : 'sport='+global_sport,
		'success' : function (responseData, textStatus) {
			var rumorListArray = responseData.split('||');
			var rumorListItem;
			var rumorList = '';
			
			for(i=0; i < rumorListArray.length; i++)
			{
				if(rumorListArray[0].length)
				{
					rumorListItem = [];
					rumorListItem = rumorListArray[i].split('|');
	
					if((i % 2) == 0)
						bgColor = 'transparent';
					else
						bgColor = '#000';
	
					if(rumorListItem[8] == '1' || rumorListItem[8] == '0')
						textColor = 'grey';
					else
						textColor = 'white';

					global_rumor_data[rumorListItem[0]] = [];
					global_rumor_data[rumorListItem[0]]['caption'] = rumorListItem[1];
					global_rumor_data[rumorListItem[0]]['caption_uri'] = rumorListItem[2];
					global_rumor_data[rumorListItem[0]]['author'] = rumorListItem[3];
					global_rumor_data[rumorListItem[0]]['source'] = rumorListItem[4];
					global_rumor_data[rumorListItem[0]]['source_uri'] = rumorListItem[5];
					global_rumor_data[rumorListItem[0]]['source_date'] = rumorListItem[6];
					global_rumor_data[rumorListItem[0]]['question'] = rumorListItem[7];
					global_rumor_data[rumorListItem[0]]['verdict'] = rumorListItem[8];
					global_rumor_data[rumorListItem[0]]['rumor'] = rumorListItem[9];
					global_rumor_data[rumorListItem[0]]['team_string'] = rumorListItem[10];
					
					rumorList += '<div style="font-size: 9pt; padding: 4px 2px; background-color: '+bgColor+'"><a class="js_link" style="color: '+textColor+';" onclick="loadEditRumor('+rumorListItem[0]+');">'+rumorListItem[1]+'</a></div>';
				}
			}
			
			$.ajax({
				'url' : '/ajax/get_team_list',
				'cache' : false,
				'type' : 'POST',
				'data' : 'sport='+global_sport,
				'success' : function (responseData, textStatus) {	
					hideWaiting();

					var rumorTeamArray = responseData.split('||');
					var rumorTeamItem;
					var rumorTeam = '';
					for(i=0; i < rumorTeamArray.length; i++)
					{
						if(rumorTeamArray[0].length)
						{
							rumorTeamItem = [];
							rumorTeamItem = rumorTeamArray[i].split('|');
							
							rumorTeam += '<option value="'+rumorTeamItem[0]+'">'+rumorTeamItem[1]+'</option>';
						}
					}
					
					$('body').append(
						 '<div id="full_admincp" class="full_container" style="display: none; position: absolute; top: 0px; left: '+full_left_pos+'px; height: '+full_height+'px; width: 816px; z-index: 1001; padding: 0px; overflow: hidden;">'+
							'<div class="full_content" style="position: absolute; left: 15px; top: 60px; height: '+full_content_height+'px; width: 465px; padding: 0px; z-index: 1003; overflow: none;">'+
								'<div style="padding-bottom: 5px;"><h1>Rumor Admin</h1></div>'+
								'<div style="width: 300px; height: 1px; padding: 0px 30px; margin: 20px auto 20px auto; background-color: #000;"></div>'+
								'<div class="text_content" style="font-size: 10pt; display: none; height: '+text_content_height+'px; overflow: auto;">'+
									'<form id="edit_rumor" name="edit_rumor">'+
									'<fieldset class="ff_container">'+
										'<legend>First the source</legend>'+
										'<div><label for="author">Author: </label><input id="author" name="author" type="text" class="ff_input_blur" style="margin-left: 38px;" title="The author who wrote the source article." onFocus="focusFormField(this);" onBlur="blurFormField(this, 1);" /></div>'+
										'<br />'+
										'<div><label for="source">Source: </label><input id="source" name="source" type="text" class="ff_input_blur" style="margin-left: 36px;" title="The source of the article (newspaper or website name)." onFocus="focusFormField(this);" onBlur="blurFormField(this, 1);" /></div>'+
										'<br />'+
										'<div><label for="source_date">Source Date: </label><input id="source_date" name="source_date" type="text" class="ff_input_blur" title="The date on the source article. MUST BE IN THE FORM YYYY-MM-DD" onFocus="focusFormField(this);" onBlur="blurFormField(this);" /></div>'+
										'<br />'+
										'<div><label for="source_uri">Source Link: </label><input id="source_uri" name="source_uri" type="text" class="ff_input_blur" style="margin-left: 5px;" title="The source article\'s URL, if there is one. Double check that it works in a new window before submitting." onFocus="focusFormField(this);" onBlur="blurFormField(this, 1);" /></div>'+
										'<br />'+
										'<div class="ff_error_text" id="ff_author_container"></div>'+
										'<div class="ff_error_text" id="ff_source_container"></div>'+
										'<div class="ff_error_text" id="ff_source_date_container"></div>'+
										'<div class="ff_error_text" id="ff_source_uri_container"></div>'+
										'<div class="ff_help_container"></div>'+
									'</fieldset>'+
									'<br />'+
									'<fieldset class="ff_container">'+
										'<legend>Now the meat</legend>'+
										'<div><label for="caption">Caption: </label><input id="caption" name="caption" type="text" class="ff_input_blur" style="margin-left: 27px;" title="The title of the rumor." onFocus="focusFormField(this);" onBlur="blurFormField(this); nameToURI(this, \'caption_uri\');" /></div>'+
										'<br />'+
										'<div><label for="caption_uri">Caption URI: </label><input id="caption_uri" name="caption_uri" type="text" class="ff_input_blur" title="Don\'t edit this manually unless you know what you\'re doing. This is the address bar friendly version of the caption for linking." onFocus="focusFormField(this);" onBlur="blurFormField(this);" /></div>'+
										'<br />'+
										'<div><label for="question">Question: </label><input id="question" name="question" type="text" class="ff_input_blur" style="margin-left: 17px;" title="The YES/NO question posed by the rumor." onFocus="focusFormField(this);" onBlur="blurFormField(this);" /></div>'+
										'<br />'+
										'<div><label for="rumor">Rumor: </label><br /><textarea id="rumor" name="rumor" style="height: 150px; width: 375px;" title="The story itself. Go through and sanitize special characters by retyping them (quotes, dashes, etc.)."  onFocus="focusFormField(this);" onBlur="blurFormField(this, 1, 1);" /></div>'+
										'<br />'+
										'<div><label for="team_1">Team 1: </label>'+
										'<select id="team_1" name="team_1" class="ff_input_blur" style="margin-left: 24px;" title="Select the first team the rumor relates to." onFocus="focusFormField(this);" onBlur="blurFormField(this, 1);">'+
										'<option value="0"></option>'+
										rumorTeam+			
										'</select></div>'+
										'<br />'+
										'<div><label for="team_2">Team 2: </label>'+
										'<select id="team_2" name="team_2" class="ff_input_blur" style="margin-left: 24px;" title="Optionally, select the second team the rumor relates to." onFocus="focusFormField(this);" onBlur="blurFormField(this, 1);">'+
										'<option value="0"></option>'+
										rumorTeam+
										'</select></div>'+
										'<br />'+
										'<div class="ff_error_text" id="ff_caption_container"></div>'+
										'<div class="ff_error_text" id="ff_caption_uri_container"></div>'+
										'<div class="ff_error_text" id="ff_rumor_container"></div>'+
										'<div class="ff_error_text" id="ff_team_1_container"></div>'+
										'<div class="ff_error_text" id="ff_team_2_container"></div>'+
										'<div class="ff_help_container"></div>'+
									'</fieldset>'+
									'<br />'+
									'<fieldset class="ff_container">'+
										'<legend>Finally, the nuts and bolts</legend>'+
										'<div><label for="rumor_id">Rumor ID: </label><input id="rumor_id" name="rumor_id" type="text" class="ff_input_blur" title="Zero means create a new rumor, otherwise you\'ll be editting whichever rumor\'s ID is here." onFocus="focusFormField(this);" onBlur="blurFormField(this);" /></div>'+
										'<br />'+
										'<div><label for="verdict">Verdict: </label>'+
										'<select id="verdict" name="verdict" class="ff_input_blur" style="margin-left: 11px;" title="The final answer to the YES/NO question posed by the caption. Selecting a verdict will close the rumor and award points to members." onFocus="focusFormField(this);" onBlur="blurFormField(this, 1);">'+
										'<option value="-1"></option>'+
										'<option value="0">No</option>'+
										'<option value="1">Yes</option>'+
										'</select></div>'+
										'<br />'+
										'<div class="ff_error_text" id="ff_rumor_id_container"></div>'+
										'<div class="ff_error_text" id="ff_views_container"></div>'+
										'<div class="ff_error_text" id="ff_verdict_container"></div>'+
										'<div class="ff_help_container"></div>'+
									'</fieldset>'+
									'<br />'+
									'<div style="position: relative; width: 420px; padding: 5px; color: #2e2e2e; font-size: 9pt;">'+
										'<div style="float: left; width: 235px; padding: 2px 0px;"></div>'+
										'<a id="submit_edit_rumor" class="js_link" onclick="submitEditRumor(); return false;"><img style="float: right;" src="/img/submit_button.png" /></a>'+
										'<div id="submit_edit_rumor_wait" style="display: none; position: absolute; top: 12px; right: 0px;"><img src="/img/loading_small.gif" /></div>'+
									'</div><br /><br /><br /><br />'+
									'</form>'+
								'</div>'+	
							'</div>'+
							'<div class="full_content" style="position: absolute; right: 12px; top: 60px; height: '+full_content_height+'px; width: 310px; padding: 0px; z-index: 1003; overflow: hidden;">'+
								'<div style="text-align: center;">'+
									'<div style="font-size: 0.625em; color: #6A7073; text-align: center;">ADVERTISEMENT</div>'+
									'<div class="box_ad" style="width: 300px; height: 250px; border: 1px solid black; margin: 5px auto;"></div>'+
								'</div>'+
								'<div style="position: relative; padding: 5px 0px 0px 3px;">'+
									'<h1 style="text-align: left; padding: 0px 0px 5px 0px; color: #FFF;">ALL RUMORS</h1>'+
									'<div style="position: absolute; top: 0px; right: 5px;"><a class="js_link" onclick="scrollDivDown(\'.rumor_list\', 64);"><img src="/img/scroll_down_white.png" /></a></div>'+
									'<div style="position: absolute; top: 0px; right: 30px;"><a class="js_link" onclick="scrollDivUp(\'.rumor_list\', 64);"><img src="/img/scroll_up_white.png" /></a></div>'+
									'<div class="rumor_list" style="height: '+rumor_list_height+'px; overflow: hidden;">'+rumorList+'</div>'+
								'</div>'+
							'</div>'+
							'<div style="position: absolute; right: 0px; top: 10px; height: 60px; width: 60px; z-index: 1004;"><a class="close_foreground"><img src="/img/close.png" /></a></div>'+
							'<div style="position: absolute; left: 0px; top: 40px; height: 20px; width: 816px; background-image: URL(\'/img/article_top.png\'); z-index: 1002;"></div>'+
							'<div class="full_bg" style="position: absolute; left: 0px; top: 60px; height: '+full_bg_height+'px; width: 816px; background-image: URL(\'/img/article_bg.png\'); z-index: 1002;"></div>'+
							'<div style="position: absolute; left: 0px; bottom: 0px; height: 130px; width: 816px; background-image: URL(\'/img/article_bottom.png\'); z-index: 1002;"></div>'+
						'</div>'
					);

					$('#full_admincp').show("slide", { direction: "down" }, 1000, function() {
						$('form#edit_rumor input').keypress(function (k) { if (k.which == 13) submitEditRumor(); });
						$('.text_content').show();
						
						var box_ad_position = $('.box_ad').offset();
						$('.adsense').css({'top' : (box_ad_position.top+1)+'px', 'left' : (box_ad_position.left+1)+'px', 'display' : 'block'});
					
						$('.close_foreground').attr('href', '/#');
						$('.close_foreground').click(function() {
							$.historyLoad('');
							return false;
						});
					});
				}
			});
		}
	});
}

function submitEditRumor() {
	$('#submit_edit_rumor').hide();
	$('#submit_edit_rumor_wait').show();
	$('input').attr('disabled', 'disabled');

	$('form#edit_rumor').children('.ff_container').children().css('background-image', 'none');
	$('form#edit_rumor').children('.ff_container').children('.ff_error_text').html('');

	$.ajax({
		'url' : '/ajax/edit_rumor',
		'cache' : false,
		'type' : 'POST',
		'data' : 'rumor_id='+$('#rumor_id').val()+
				'&sport='+global_sport+
				'&verdict='+$('#verdict').val()+
				'&caption='+$('#caption').val()+
				'&caption_uri='+$('#caption_uri').val()+
				'&question='+$('#question').val()+
				'&rumor='+$('#rumor').val()+
				'&team_1='+$('#team_1').val()+
				'&team_2='+$('#team_2').val()+
				'&author='+$('#author').val()+
				'&source='+$('#source').val()+
				'&source_date='+$('#source_date').val()+
				'&source_uri='+$('#source_uri').val(),
		'success' : function (responseData, textStatus) {
			// Error
			if(responseData != '') {
				var responseArray = responseData.split('||');
				var error_fields = responseArray[0].split('|');
				var error_messages = responseArray[1].split('|');
				
				var i;
				for(i = 0; i < error_fields.length; i++) {
					$('#'+error_fields[i]).parent().css({
						'background-image' : 'URL(/img/form_validation_error.gif)',
						'background-position' : '95% 50%',
						'background-repeat' : 'no-repeat'
					});
					$('#ff_'+error_fields[i]+'_container').html(error_messages[i]);
				}

				$('#submit_edit_rumor').show();
				$('#submit_edit_rumor_wait').hide();
				$('input').attr('disabled', '');	
			}
			// No error
			else {
				window.location.reload();
			}
		},
		'error' : function (XMLHttpRequest, textStatus, errorThrown) {
		  	// TODO - Add AJAX error handling
		}
	});
}

function loadEditRumor()
{
	var id = arguments[0];

	$('input#rumor_id').val(id);
	$('input#caption').val(global_rumor_data[id]['caption']);
	$('input#caption_uri').val(global_rumor_data[id]['caption_uri']);
	$('input#author').val(global_rumor_data[id]['author']);
	$('input#source').val(global_rumor_data[id]['source']);
	$('input#source_uri').val(global_rumor_data[id]['source_uri']);
	$('input#source_date').val(global_rumor_data[id]['source_date']);
	$('input#question').val(global_rumor_data[id]['question']);
	$('select#verdict').val(global_rumor_data[id]['verdict']);
	$('textarea#rumor').val(global_rumor_data[id]['rumor']);

	rumorTeams = global_rumor_data[id]['team_string'].split(',');
	
	if(rumorTeams.length == 1)
		$('select#team_1').val(rumorTeams[0]);
	else
	{
		$('select#team_2').val(rumorTeams[1]);
	}
}

function toggleComments(height)
{
	if(global_comments_open == 0)
	{
		$('#comment_toggle').attr('src', '/img/hide_comments.png');
		$('.comment_container').css('height', (height+40)+'px');
		$('.comments').css('height', height+'px');
		$('.text_content').css('height', '0px');
		$('.add_comment').show();
		
		global_comments_open = 1;
	}
	else
	{
		$('#comment_toggle').attr('src', '/img/show_comments.png');
		$('.comment_container').css('height', '20px');
		$('.text_content').css('height', height+'px');
		$('.add_comment').hide();
		
		global_comments_open = 0;
	}
}

function addComment()
{
	var rumor_id = arguments[0] || '0';
	
	if(global_adding_comment == 0)
	{
		$.ajax({
			'url' : '/ajax/get_user',
			'cache' : false,
			'type' : 'GET',
			'success' : function (responseData, textStatus) {
				if(responseData != '')
				{
					// No errors
					if(responseData != '0')
					{
						global_adding_comment = 1;
						
						$('.comments').append(
							'<div id="add_comment_container" style="position: relative; font-size: 9pt; color: #000; margin-top: 10px;">'+
								'<form name="add_comment">'+
								'<textarea id="comment" name="comment" style="height: 120px; width: 439px;"></textarea><br />'+
								'<a id="submit_comment" class="js_link" onclick="submitComment('+rumor_id+'); return false;"><img style="float: right; margin: 5px 20px 0px 0px;" src="/img/submit_button.png" /></a></form>'+
								'<div id="submit_comment_wait" style="display: none; position: absolute; top: 130px; right: 20px;"><img src="/img/loading_small.gif" /></div>'+
							'</div>'
						);

						$('.comments').animate({scrollTop: $('.comments').height()}, 500, 'swing');
					}
					else
						alert('You must login before adding a comment.');
				}
				else
				{
					// Error occured, alert it
					alert('Database access error, please refresh the page and try again.');
				}
			}
		});
	}
}

function submitComment()
{
	var rumor_id = arguments[0] || '0';

	$('#submit_comment').hide();
	$('#submit_comment_wait').show();
	$('textarea').attr('disabled', 'disabled');
	
	$.ajax({
		'url' : '/ajax/add_comment',
		'cache' : false,
		'type' : 'POST',
		'data' : 'rumor_id='+rumor_id+'&comment='+$('#comment').val(),
		'success' : function (responseData, textStatus) {
			if(responseData != '')
			{
				// No errors
				var responseArray = responseData.split('|');
				
				var comment_username = responseArray[0];
				var comment_created = responseArray[1];
				var comment = responseArray[2];
				
				$('.comments').append(
					'<div class="new_comment" style="display: none;"><div style="position: relative; font-size: 9pt; color: #000;"><span style="font-weight: bold;">'+comment_username+'</span> on <span style="font-style: italic;">'+comment_created+'</span><div style="padding: 5px;">'+comment+'</div></div>'+
					'<div style="width: 300px; height: 1px; padding: 0px 30px; margin: 10px auto 10px auto; background-color: #000;"></div></div>'
				);
				
				$('.add_first_comment').fadeOut('slow', function(){ $('.add_first_comment').remove(); });
				$('#add_comment_container').fadeOut('slow', function(){ $('#add_comment_container').remove(); });
				$('.new_comment').fadeIn('slow', function(){ $('.new_comment').removeClass('new_comment'); })
				$('.comments').scrollTop($('.comments').height());
				
				global_adding_comment = 0;
			}
			else
			{
				// Error occured, alert it
				alert('Database access error, please refresh the page and try again.');
			}
		}
	});
}

function showMyProfile()
{
	var sub_action = arguments[0] || '';

	if(global_foreground_open == 1 && sub_action != '')
	{
		if(sub_action == 'edit_profile')
			$('#verdicts_container').fadeOut('normal', function() { $('#edit_profile_container').fadeIn('normal'); });
		else
			$('#edit_profile_container').fadeOut('normal', function() { $('#verdicts_container').fadeIn('normal'); });
	}
	else
	{
		addOverlay();
		showWaiting('GRABBING YOUR FILE...', 'white');
		
		$.ajax({
			'url' : '/ajax/get_my_profile',
			'cache' : false,
			'type' : 'POST',		
			'success' : function (responseData, textStatus) {
				// Success
				if(responseData != '') {
					hideWaiting();
	
					var responseArray = responseData.split('|||');
					var editProfileArray = responseArray[0].split('|');
					var verdictListArray = responseArray[1].split('||');
	
					var full_height = $(window).height() - 70;
					var full_bg_height = full_height - 190;
					var full_content_height = full_height - 85;
					var full_left_pos = ($(document).width() / 2) - (840 / 2);
					
					var user = [];
					user['id'] = editProfileArray[0];
					user['username'] = editProfileArray[1];
					user['email'] = editProfileArray[2];
					
					var i;
					var verdictListItem;
					var verdictList = '';
					for(i=0; i < verdictListArray.length; i++)
					{
						verdictListItem = [];
						verdictListItem = verdictListArray[i].split('|');
	
						if((i % 2) != 0)
							bgColor = 'transparent';
						else
							bgColor = '#E9E9E9';
						
						if(verdictListItem[3] < 7)
							verdictListItem[3] = 'yes';
						else if(verdictListItem[3] > 7)
							verdictListItem[3] = 'no';
						else
							verdictListItem[3] = 'tie';
						
						verdictList += '<tr style="background-color: '+bgColor+';">'+
								'<td style="font-size: 9pt; font-weight: bold; color: #000000; padding: 4px;"><a style="color: black;" href="#'+verdictListItem[0]+'" onclick="$.historyLoad("'+verdictListItem[0]+'");">'+verdictListItem[1]+'</a></td>'+
								'<td style="padding: 4px; text-align: center; vertical-align: middle;"><img src="/img/'+verdictListItem[2]+'_small.png" /></td>'+
								'<td style="padding: 4px; text-align: center; vertical-align: middle; padding-left: 20px;"><img src="/img/'+verdictListItem[3]+'_small.png" /></td>'+
							'</tr>';
					}	
					
					var edit_profile_display = ' display: none;';
					var verdicts_display = ' display: block;';
					
					if(sub_action == 'edit_profile')
					{
						edit_profile_display = ' display: block;';
						verdicts_display = ' display: none;';
					}
						
					$('body').append(
							 '<div id="full_my_profile" class="full_container" style="display: none; position: absolute; top: 0px; left: '+full_left_pos+'px; height: '+full_height+'px; width: 816px; z-index: 1001; padding: 0px; overflow: hidden;">'+
								'<div class="full_content" style="position: absolute; left: 15px; top: 60px; height: '+full_content_height+'px; width: 465px; padding: 0px; z-index: 1003; overflow: hidden;">'+
									'<div id="verdicts_container" style="'+verdicts_display+' position: absolute; top: 0px; left: 0px;">'+
										'<div style="padding-bottom: 5px;"><h1>My Verdicts</h1></div>'+
										'<div style="width: 300px; height: 1px; padding: 0px 30px; margin: 20px auto 20px auto; background-color: #000;"></div>'+
										'<table cellspacing="0" cellpadding="0">'+
											'<tr>'+
												'<td style="width: 260px; font-weight: bold; font-size: 11pt; color: #000000; padding-bottom: 5px;">Rumor</td>'+
												'<td style="font-weight: bold; font-size: 11pt; color: #000000; padding-bottom: 5px;">Your Verdict</td>'+
												'<td style="font-weight: bold; font-size: 11pt; color: #000000; padding-left: 20px; padding-bottom: 5px;">Majority</td>'+
											'</tr>'+
											''+verdictList+''+
										'</table>'+
									'</div>'+
									'<div id="edit_profile_container" style="'+edit_profile_display+' position: absolute; top: 0px; left: 0px;">'+
										'<div style="padding-bottom: 5px;"><h1>Edit My Profile</h1></div>'+
										'<div style="width: 300px; height: 1px; padding: 0px 30px; margin: 20px auto 20px auto; background-color: #000;"></div>'+
										'<div style="font-size: 10pt;">'+
											'<form id="edit_profile" name="edit_profile">'+
											'<fieldset class="ff_container">'+
												'<legend>You can\'t change who you are</legend>'+
												'<div><label for="username">Username: </label>&nbsp;<span style="font-weight: bold;">'+user['username']+'</span></div>'+
												'<br />'+
												'<div><label for="email">Email: </label><input id="email" name="email" type="text" class="ff_input_blur" style="margin-left: 31px;" title="Either your email address or your username can be used when logging in. A valid email address is required to participate on this site." onFocus="focusFormField(this);" onBlur="blurFormField(this);" value="'+user['email']+'" /></div>'+
												'<br />'+
												'<div class="ff_error_text" id="ff_email_container"></div>'+
												'<div class="ff_help_container"></div>'+
											'</fieldset>'+
											'<br />'+
											'<fieldset class="ff_container">'+
												'<legend>You can change how you prove it</legend>'+
												'<div><label for="password">New Password: </label><input id="password" name="password" type="password" class="ff_input_blur" style="margin-left: 54px;" title="Only fill this in if you intend to change your current password to what you enter here." onFocus="focusFormField(this);" onBlur="blurFormField(this);" /></div>'+
												'<br />'+
												'<div><label for="confirm_password">Confirm New Password: </label><input id="confirm_password" name="confirm_password" type="password" class="ff_input_blur" title="You know the drill." onFocus="focusFormField(this);" onBlur="blurFormField(this);" /></div>'+
												'<br />'+
												'<div class="ff_error_text" id="ff_password_container"></div>'+
												'<div class="ff_error_text" id="ff_confirm_password_container"></div>'+
												'<div class="ff_help_container"></div>'+
											'</fieldset>'+
											'<br />'+
											'<div style="position: relative; width: 420px; padding: 5px; color: #2e2e2e; font-size: 9pt;">'+
												'<a id="submit_edit_profile" class="js_link" onclick="submitEditProfile(); return false;"><img style="float: right;" src="/img/submit_button.png" /></a>'+
												'<div id="submit_edit_profile_wait" style="display: none; position: absolute; top: 12px; right: 0px;"><img src="/img/loading_small.gif" /></div>'+
											'</div>'+
											'</form>'+
										'</div>'+	
									'</div>'+	
								'</div>'+
								'<div class="full_content" style="position: absolute; right: 12px; top: 60px; height: '+full_content_height+'px; width: 310px; padding: 0px; z-index: 1003; overflow: hidden;">'+
									'<div style="position: relative; padding-bottom: 10px;">'+
										'<div style="text-align: center; padding-bottom: 10px;"><img src="/img/my_profile.png" /></div>'+
										'<div style="font-size: 11pt; font-weight: bold; color: #FFF; padding: 5px;"><a href="#my_verdicts" onclick="$.historyLoad(\'my-verdicts\'); return false;">View My Verdicts</a></div>'+
										'<div style="font-size: 11pt; font-weight: bold; color: #FFF; padding: 5px;"><a href="#edit-profile" onclick="$.historyLoad(\'edit-profile\'); return false;">Edit My Profile</a></div>'+
									'</div><br /><br />'+
									'<div style="text-align: center;">'+
										'<div style="font-size: 0.625em; color: #6A7073; text-align: center;">ADVERTISEMENT</div>'+
										'<div class="box_ad" style="width: 300px; height: 250px; border: 1px solid black; margin: 5px auto;"></div>'+
									'</div>'+
								'</div>'+
								'<div style="position: absolute; right: 0px; top: 10px; height: 60px; width: 60px; z-index: 1004;"><a class="close_foreground"><img src="/img/close.png" /></a></div>'+
								'<div style="position: absolute; left: 0px; top: 40px; height: 20px; width: 816px; background-image: URL(\'/img/article_top.png\'); z-index: 1002;"></div>'+
								'<div class="full_bg" style="position: absolute; left: 0px; top: 60px; height: '+full_bg_height+'px; width: 816px; background-image: URL(\'/img/article_bg.png\'); z-index: 1002;"></div>'+
								'<div style="position: absolute; left: 0px; bottom: 0px; height: 130px; width: 816px; background-image: URL(\'/img/article_bottom.png\'); z-index: 1002;"></div>'+
							'</div>'
						);
					
					$('#full_my_profile').show("slide", { direction: "down" }, 1000, function() {
						$('form#edit_profile input').keypress(function (k) { if (k.which == 13) submitEditProfile(); });
						
						var box_ad_position = $('.box_ad').offset();
						$('.adsense').css({'top' : (box_ad_position.top+1)+'px', 'left' : (box_ad_position.left+1)+'px', 'display' : 'block'});
					
						$('.close_foreground').attr('href', '/#');
						$('.close_foreground').click(function() {
							$.historyLoad('');
							return false;
						});
					});
				}
				// Error
				else {
					// TODO - Add AJAX error handling
				}
			},
			'error' : function (XMLHttpRequest, textStatus, errorThrown) {
			  	// TODO - Add AJAX error handling
			}
		});
	}
}

function submitEditProfile() {
	$('#submit_edit_profile').hide();
	$('#submit_edit_profile_wait').show();
	$('input').attr('disabled', 'disabled');

	$('form#edit_profile').children('.ff_container').children().css('background-image', 'none');
	$('form#edit_profile').children('.ff_container').children('.ff_error_text').html('');
	
	$.ajax({
		'url' : '/ajax/edit_profile',
		'cache' : false,
		'type' : 'POST',
		'data' : 'email='+$('#email').val()+
				'&password='+$('#password').val()+
				'&confirm_password='+$('#confirm_password').val(),
		'success' : function (responseData, textStatus) {
			// Error
			if(responseData != '') {
				var responseArray = responseData.split('||');
				var error_fields = responseArray[0].split('|');
				var error_messages = responseArray[1].split('|');
				
				var i;
				for(i = 0; i < error_fields.length; i++) {
					$('#'+error_fields[i]).parent().css({
						'background-image' : 'URL(/img/form_validation_error.gif)',
						'background-position' : '95% 50%',
						'background-repeat' : 'no-repeat'
					});
					$('#ff_'+error_fields[i]+'_container').html(error_messages[i]);
				}

				$('#submit_edit_profile').show();
				$('#submit_edit_profile_wait').hide();
				$('input').attr('disabled', '');	
			}
			// No error
			else {
				$('#submit_edit_profile').show();
				$('#submit_edit_profile_wait').hide();
				$('input').attr('disabled', '');
				$('form#edit_profile').children('.ff_container').children().css('background-image', 'none');
				$('form#edit_profile').children('.ff_container').children('.ff_error_text').html('');
				alert('Great success!');
			}
		},
		'error' : function (XMLHttpRequest, textStatus, errorThrown) {
		  	// TODO - Add AJAX error handling
		}
	});
}