jQuery(document).ready(function($){

//TS added

$("#show-ypo-form").click(function () {
     $("#ypo-div").show();
	 $('#show-ypo-form').hide();
	 $('#hide-ypo-form').show();
    });

$("#hide-ypo-form").click(function () {
     $("#ypo-div").hide();
	 $('#hide-ypo-form').hide();
	 $('#show-ypo-form').show();
    });

var opts = {
initLetter: 'a',
includeAll: true,
flagDisabled: true,
noMatchText: '<div class="contenttable"><div> Sorry, nothing matched your filter. Please try another letter.</div></div><div class="mb12"></div>',
lastClass: 'letters-last',
selectedClass: 'ln-selected',
disabledClass: 'ln-disabled',
showCounts: true
};


$('#ypoDir').listnav(opts);

// JD added

$('.greeting').randomContent({xmlPath: "/assets/welcome.xml", nodeName: "greeting"});



 $(".favorite").click(function(){
	str_id = this.id;
	array_id = str_id.split("-");

	$("#favorite-"+array_id[1]+"-status").text = "Loading...";
	$("#favorite-"+array_id[1]+"-status").load("/utility/favorite/"+array_id[1]+"/"+array_id[2]);

	$(this).css({ display:"none" });
	if (array_id[2] == "delete") {
		$("#favorite-"+array_id[1]).css({ display:"block" });
	} else {
		$("#favorite-"+array_id[1]+"-delete").css({ display:"block" });
	}
 });
   $('#ratingform').ajaxForm(function() { });

// set the initial state of the buttons and marquee
$('.content-marquee').hide();
$('#marquee-1').addClass('active');
$('#marquee-1-content').show();	

$('.button-marquee').click(function(){

	// get the id name of the click control to help select the corresponding content
	var name = $(this).attr('id');

	// check if corresponding content is hidden first before switching content
	if ($('#' + name +'-content').is(':hidden')) {

		// switch the button state
		$('.button-marquee').removeClass('active');
		$(this).addClass('active');

		// crossfade content
		$('.content-marquee').hide();
		$('#' + name + '-content').show();
	}
});


$(".navitem").hover(
		function(){
			var name = $(this).attr('id');
			$('#' + name + '-navbutton').addClass('rollover');
			$('#' + name + '-dropdown').show();
		},
		function(){
			var name = $(this).attr('id');
			$('#' + name + '-navbutton').removeClass('rollover');
			$('#' + name + '-dropdown').fadeOut("fast");
		}
)


});

function fnStarSelect(form, int_value) {
	form.rating.value = int_value;
	for(i=1; i<=5; i++) {
		document.getElementById("userstar-" + i).disabled = 1;
		document.getElementById("userstar-" + i).onclick=null;
		document.getElementById("userstar-" + i).onmouseover=null;
		document.getElementById("userstar-" + i).onmouseout=null;
		document.getElementById("userstar-" + i).style.cursor = "default";
	}
	return false;
}

function fnStarMouseOver(int_value) {
	for(i=1; i<=int_value; i++) { document.getElementById("userstar-" + i).src = "/themes/rating_themes/ngc/images/star-100.gif"; }
}

function fnStarMouseOut(int_value) {
	for(i=1; i<=int_value; i++) { document.getElementById("userstar-" + i).src = "/themes/rating_themes/ngc/images/star-0.gif"; }
}

int_active_ranked_content = 1;
function fnRankedTabChange(int_new_ranked_content) {
	document.getElementById("ranked-tab-" + int_active_ranked_content).style.backgroundPosition = "top left";
	document.getElementById("ranked-tab-" + int_new_ranked_content).style.height = "40px";
	document.getElementById("ranked-content-" + int_active_ranked_content).style.display = "none";

	document.getElementById("ranked-tab-" + int_new_ranked_content).style.backgroundPosition = "bottom left";
	document.getElementById("ranked-tab-" + int_new_ranked_content).style.height = "41px";
	document.getElementById("ranked-content-" + int_new_ranked_content).style.display = "block";

	int_active_ranked_content = int_new_ranked_content;
}

function fnCalendarChange(int_value) {
	if (int_value) {
		document.getElementById("events-list").style.display = "block";
		document.getElementById("category-box").style.display = "block";
		document.getElementById("events-calendar").style.display = "none";
	} else {
		document.getElementById("events-list").style.display = "none";
		document.getElementById("category-box").style.display = "none";
		document.getElementById("events-calendar").style.display = "block";
	}
}

function fnEventVisibiliyToggle(str_value) {
	var allHTMLTags=document.getElementsByTagName("*");
	for (i=0; i<allHTMLTags.length; i++) {
		if (allHTMLTags[i].className==("cat-" + str_value)) {
			if (allHTMLTags[i].style.display=='none') {
				allHTMLTags[i].style.display='block';
			} else {
				allHTMLTags[i].style.display='none';
			}
		}
	}
}


int_active_sidebar_search = 0;
function fnSidebarSearchChange() {
	if (int_active_sidebar_search) {
		document.getElementById("sidesearch-simple").style.display = "block";
		document.getElementById("sidesearch-advanced").style.display = "none";
		int_active_sidebar_search = 0;
	} else {
		document.getElementById("sidesearch-simple").style.display = "none";
		document.getElementById("sidesearch-advanced").style.display = "block";
		int_active_sidebar_search = 1;
	}
}

/*window.onload = prepareSearchFields;

function prepareSearchFields() {
	//check that the browser is capable of executing the script
	if(!document.getElementById) return false; 
	//find our input field and assign it to a variable for easy referencing
	var searchField = document.getElementById("search-input");
	//find the default value of the search field
	var defaultValue = searchField.defaultValue;
	
	searchField.onfocus = function() {
		if(searchField.value == defaultValue) {
			searchField.value = "";
		}
	}
	
	searchField.onblur = function() {
		if(searchField.value == "") {
			searchField.value = defaultValue;
		}
	}
}
*/

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
}
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
}

function navHover(which)
{					
	if (document.getElementById(which.id))
	{
		cur = document.getElementById(which.id).className;
		
		if (cur == 'buttonLarge')
		{
			document.getElementById(which.id).className = 'buttonLargeHover'
		}
		else if (cur == 'buttonSmall')
		{
			document.getElementById(which.id).className = 'buttonSmallHover'
		}
	}
}

function navReset(which)
{					
	if (document.getElementById(which.id))
	{
		cur = document.getElementById(which.id).className;
		
		if (cur == 'buttonLargeHover')
		{
			document.getElementById(which.id).className = 'buttonLarge'
		}
		else if (cur == 'buttonSmallHover')
		{
			document.getElementById(which.id).className = 'buttonSmall'
		}
	}
}


function navJump(where)
{
	window.location=where;
}


function show_element(which)
{	
	document.getElementById(which + 'on').style.display = "block";
	document.getElementById(which + 'off').style.display = "none";
	set_cookie(which, 'on');
}


function hide_element(which)
{
	document.getElementById(which + 'on').style.display = "none";
	document.getElementById(which + 'off').style.display = "block";
	set_cookie(which, 'off');
}

function set_cookie(which, state)
{
	document.cookie = "{cookie_name}" + which + "=" + state + "; path=" + "/" + ';';
}

function fetch_cookie(which)
{
	thecookie = "{cookie_name}" + which + '=';
	str_pos  = document.cookie.indexOf(thecookie);
	cc = false;
	
	if (str_pos != -1)
	{
		cstart = str_pos + thecookie.length;
		cend   = document.cookie.indexOf(";", cstart);
		
		if (cend == -1)
			cend = document.cookie.length;
		
		cc = unescape(document.cookie.substring(cstart, cend));		
	}

	return cc;
}

function set_display()
{			
	var el = new Array();
	{include:javascript_forum_array}
	
	for (i = 0 ; i < el.length; i++ )
	{
		if (fetch_cookie(el[i]) != false)
		{
			if (fetch_cookie(el[i]) == 'on')
			{
				show_element(el[i]);
			}
			else
			{
				hide_element(el[i]);
			}
		}
	}
}


