$(document).ready(function() {
	// JOB LISTING UI
	$(".jobPostAnchor").bind("click", function(){

		var jobId = this.id.substring('anchor_'.length)
		
		// hide intro content
		$('#introContent').hide();
		
		// hide career content
		$('#allCareersContent').hide();
		
		// copy job ad text into jobAd div in main content pane
		$('#jobAd').html($("#ad_"+jobId).html());
		
		// show submenu full description anchor
		$('#fullJobDescrAncor_'+jobId).show();
		
		// add full description behavior
		$('#jobAd').append(
			'<p><a href="" class="showFullJobDescrAnchor">Click here to view the Position Description</a></p>'
		);
		
		$('.showFullJobDescrAnchor').bind('click', function(){
			// hide submenu full description anchor
			$('#fullJobDescrAncor_'+jobId).hide();

			// copy job descr text
			$('#jobAd').html($('#descr_'+jobId).html());

			// add closing behavior to new content
			$('#jobAd').append(
					'<div style="float: right;"><a class="grayButton" href="#" id="closeJobAd">- hide</a></div>'
			);
			$('#closeJobAd').bind('click', function(){
				// erase current content
				$('#jobAd').html('');
				// show intro content
				$('#introContent').show();
				// show career content
				$('#allCareersContent').show();
				// prevent click-through
				return false;
			});

			// prevent click-through
			return false;

		});
		
		// add closing behavior
		$('#jobAd').append(
				'<div style="float: right;"><a class="grayButton" href="" id="closeJobAd">- hide</a></div>'
		);
		$('#closeJobAd').bind('click', function(){
			// erase current content
			$('#jobAd').html('');			
			// prevent click-through
			return false;
		});
				
		// prevent click-through
		return false;

	});
	
	// DISPLAY JOB DESCRIPTION
	$('.showJobDescrAnchor').bind('click', function(){
		
		// first get job id
		var jobId = this.id.substring('show_job_descr_'.length);
		
		// hide intro text
		$('#introContent').hide();
		
		// hide career content
		$('#allCareersContent').hide();
		
		// copy job descr text in jobAd div in main content pane
		$('#jobAd').html($("#descr_"+jobId).html());
		
		// add closing behavior
		$('#jobAd').append(
				'<div style="float: right;"><a class="grayButton" href="" id="closeJobAd">- hide</a></div>'
		);
		$('#closeJobAd').bind('click', function(){
			// erase current content
			$('#jobAd').html('');
			// show intro text
			$('#introContent').show();
			// show career content
			$('#allCareersContent').show();
			// prevent click-through
			return false;
		});

		// prevent click-through
		return false;
		
	});

	// CAREER CONTENT UI
	$(".careerContentAnchor").bind("click", function(){
		
		if ($("#"+this.id).hasClass('contentOpen')){
			return false;
		}
		
		var cc = this.id.substring('careerContentAnchor_'.length)
		
		// remember that this one is open
		$(".careerContentAnchor").removeClass('contentOpen');
		$("#"+this.id).addClass('contentOpen');
				
		// show desired ad
		$("#cc_"+cc).show(500);
		
		// prevent click-through
		return false;
	});

	$(".hideCareerContentAnchor").bind("click", function(){
		
		var cc = this.id.substring('hideCareerContentAnchor_'.length)
		
		$("#careerContentAnchor_"+cc).removeClass('contentOpen');
				
		// show desired ad
		$("#cc_"+cc).hide(500);
		
		// prevent click-through
		return false;
	});

	$(".expandAllAnchor").bind("click", function() {

		// show all career content
		$(".careerContent").show(500);		
		$(".careerContentAnchor").addClass('contentOpen');
			
		// hide this button and show hide all button
		$("#hideAllDiv").show();	
		$("#expandAllDiv").hide();
	
		// prevent click-through
		return false;
	});

	$(".hideAllAnchor").bind("click", function() {

		// show all career content
		$(".careerContent").hide(500);		
		
		$(".careerContentAnchor").removeClass('contentOpen');
		
		// hide this button and show hide all button
		$("#hideAllDiv").hide();	
		$("#expandAllDiv").show();
	
		// prevent click-through
		return false;
	});
	
});

