/* to be able to change the URL of any page using onclick or similar function
----*/
function changeURL(destinationURL){ 
	window.location.href = destinationURL;
}


/* TO LOAD ON EVERY PAGE - loads templated pages
-----------------------------------------------------------*/
$(document).ready(function(){
		$("#right-bar").load("/template/right-column.html");
		$("#header").load("/template/header.html");
		$("#footer").load("/template/footer.html");
		subMenuLoad();
		setTimeout("tree()", 300); 
		setTimeout("runValidation()", 400);
		setTimeout("noClick()", 400);	
		
	});




/* SHOW SPECIFIC CONTACT BOX 
---------------------------------------------------------------- */
function noClick() {
	var bodyClass = ($('body').attr('class')); //identifies the body class
	var bodyId = ($('body').attr('id')); //identifies the body id

	if (bodyClass == 'school-loans' || bodyClass == 'school-accepted' || bodyId == 'ac'){
		$('#sub-nav-contact-loans').show();
	}
	if (bodyClass == 'company-press' || bodyClass == 'company-headlines' || bodyClass == 'company-news' || bodyClass == 'company-awards' || bodyClass == 'company-media-ac' || bodyClass == 'company-media'){
		$('#sub-nav-contact-press').show();
	}
	if (bodyClass == 'company-employment' || bodyClass == 'company-core'){
		$('#sub-nav-contact-employment').show();
	}
	if (bodyId == 'mentors'){
		$('#sub-nav-contact-mentors').show();
	}
	
}




/* SETTINGS FOR SUBNAV TREEVIEW
-------------------------------------*/
function tree() {
	$(".sub-nav-list").treeview({
		persist: "location",
		collapsed: true,
		unique: true
	})
}

/* TO LOAD FORM VALIDATION
-------------------------------------*/
function runValidation() {
	var bodyClass = ($('body').attr('class')); //identifies the body class

	if (bodyClass == 'school-gmi'){
		$("#gmi-form").validate();
	}
	if (bodyClass == 'resources-newsletter' || bodyClass == 'company-contact'){
		$(".cmxform").validate();
	}

}



/* TO LOAD APPROPRIATE SUB-MENU
-------------------------------------*/
function subMenuLoad() {
	var bodyId = ($('body').attr('id')); //identifies the body id
/* --- no longer using sub-nav-school.html since A&C is new menu system.
	if (bodyId == 'school'){
		$("#sub-nav").load("/template/sub-nav-school.html");
	}
*/
	if (bodyId == 'school'){
		$("#sub-nav").load("/template/sub-nav-school.html");
		$("#two-col-sub-nav").load("/template/sub-nav-school.html");	
	}
	if (bodyId == 'ac'){
		$("#two-col-sub-nav").load("/template/sub-nav-AandC.html");	
	}
	if (bodyId == 'mentors'){
		$("#sub-nav").load("/template/sub-nav-mentors.html");
	}
	if (bodyId == 'community'){
		$("#sub-nav").load("/template/sub-nav-community.html");
	}
	if (bodyId == 'resources'){
		$("#sub-nav").load("/template/sub-nav-resources.html");
	}
	if (bodyId == 'company'){
		$("#sub-nav").load("/template/sub-nav-company.html");
		$("#two-col-sub-nav").load("/template/sub-nav-company.html");
	}

}

/* Scroll feature for anchor links
-------------------------------------------*/
/*set class = scroll*/

function scrolling(loc){
		//prevent the default action for the click event
		//event.preventDefault();

		//get the full url - like mysitecom/index.htm#home
/*		var full_url = this.href;

		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
*/
		var trgt = "#"+loc;

		//get the top offset of the target anchor
		var target_offset = $(trgt).offset();
		var target_top = 250+target_offset.top;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 500);
}


/* Enable show/hide Toggle link
-------------------------------------------*/
function toggleLink() {
// Andy Langton's show/hide/mini-accordion - updated 23/11/2009
// Latest version @ http://andylangton.co.uk/jquery-show-hide
	var showText='Show'; 	// choose text for the show/hide link - can contain HTML (e.g. an image)
	var hideText='Hide';
	var is_visible = false;	// initialise the visibility check
	
	// append show/hide links to the element directly preceding the element with a class of "toggle"
	$('.toggle').prev().append(' (<a href="#" class="toggleLink">'+showText+'</a>)');
	
	// hide all of the elements with a class of 'toggle'
	$('.toggle').hide();
	
	// capture clicks on the toggle links
	$('a.toggleLink').click(function() {
		var currentText = $(this).html(); // grab current text (show or hide)
		if (currentText == showText){
			$(this).html(hideText);
			$(this).parent().next('.toggle').toggle('normal');
		}
		else {
			$(this).html(showText);
			$(this).parent().next('.toggle').toggle('normal');
		
		}
		return false;
	});
	
	$('.toggle-password').click(function() {
		$(this).next('.password-text').toggle('normal');
	});
}

