$(document).ready(function(){	   
	
	// Disable Submit so doesn't appear in search query string
	$("#search input").keypress(function(e) {
		if (e.which == 13) {
			$("#search input[type='submit']").attr("disabled","disabled");
			$("#search").submit();
		}
	});
	$("#search input[type='submit']").click(function() {
		$(this).attr("disabled","disabled");
		$("#search").submit();
	});

	$('#feedback')
		.css("cursor","pointer")
		.click(function() {
			$('#feedback-content').slideDown();
		});
						   
	$(".feedback-content-close").click(function(){
		$("#feedback-content").slideUp();
	});

	$(".menu").each(function (i) {
		$(this).children("ul").children("li").children("ul").hide();
		$(this).children("ul").children("li.subnav-title").prepend("<a class=\"expand\">[+]</a> ");
		$(this).children("ul").children("li.on").children("a.expand").replaceWith("<a class=\"expand\">[-]</a> ");
		$(this).children("ul").children("li.subnav-title").children("a.expand")
			.click(function(){
				if ($(this).text() == "[+]") {
					$(this).parent().children("ul").slideDown();
					$(this).text("[-]");
				} else {
					$(this).parent().children("ul").slideUp();
					$(this).text("[+]");
				}
			})
		$(this).children("ul").children("li.on").children("ul").show();
		});
	
	$("div.more-news").each(function (i) {
		$(this).hide();
		$("h3.archive-heading").append(" <a class=\"more\">[+]</a>");
		$("a.more")
			.click(function(){
				if ($(this).text() == "[+]") {
					$("div.more-news").slideDown();
					$(this).text("[-]");
				} else {
					$("div.more-news").slideUp();
					$(this).text("[+]");
				}
			})
		$(this).children("ul").children("li.on").children("ul").show();
		});

	// Home Page Image Fading
	$('#random-box').cycle({
		fx:    'fade',
		speed:    2000,
		timeout:  1200, 
		pause:  1
	});
	
	// Home Page and Footer Clickable Image Blocks
	$('div.random-box-hover,#latest-news,.twoblock')
		.css("cursor","pointer")
		.click(function() {
			location.href = $(this).find("a").attr("href");
		});


	 
//scrolls down to ids in a page
function filterPath(string) {

    return string

      .replace(/^\//,'') 

      .replace(/(index|default).[a-zA-Z]{3,4}$/,'') 

      .replace(/\/$/,'');

  }

  $('a[href*=#]').each(function() {
    if ( filterPath(location.pathname) == filterPath(this.pathname)
    && location.hostname == this.hostname
    && this.hash.replace(/#/,'') ) {
      var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
      var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
       if ($target) {
         var targetOffset = $target.offset().top;
         $(this).click(function() {
           $('html, body').animate({scrollTop: targetOffset}, 400);
           return false;
         });
      }
    }
  });
  

	$("#t-" + jQuery.url.attr("anchor")).each(function(){
		$(this).addClass('on');
		$(this).parent("ul").parent("li").addClass('on');
		$(this).parent("ul").show();
	});
	
	$("#sub-" + jQuery.url.attr("anchor")).each(function(){ // for sub-navigation go 1 level down
		$(this).addClass('on');
		$(this).parent("ul").parent("li").parent("ul").parent("li").addClass('on');
		$(this).parent("ul").parent("li").parent("ul").show();
	});
	

});

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;




