var $j = jQuery.noConflict();

$j(document).ready (function(){
	fixMainNav();
	fixSubNav();
	fixFooterNav();
	fixSiteMapNav();
	fixTestimonials();
	hoverNav();
	$j("#contact-form").validate({
      rules: {
      emailconfirm: {
        equalTo: "#emailid"
      }
  }
});
	showHideAnts()
	
});
// Add last class to final main nav item

function fixMainNav(){
	$j("div#main-nav ul li:first-child").addClass("first");
	$j("div#main-nav ul li:last-child").addClass("last");
}
function fixFooterNav(){
	$j("div#footer-nav li:first-child").addClass("first");
	$j("div#footer-nav li:last-child").addClass("last");
}
function fixSubNav(){
	$j("ul#sub-nav li:first-child").addClass("first");
	$j("ul#sub-nav li:last-child").addClass("last");
}
function fixSiteMapNav(){
	$j("div#site-map-items ul li:first-child").addClass("first");
	$j("div#site-map-items ul li:last-child").addClass("last");
}
function fixTestimonials(){
	$j("div#testimonial-items div.testimonial-item:first-child").addClass("first");
	$j("div#testimonial-items div.testimonial-item:last-child").addClass("last");
}
function hoverNav(){
    $j("div#header div#main-nav-content").show();
    $j("div.hover-content").hide();
	var currentpage = $j("li.current_page_parent").attr("class");
	if(currentpage == undefined){
		var currentpage = $j("li.current_page_item").attr("class");
	}
	var regexpressiona = /[0-9]{1,2}/; // regular expression that finds the page item.
	var currentnavitema = (regexpressiona.exec(currentpage)); // capture the page item.
	var ptoshowa = "div#page-item-" + currentnavitema;
	
	$j(ptoshowa).show(); // Show appropriate intro content
	$j("body#News div#page-item-8").show();
	$j("body#Articles div#page-item-8").show();
	
    $j("div#main-nav li.page_item").hover(
      function () {
	  	var currentnavclass = $j(this).attr("class"); // capture the nav elements class.
		var regexpression = /[0-9]{1,2}/; // regular expression that finds the page item.
		var currentnavitem = (regexpression.exec(currentnavclass)); // capture the page item.
		var ptoshow = "div#page-item-" + currentnavitem; // creates the id of the content to show based on the last number of the nav element's class.
		$j("div.hover-content").hide(); // Hide all content
		$j(ptoshow).show(); // Show appropriate intro content
      },
      function () {
		$j("div.hover-content").hide();
	  	$j(ptoshowa).show();
		$j("body#News div#page-item-8").show();
		$j("body#Articles div#page-item-8").show();
	  }
	);
}
function showHideAnts(){
     $j("div#ants-off p").toggle(
	  function () {
        $j("div#wrapper-flash").hide();
		$j(this).text("Ants On");
      },
      function () {
        $j("div#wrapper-flash").show();
		$j(this).text("Ants Off");
      }
    );
}
