
active_selector = "selector1";
active_panel = "panel1";

panel_timer = null;

panel_toggle_delay = 8000;

function activate_selector(selector_id) {
	current_active_div_id = active_selector + "_active";
	current_active_div = document.getElementById(current_active_div_id);
			
	current_active_div.style.display = "none";
	
	current_inactive_div_id = active_selector + "_inactive";
	current_inactive_div = document.getElementById(current_inactive_div_id);
	
	current_inactive_div.style.display = "block";

	active_div_id = selector_id + "_active";
	inactive_div_id = selector_id + "_inactive";
	
	active_div = document.getElementById(active_div_id);
	inactive_div = document.getElementById(inactive_div_id);

	inactive_div.style.display = "none";
	
	active_div.style.display = "block";
	
	active_selector = selector_id;
}


function activate_panel(panel_id) {
	current_active_div_id = "selector1_active_" + active_panel
	current_active_div = document.getElementById(current_active_div_id);
	
	current_active_div.style.display = "none";
	
	active_div_id = "selector1_active_" + panel_id;
	active_div = document.getElementById(active_div_id);
	
	active_div.style.display = "block";


	current_active_nav_id = active_panel + "_nav_active"
	current_active_nav = document.getElementById(current_active_nav_id);
	
	current_inactive_nav_id = active_panel + "_nav_inactive";
	current_inactive_nav = document.getElementById(current_inactive_nav_id);
	
	active_nav_id = panel_id + "_nav_active";
	active_nav = document.getElementById(active_nav_id);
	
	inactive_nav_id = panel_id + "_nav_inactive";
	inactive_nav = document.getElementById(inactive_nav_id);
	
	current_active_nav.style.display = "none";
	current_inactive_nav.style.display = "inline";
	
	active_nav.style.display = "inline";
	inactive_nav.style.display = "none";

	
	active_panel = panel_id;
	

}

function click_panel() {
	clearTimeout(panel_timer);
	
	next_panel();
	
	cmd = "toggle_panels(false)";
	panel_timer = setTimeout(cmd, panel_toggle_delay);
}

function click_panel_nav(panel_id) {
	clearTimeout(panel_timer);
	
	activate_panel(panel_id);
	
	cmd = "toggle_panels(false)";
	panel_timer = setTimeout(cmd, panel_toggle_delay);
}

function next_panel() {	
	//current_panel_num = active_panel.substr(5, 1);
	//current_panel_num = parseInt(current_panel_num);

	//console.log(current_panel_num);

	next_panel_num = find_next_panel(current_panel_num);

	//next_panel_num = (current_panel_num + 1);
	
	//if (next_panel_num > 4) {
	//	next_panel_num = 1;
	//}
	
	next_panel_id = "panel" + next_panel_num;
	
	activate_panel(next_panel_id);
	
	current_panel_num = next_panel_num;


}

function toggle_panels(start) {
	if (start === false) {
		next_panel();
	}
	
	cmd = "toggle_panels(false)";
	panel_timer = setTimeout(cmd, panel_toggle_delay);

}


function find_next_panel(current_num) {
	grab_next = false;

	for (i=0; i < panels.length; i++) {

		if (grab_next) {
			return_next = panels[i];
			
			grab_next = false;
		}

		if (panels[i]==current_num) {
			grab_next = true;
		
		}
	}
	
	if (grab_next) {
		return_next = panels[0];
	}
	
	//console.log(current_num + ":" + return_next);
	
	return return_next;
}



newsalerts_current_sheet = 1;

function newsalerts_tab_go(sheet) {
	current_sheet = "newsalerts_sheet" + newsalerts_current_sheet;
	current_tab = "newsalerts_tab_selector" + newsalerts_current_sheet;
	
	$("#" + current_sheet).hide();
	$("#" + current_tab).removeClass("newsalerts_tab_selector_active");
	$("#" + current_tab).addClass("newsalerts_tab_selector_inactive");
	
	new_sheet = "newsalerts_sheet" + sheet;
	new_tab = "newsalerts_tab_selector" + sheet;
	
	$("#" + new_sheet).show();
	$("#" + new_tab).removeClass("newsalerts_tab_selector_inactive");
	$("#" + new_tab).addClass("newsalerts_tab_selector_active");
	
	newsalerts_current_sheet = sheet;

}

grants_current_sheet = 1;

function grants_tab_go(sheet) {
	current_sheet = "grants_sheet" + grants_current_sheet;
	current_tab = "grants_tab_selector" + grants_current_sheet;
	
	$("#" + current_sheet).hide();
	$("#" + current_tab).removeClass("grants_tab_selector_active");
	$("#" + current_tab).addClass("grants_tab_selector_inactive");
	
	new_sheet = "grants_sheet" + sheet;
	new_tab = "grants_tab_selector" + sheet;
	
	$("#" + new_sheet).show();
	$("#" + new_tab).removeClass("grants_tab_selector_inactive");
	$("#" + new_tab).addClass("grants_tab_selector_active");
	
	grants_current_sheet = sheet;

}

function widget_show_month(show_month, show_year) {
	$("#widget_grid").fadeOut("normal");

	$("#style1_calendar_div").load("listener_calendar.php", { 'show_month': show_month, 'show_year': show_year });

}

$(document).ready(function() { 
	span_width = $("#selector1_active_panel_nav_text_span").width();
	
	//console.log(span_width);
	span_width = span_width + 5;
	
	$("#selector1_active_panel_nav").width(span_width + "px");
	$("#selector1_active_panel_nav").css("left", (522 - span_width) +"px");


	// calendar
	$("#style1_calendar_div").load("listener_calendar.php");

	$(".style1_calendar_dropoff").mouseover(function () {
		$(".widget_day_events_overlay").hide();
	
	});
	
	$("#signup_email").focus(function() {
		if ($(this).val()=="eMail Address") {
			$(this).val("");
		}
	});
	
	$("#signup_email").blur(function() {
		field_value = $(this).val()
		field_value = $.trim(field_value);
		
		if (field_value.length==0) {
			$(this).val("eMail Address");
		}
	
	});
	
	$("#signup_name").focus(function() {
		if ($(this).val()=="Name") {
			$(this).val("");
		}
	
	});
	
	$("#signup_name").blur(function() {
		field_value = $(this).val()
		field_value = $.trim(field_value);
		
		if (field_value.length==0) {
			$(this).val("Name");
		}
	
	});
	
	$("#signup_org").focus(function() {
		if ($(this).val()=="Organization") {
			$(this).val("");
		}
	
	});
	
	$("#signup_org").blur(function() {
		field_value = $(this).val()
		field_value = $.trim(field_value);
		
		if (field_value.length==0) {
			$(this).val("Organization");
		}
	
	});

	$(".right_heading").click(function() {
		if ($(this).parent(".right_item").hasClass("right_active")) {
		
		} else {
		
			
			$(this).parent(".right_item").children(".right_body").slideDown();

			$(".right_active").children(".right_body").slideUp();
			
			
			$(".right_active").removeClass("right_active");
			
			$(this).parent(".right_item").addClass("right_active");
			
		
		}
	
	});

});
