function initMenu(){
	var nodes = document.getElementById("menu").getElementsByTagName("li");
	for (var i=0; i<nodes.length; i++)
	{
		nodes[i].onmouseover = function()
		{
			this.className += " hover";
		}
		nodes[i].onmouseout = function()
		{
			this.className = this.className.replace(" hover", "");
		}
	}
}
if (document.all && !window.opera) attachEvent("onload", initMenu);
function initTabs()
{
	var sets = document.getElementsByTagName("ul");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("tabset") != -1)
		{
			var tabs = [];
			var links = sets[i].getElementsByTagName("a");
			for (var j = 0; j < links.length; j++)
			{
				if (links[j].className.indexOf("tab") != -1)
				{
					tabs.push(links[j]);
					links[j].tabs = tabs;
					var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));

					//reset all tabs on start
					if (c) if (links[j].className.indexOf("active") != -1) c.style.display = "block";
					else c.style.display = "none";

					links[j].onclick = function ()
					{
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c)
						{
							//reset all tabs before change
							for (var i = 0; i < this.tabs.length; i++)
							{
								document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.display = "none";
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.display = "block";
							return false;
						}
					}
				}
			}
		}
	}
}

jQuery(document).ready(function($) {

if (window.addEventListener) window.addEventListener("load", initTabs, false);
else if (window.attachEvent) window.attachEvent("onload", initTabs);

/*This code snippet allows links to directly scroll to the comment box in IE if the URL ends with #respond*/
  		 var resp_url = location.href.match(/#respond$/);
  		 if(resp_url) {
  		 	  		$('html,body').animate({scrollTop: $("#respond").offset().top},'fast');
  		 }

function highlightCurrentNav() {
    var reg_exp = new Array(/about-this-site/,
    "About This Site",
    /the-issues/,
    "The Issues",
    /the-candidates/,
    "The Candidates",
    /get-informed/,
    "Get Informed",
    /get-involved/,
    "Get Involved",
    /6-words/,
    "6 Words");

    var url = location.href;
    var reg_exp_len = reg_exp.length;

    for (var i = 0; i < reg_exp_len; i++) {
        if (url.search(reg_exp[i]) !== -1) {
			$("#menu li a[title*='" + reg_exp[i + 1] + "']").parent().addClass('current_page_top');
		}
    }

	/*This code snippet hides certain content from the search results e.g. prevents share a story and poll pages from being displayed by hiding the relevant div*/
	var search_url = /\?s\=/;
	if (url.search(search_url) !== -1) {
		$("div[class='post']>h2>a").each(function(){
			var postList = $(this).html();
			if(postList === "Suggest a poll question" || postList === "Poll Archive" || postList === "Share a story"){
				$(this).parent().parent().hide();
			}
		});
	}
}
window.onload = function() {highlightCurrentNav()};
(function(){
	/*This code snippet looks to see which radio buttons were selected during search, and alters the destination URL appropriately*/
	$('#searchform input[type=submit]').click(function() {
  		 var q2 = '?s=';
  		 var q3 = $("input[name='s']").val(); //Get query inside search box
  		 	
  		 	//Loop through all rdoContent (radio buttons) and see which one is checked
  		 	$("input[name='rdoContent']").each(function(){
			
			if ($(this).attr('checked')) {
				v = $(this).val();
				var q1 = ''; //tag info
				switch (v) {
					case 'all':
						break;
					case 'images':
						q1 = '/images/';
						break;
					case 'video':
						q1 = '/video/';
						break;
				}				
				window.location = location.host + q1 + q2 + q3;				
			}
		});
	});
})();

});
