 $(document).ready(function(){
 	//page stylin
 
 	
 	//creates address book from xml file
 	
	
	$.ajax({
    url: 'humboldt-employment.xml',
    type: 'GET',
    dataType: 'xml',
    timeout: 1000,
    beforeSend: function() {
    //$("#loading").show()
    },
    error: function(){
        alert('Error loading XML document- Please Refresh');
    },
    success: function(xml){
    	
       $(xml).find('job').each(function(){
       		var cardID = $(this).attr("id")
       		var cardCategory = $(this).attr("category");
       		cardID= "job"+cardID;
      		var jobCard = $(document.createElement('dl')).attr("id",cardID);
 			
 		
 			// job title
 			var jobTitle = $(this).children().eq(0).text();
 			var jobTitleClass = $(this).children()[0].tagName;
 			$(document.createElement('dt')).html(jobTitle).addClass(jobTitleClass).prependTo(jobCard);
 			
 			
 			
 			
 			// job description 
 			var jobDescriptionWrap = $(document.createElement('dd')).addClass("jobDescription").appendTo(jobCard);
 			
 			var jobDescriptionText = $(this).children().eq(1).text();
 			var jobDescriptionClass = $(this).children()[1].tagName;
 			$(document.createElement('p')).html(jobDescriptionText).addClass(jobDescriptionClass).appendTo(jobDescriptionWrap);

 			
 			//email
 			var jobEmail = $(this).children().eq(2).text();
 			var jobEmailClass = $(this).children()[2].tagName;
 			$(document.createElement('p')).html(jobEmail).addClass(jobEmailClass).appendTo(jobDescriptionWrap);
 			
 			
 			
 			
 			
 			
 			 $(jobCard).appendTo("#"+cardCategory);
        	
        
    	});
    	
    	// checks if no jobs
    	
    	$("#jobs > div").each(function(){
    		if($(this).children().length == 0) {
    			$(this).html("<h4>No openings at this time</h4>")
    		}
    	});


    	//create email link
    		$("#jobs").find(".Email").each(function(){

			$(this).contents().not("[nodeType=1]").wrap("<a></a>")
			$(this).prepend("<strong>Apply to:</strong> ").append("<br /><em>Interested candidates please forward resume with cover letter</em>")	
			$(this).contents().eq(1).attr("href","mailto:"+$(this).contents().eq(1).text())
		
    		
    	});
    	
    	//inserts address book expander
    	$("#jobs dl dt").after("<dd class='expander'><a href='' class='moreinfo'>More Info</a></dd>")
    	
    	$("#jobs dl dd").not(".expander").hide();
    	$("#jobs dl .moreinfo").click(function(event){
			 $(this).toggleClass("infoOpened")
    	 	$(this).parent().siblings("dd.jobDescription").toggle("slow")
    	 	$(this).parent().parent().toggleClass("opened")
    	 	if($(this).text() == "More Info"){$(this).text("Hide Info")} else {$(this).text("More Info");
    	}
    	 return false;
    	 
    	});
    	
    	$("#jobs div dl").addClass("striped");
    	$("#jobs div dl dd span:odd").css("background-color","#ebf4fc");    	
    	//hides initial sections
    	
			$("#jobs > div").not("#Administrative").hide();
			$("#jobsTabs .Administrative a").addClass("current")
		
		
    	$("#jobsTabs li a").click(function(event){
    		var section = $(this).parent().attr("class")
    		$("#jobs > div").not("#"+section).hide();
    		$("#jobs #"+section).fadeIn("slow");
    		$("#jobsTabs li a").removeClass("current")
    		$(this).addClass("current")
			
    	 return false;
    	 
    	});

    	
    	
    }//end ajax
    

});
});