// JavaScript Document
jQuery.noConflict();
jQuery(document).ready(function($){
						   
	//fills in the email address to prevent bots sniffing her out
	var emailName = "development";
	var emailDomainB = "herdrum.com";
	var emailDomainA = "christop";
	var fullEmailAddress = emailName + "@" + emailDomainA + emailDomainB;
	$("#developmentEmail").attr("href", "mailto:"+fullEmailAddress);
	
	//fills in contact phone number to prevent bots sniffer her out
	var phonePrefix = "794";
	var areaCode = "415";
	var phoneSuffixB = "93";
	var phoneSuffixA = "53";
	var phoneNumber = areaCode + "-" + phonePrefix + "-" + phoneSuffixA + phoneSuffixB;
	$("#developmentPhone").text(phoneNumber);
	$("#developmentPhone").attr({href:"tel:"+phoneNumber,target:"_self"});

	//overrides the 60px height we had to set to force the current page icon to be pre-dropped
   	$("div#domainNavigation li:not(.currentDomain)").css("height", '39px');

	//forcibly hides all sectionMenu divs
	$("div#sectionMenu").css("top", '40px');
	
	//auto-tag code blocks with appropriate code type graphic flag
	$("#mainContent pre").each(function() {
		var currentClass = $(this).attr("class");
		var targetDiv = $(this).parent().children().filter(".codetag");
		codetagImageSrc = "url('../images/codetag" + currentClass + ".gif')"
		targetDiv.css('background-image', codetagImageSrc); 
	});
	
	//reads the name of the sectionMenu link and targets a sectionMenu div with a matching class
	//also exclusionary retraction of non-matching divs
	$("div#subdomainMenu a").click(function(){
		var menuSelection = "."+$(this).html();	
		var subdomainMenuHeight = $("div#subdomainMenu").height();
		var subdomainMenuMargin = $("div#subdomainMenu").css("padding-top");
		subdomainMenuMargin = parseInt(subdomainMenuMargin.substring(0,subdomainMenuMargin.indexOf("px")));
		subdomainMenuHeight = subdomainMenuHeight + subdomainMenuMargin;

		var sectionMenuHeight = $("div#sectionMenu").height();
		var sectionTopTarget = subdomainMenuHeight - sectionMenuHeight - 5;
		//alert(subdomainMenuHeight + ", " + subdomainMenuMargin);// + ", " + sectionTopTarget);
		$("div#sectionMenu:not(menuSelection)").css("zIndex", "1");
		$("div#sectionMenu"+menuSelection).css("zIndex", "5");
		$("div#sectionMenu:not(menuSelection)").animate({top:sectionTopTarget+'px'}, 200, 'easeOutBounce');
		$("div#sectionMenu"+menuSelection).animate({top:subdomainMenuHeight+5+'px'}, 400, 'easeOutBounce');
 	   });


  	  //When mouse rolls over domain navigation icons
  	  $("div#domainNavigation li").mouseover(function(){
		//Probably a better way to extract than by relying on index position
		//But for now some items have multiple classes and order is important; the class name is used to select related div for further behavior
		var allDomains = $(this).attr("class").split(" ");
		var oneDomain = allDomains[0];
		var targetRollover = oneDomain + "RolloverTitle";
		$("div#"+targetRollover).fadeIn("fast");
		
		//extend the rollover domain icon unless it is the current domain
		if (!($(this).hasClass("currentDomain"))) {
			$(this).stop().animate({height:'60px'},{queue:false, duration:600, easing: 'easeOutBounce'});
		};
 	  });

   	 //When mouse is removed from domain navigation icons
   	 $("div#domainNavigation li").mouseout(function(){
		var allDomains = $(this).attr("class").split(" ");
		var oneDomain = allDomains[0];
		var targetRollover = oneDomain + "RolloverTitle";
		$("div#"+targetRollover).fadeOut("fast");
		
		//retract the domain icon unless it is the current domain
		if (!($(this).hasClass("currentDomain"))) {
			$(this).stop().animate({height:'39px'},{queue:false, duration:600, easing: 'easeOutBounce'});
		};
   	 });
	
	//Domain navigation LIs are just background images and have no content to physically click on to get to other pages
	//We'll Javascript up the working link here
	$("div#domainNavigation li, div#download, div#bannerList li").click(function() {
		window.location = $(this).attr("href");
	});
		
});
