$(document).ready(function(){
						   	
	$j(".more_info_link").click(function(){
		$j("#div_more_info_1").slideToggle("medium");
		$j("#div_more_info_2").slideToggle("medium");
	});
	
	$j("#ActivitiesFilterForm").submit(function(){
		//alert($j("#orderCategory").val() + " | " + $j("#orderField").val() + " | " + $j("#orderDir").val()));
	});
});

function goToURL(url)
{
	window.location = url;	
}

function init()
{
	var wH = $j(window).height();
	var cH = $j("#content").height()+380;

	if (cH < wH)
	{
		$j("#footer").css({"position": "absolute" ,"bottom": 0});
	}
}

function monitorClick(e)
{    
	var evt = (e) ? e : event;	
	var theElem = (evt.srcElement) ? evt.srcElement : evt.target;

	if (theElem.id == "userMenuArrow2" || theElem.id == "userMenuArrow")
	{
		menuToggle();
	}
	
	else
	{
		$j('#userMenuArrow').css('display', '');
		$j('#userMenuArrow2').css('display', 'none');
		$j('#userMenu').css('display', 'none');
	}
}

function menuToggle()
{
	$j('#userMenu').toggle();
	$j('._userMenuArrow').toggle();
}

function cleanup_errors()
{
	if ($j('#flashMessage.error_bar').length > 0)
	{
		$j('#flashMessage.error_bar').fadeOut(800);
	}
	
	if ($j('#authMessage.message').length > 0)
	{
		$j('#authMessage.message').fadeOut(800);
	}
}

function flashMessage()
{
	/*if ($j('#flashMessage').length > 0)
	{		
		$j("#flashMessage").animate({ color: "#ffffff", backgroundColor: "#812F28" }, 1400)
         .animate({ color: "#9F261D", backgroundColor: "#000000" }, 1200);
	}*/
}

function set_comment_options(viewing)
{	
	$j("a#comment_options_" + prev).removeClass('cur');
	$j("a#comment_options_" + viewing).addClass('cur');
	prev = viewing;
}

function comment_options_enabled(bool)
{
	enabled = bool;	
}

function deleteComment(div_id, feedback)
{
	$j("#" + div_id + "_feedback").append("<div id=\"__f\" style=\"display: none;\"><b>" + feedback + "</b></div>");
	$j("#__f").fadeIn("fast");
	setTimeout(function(){doDeleteComment(div_id, feedback)}, 800);
}

function doDeleteComment(div_id, feedback)
{
	if (feedback == "The comment was deleted successfully.")
	{
		$j("#" + div_id).slideUp("medium").fadeOut("medium", function(){ $j("#" + div_id).remove(); });
	}
	
	else
	{
		if ($j("#__f").length > 0)
		{
			$j("#__f").remove();
		}
	}
}

function insertNewComment(type, id, username, slug, photo, comment)
{
	if (type == 1)
	{		
		$j("#the_comments").prepend('<div id="c' + id + '" class="comment comment_pad" style="display: none;"><div class="left"><a href="/people/' + slug + '"><img alt="" class="user_photo" src="/images/photos/80_' + photo + '"/></a></div><div class="right comment_details"><div id="c' + id + '_feedback"></div><h1><a href="/people/' + slug + '">' + username + '</a> <span class="small grey">Posted just now</span></h1><br/> ' + comment + ' </div><div class="clear"/></div>');
	}
	
	$j("#c" + id).slideDown("medium").fadeIn("medium");
}

function insertNewComment2(type, id, username, slug, photo, comment)
{
	if (type == 1)
	{		
		$j("#comments_list").prepend('<li class="pad" id="c' + id + '"><div class="user_update"> <b>' + comment + '</b> <span class="grey small">just now</span> </div> </li>');
	}
	
	else if (type == 2)
	{		
		$j("#comments_list").prepend('<li class="pad" id="c' + id + '"><div class="left"> <a href="/people/' + slug + '"><img alt="" class="user_photo" src="/images/photos/80_' + photo + '"/> </a> </div> <div class="right comment_details"> <div id="c' + id + '_feedback"/> <h1> <a href="/people/' + slug + '">' + username + '</a> <span class="small grey"> Posted just now</span> </h1> <p style="margin-top: -18px;">&nbsp;</p> ' + comment + '</div> <div class="clear"/></li>');
	}
	
	$j("#c" + id).slideDown("medium").fadeIn("medium");
}

function ajaxError(content,loading,error)
{
	Element.fade(loading, {duration: 0.4});
	Element.appear(error, {duration: 0.46});
	$(content).remove();
}

var loading = false;
var timer = 0;
var div = '';

function setLoadingDiv(time,_div)
{
	loading = true;
	timer = time;
	div = (_div != '') ? _div : div;
	
	if (loading == true && time == 10)
	{
		$j("#"+div).append("<br /><br /><i class=\"grey\">Still loading...</i>");
	}
	
	else if (loading == true && time == 20)
	{
		$j("#"+div).append("<br /><br /><i class=\"grey\"><b>Still</b> here...</i>");
		clearTimeout(doTimer);
	}
	
	else
	{
		if (timer == 0)
		{
			doTimer = setTimeout("setLoadingDiv(10,'')",10000);
		}
		
		else if (timer == 4)
		{
			doTimer = setTimeout("setLoadingDiv(20,'')",20000);
		}
	}
}

function showIndicator(div)
{
	$j('#' + div).html('<img src="images/loading.gif" alt="Loading" border="0" />');	
}

function listingsSaveAddLoader(div)
{
	$j("#" + div).html('<div style="margin-top: -5px;"><img src="/images/loading_small.gif" alt="" border="0" /></div>');
}

function resetLoadingDiv(div)
{
	$j("#" + div).html('<img src="/images/loading.gif" alt="" />');
	clearTimeout(doTimer);
}

function clearField(field)
{
	$j("#" + field).val('');
}

document.onclick = monitorClick;
window.onload = init;