jQuery.fx.off = false;

var expanding_elements = new Array();

function show_topics()
{
    var topic_type = $('#show_topics').val();
    if(topic_type == 'all')
    	document.location = ext_url + 'discussions/index/' + disc_cat;
    else if (topic_type == 'my')
        document.location = ext_url + 'discussions/index/' + disc_cat + '/my';
    else if (topic_type == 'friends')
        document.location = ext_url + 'discussions/index/' + disc_cat + '/friends';
}

function show_topics_home()
{
    var topic_type = $('#show_topics').val();
    if(topic_type == 'all')
    	document.location = ext_url + 'home/index/' + disc_cat;
    else if (topic_type == 'my')
        document.location = ext_url + 'home/index/' + disc_cat + '/my';
    else if (topic_type == 'friends')
        document.location = ext_url + 'home/index/' + disc_cat + '/friends';
}

function search_discussions()
{
	var discussion_search_category = $('#discussion_search_category').val();
	var topic_type = $('#show_topics').val();
	if(topic_type == null){ topic_type = 'all'; }
	var discussion_search_text = $('#discussion_search_text').val();
	document.location = ext_url + 'discussions/index/' + discussion_search_category + '/all/' + discussion_search_text;
}

function clear_field(field)
{
	document.getElementById(field).value = '';
}

function restore_field_val(field, val)
{
	if(document.getElementById(field).value == '')
	{
		document.getElementById(field).value = val;
	}
}

function toggle_replies(i, ext_url, e, isblue)
{
	var color = 'false';
	if(isblue) { color = '_blue'; }
	
	$('#reply_' + i).slideToggle('slow', toggle_arrow(i, ext_url, color));
	
	if($('#reply_' + i).css('height') == 'auto')
	{
		if(all_colapsed(e)) { show_expand_all(); }
	}
	else
	{
		if(all_expanded(e)) { show_colapse_all(); }
	}
	return null;
}

function toggle_arrow(i, ext_url, c)
{
	if(c == 'false') { c = ''; }
	if($('#reply_' + i).is(":hidden"))
	{
		$('#reply_img_' + i).attr('src', ext_url + 'img/arrow_open' + c + '.gif');
	}
	else
	{
		$('#reply_img_' + i).attr('src', ext_url + 'img/arrow_closed' + c + '.gif');
	}
	 
	return null;
}

function expand_all(e, ext_url)
{
	show_colapse_all();
	
	for(i=0;i<e.length;i++)
	{
		if($('#reply_' + e[i]).is(":hidden"))
		{
			$('#reply_' + e[i]).slideDown('slow', toggle_arrow(e[i], ext_url));
		}
	}
	return null;
}

function colapse_all(e, ext_url)
{
	show_expand_all();
	
	for(i=0;i<e.length;i++)
	{
		if(!$('#reply_' + e[i]).is(":hidden"))
		{
			$('#reply_' + e[i]).slideUp('slow', toggle_arrow(e[i], ext_url));
		}
	}
	return null;
}

function all_expanded(e)
{
	for(i=0;i<e.length;i++)
	{
		if($('#reply_' + e[i]).css('display') == 'none') return false;
	}
	return true;
}

function all_colapsed(e)
{
	for(i=0;i<e.length;i++)
	{
		if($('#reply_' + e[i]).css('height') == 'auto') return false;
	}
	return true;
}

function show_expand_all()
{
	$('#expando').css('display', 'block');
	$('#colapso').css('display', 'none');	
}

function show_colapse_all()
{
	$('#expando').css('display', 'none');
	$('#colapso').css('display', 'block');	
}

function display_expando(e)
{
	if(e.length > 0)
	{
		$('#expando').css('display', 'block');
	}
}