$(document).ready(function() {
	if ( $(".right-stage-home .blog-links").length ) {
		$(".right-stage-home .blog-links td").click( function() {
			$(this).addClass("active").siblings().removeClass("active");
			divID = $(this).find("a").attr("href");
			$("#home-blog > div").hide();
			$(divID).fadeIn("slow");
		});
	}

	if ( $("#rss-feed-container .blog-list li").length > 5 ) {
		$("#rss-feed-container .pagination").show();

		$("#rss-feed-container").pajinate({
			items_per_page: 5,
			item_container_id: "ul.blog-list",
			nav_panel_id: ".pagination" 
		});
	}

	if ($("#trayless-listing").length) {$("#trayless-listing").listnav();}
    
	if ($("#good-cents-listing").length) {
		var labels = new Array();
		$("#good-cents-listing span.category").each( function(index) {
			if ($.inArray($(this).html(), labels) == -1) {
				labels.push($(this).html());
				$cloner = $("#good-cents-listing-nav a:last");
				$cloner.clone(true).insertAfter($cloner).html( $(this).html() ).removeAttr('class');
			}
		});
		$("#good-cents-listing-nav a:last").addClass("ln-last");

			$("#good-cents-listing-nav a").click( function() {
				if ($(this).hasClass("all")) {
					$("#good-cents-listing li").fadeIn("slow");
				} else {
					var label = new Array( $(this).html() );
					$("#good-cents-listing span.category").each( function(index) {
						if ($.inArray($(this).html(), label) == -1)
							$(this).parents("li").fadeOut("fast");
						else
							$(this).parents("li").fadeIn("slow");
					});
				}
				$("#good-cents-listing-nav a").removeClass("ln-selected");
				$(this).addClass("ln-selected");
				return false;
			});
	}

	if ($("#jobs-listing").length) {
		$("#jobs-listing li").click( function() {
			document.location = $(this).find("a").attr("href");
		});
	}
	if ($("#job-posting-form").length) {
		$("#job-posting-form #expiration-entry").datepicker({
			minDate: 0, 
			maxDate: "+3M +1D",
			dateFormat: "yy-mm-dd 11:59"
		});
	}
	if ($("#trayless-form").length) {
		$("#trayless-form #implementation-date-entry").datepicker({
			maxDate: 0,
			dateFormat: "yy-mm-dd 11:59"
		});
	}
	if ($("#dlm-nomination-form").length) {
		$("#dlm-nomination-form #retirement-date-entry").datepicker({
			maxDate: 0,
			dateFormat: "yy-mm-dd"
		});
	}
	

	if ($("#category-goals").length) {
		$("#category-goals li").hide();
		goalSelected = $("#operational-category-entry option").index($("#operational-category-entry option:selected"));
//		console.log("load goalSelected = "+goalSelected);
		if (goalSelected > 0) {
			$("#category-goals li:eq("+(goalSelected-1)+")").fadeIn("slow");
			if (goalSelected == 6) {
				//$("#sustainability-contest-form .sustainability-details").hide();
				$("#sustainability-contest-form .student-details").fadeIn("slow");
			} else {
				//$("#sustainability-contest-form .sustainability-details").fadeIn("slow");
				$("#sustainability-contest-form .student-details").hide();
			}
		} else {
			$("#sustainability-contest-form .sustainability-details, #sustainability-contest-form .student-details, #sustainability-contest-form .shared-details").hide();
		}

		$("#operational-category-entry").change(function () {
			goalSelected = $("#operational-category-entry option").index($("#operational-category-entry option:selected"));
//			console.log("goalSelected = "+goalSelected);
			$("#category-goals li").hide();
			$("#category-goals li:eq("+(goalSelected-1)+")").fadeIn("slow");

			if (goalSelected == 6) {
				$("#sustainability-contest-form .sustainability-details").hide();
				$("#sustainability-contest-form .sustainability-details input").attr("disabled","true");

				$("#sustainability-contest-form .student-details, #sustainability-contest-form .shared-details").fadeIn("slow");
				$("#sustainability-contest-form .student-details input, #sustainability-contest-form .student-details select, #sustainability-contest-form .shared-details input").fadeIn("slow");
			} else if (goalSelected != 0) {
				$("#sustainability-contest-form .sustainability-details, #sustainability-contest-form .shared-details").fadeIn("slow");
				$("#sustainability-contest-form .sustainability-details input, #sustainability-contest-form .shared-details input").removeAttr("disabled");
				$("#sustainability-contest-form .student-details").hide();
				$("#sustainability-contest-form .student-details input, #sustainability-contest-form .student-details select").attr("disabled","true");
			} else {
				$("#sustainability-contest-form .sustainability-details, #sustainability-contest-form .student-details, #sustainability-contest-form .shared-details").hide();
				$("#sustainability-contest-form .sustainability-details input, #sustainability-contest-form .student-details input, #sustainability-contest-form .student-details select, #sustainability-contest-form .shared-details input").attr("disabled","true");
			}
		});

		$("#sustainability-contest-form .dates input").datepicker({
			maxDate: 0,
			dateFormat: "yy-mm-dd 11:59"
		});
	}
});


$(document).ready(function() {
	if ($("#sustainability-listing-nav").length) {
		var labels = new Array();
		$("#jobs-listing .job-position a").each( function(index) {
			if ($.inArray($(this).html(), labels) == -1) {
				labels.push($(this).html());
				$cloner = $("#sustainability-listing-nav a:last");
				$cloner.clone(true).insertAfter($cloner).html( $(this).html() ).removeAttr('class');
			}
		});

		$("#sustainability-listing-nav a:last").addClass("ln-last");
		$("#sustainability-listing-nav a").click( function() {
			if ($(this).hasClass("all")) {
				$("#jobs-listing li").fadeIn("slow");
			} else {
					var label = new Array( $(this).html() );
					$("#jobs-listing .job-position a").each( function(index) {
						if ($.inArray($(this).html(), label) == -1)
							$(this).parents("li").fadeOut("fast");
						else
							$(this).parents("li").fadeIn("slow");
					});
				}
				$("#sustainability-listing-nav a").removeClass("ln-selected");
				$(this).addClass("ln-selected");
				return false;
		});
	}

	if ($("#conference-programs-nav").length) {
		var labels = new Array();
		$("#jobs-listing .job-position a").each( function(index) {
			if ($.inArray($(this).html(), labels) == -1) {
				labels.push($(this).html());
				$cloner = $("#conference-programs-nav a:last");
				$cloner.clone(true).insertAfter($cloner).html( $(this).html() ).removeAttr('class');
			}
		});

		$("#conference-programs-nav a:last").addClass("ln-last");
		$("#conference-programs-nav a").click( function() {
			if ($(this).hasClass("all")) {
				$("#jobs-listing li").fadeIn("slow");
			} else {
					var label = new Array( $(this).html() );
					$("#jobs-listing .job-position a").each( function(index) {
						if ($.inArray($(this).html(), label) == -1)
							$(this).parents("li").fadeOut("fast");
						else
							$(this).parents("li").fadeIn("slow");
					});
				}
				$("#conference-programs-nav a").removeClass("ln-selected");
				$(this).addClass("ln-selected");
				return false;
			});
	}
});







