var APP_ROOT_URL = '/';

$(document).ready(function() {
      $('a.logo').hover(function() {
	  $(this).children("img.logo").attr("src",APP_ROOT_URL + "images/Logo-over.png");}, function() {
	  $(this).children("img.logo").attr("src",APP_ROOT_URL + "images/Logo-up.png");
       });

	$('ul.sf-menu').superfish({ 
            delay:       1000,                            // one second delay on mouseout 
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:       'fast',                          // faster animation speed 
            autoArrows:  false  
	}); 

	var page = location.href;
	
	if ( page.indexOf("misson") != -1 || page.indexOf("background") !=-1 ) {
			$('#menu1').addClass("menuon");
	}
	if ( page.indexOf("doc") != -1 || page.indexOf("glossary") !=-1 ) {
			$('#menu2').addClass("menuon");
	}
	if ( page.indexOf("order-a-field-manual") != -1 | page.indexOf("professional-resources") !=-1 || 	page.indexOf("recomended-reading") !=-1  )  {
			$('#menu4').addClass("menuon");
	}
	if ( page.indexOf("questions-to-ask-your-contractor") != -1 || page.indexOf("animated-how-to") !=-1  ) {
			$('#menu5').addClass("menuon");
	}

	var cr = $('div.contentRight').height();
	var cl = $('div.contentLeft').height()
	if (cr < cl) { cr = cl; }
	$('div.contentLeft').height((cr + 50));
	var foo = "bar";
	
});
 
 function menuOpen () {
	 $("ul#gnav li").removeClass("menuon");
	 $(this.target).addClass("menuon");
	 checkMenuStatus();
 }
 
 function checkAnswers () {     
     $("input.quiz-answer").each(function(i) {
         if ($(this)[0].checked) {
             var name = $(this)[0].name;
             if ($(this)[0].value == "wrong") {
                 var correct_answer =  $( "input[@name=" + name +"][@value=correct]" )[0].nextSibling.firstChild.nodeValue;
                 $("div#" + name).html("<img src='images/x.gif' /> The correct answer is <span class='correct-answer'>" + correct_answer +  "</span>");
             }
             else {
                 var name = $(this)[0].name;
                     $("div#" + name).html("<img src='images/check.gif' /> You are correct! Good Job!  ");
             }
         }
       });
    
}

function showDefinition(xml) {
    var data = xml;
    var term = location.hash.slice(1);
    var def = $( "a[@name=" + term +"]",xml).parent().parent();
    $('div#definition').html(def);
 
}      
     
function checkMenuStatus () { 
	var status = false;
	$.timer(1000, function (timer) {
  		if (!status) {
  			// is menu open?
			if (status) {
				status = true;
			}
			else {
				status = false;
				timer.reset(1000);
			}
  		}
  		else {
  			alert('Second time');
  			timer.stop();
  		}
  	});
  


	
}
      
      
//	if ($('div#definition')) {
//	    $.ajax({
//	      type: "GET",
//	      url: "content/glossary.xml",
//	      success: function(xml){
//	      showDefinition(xml);
//	   }
//	   });
//	}      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
