// JavaScript Document
$(document).ready(function(){
	clearClick();
	setBrowserClass();
	adjustContentHeight();
	initCloseButton();
	initMenu();
});

function adjustContentHeight(){
	if($('#sidebar').length > 0){
		var sidebarTopMargin = parseInt($('#sidebar').css('margin-top').replace('px',''));
		var sidebarHeight = $('#sidebar').height() + sidebarTopMargin;
		//console.log(sidebarHeight);
		var contentHeight = $('#content').height();
		//console.log(contentHeight);
		if(contentHeight < sidebarHeight){
			$('#content').height(sidebarHeight);
		}else{
			var newHeight = contentHeight - sidebarTopMargin;
			$('#sidebar').height(newHeight);
		}
	}
}

/*-----------------
 * Ministry and Campus dropdowns
 *-----------------*/
var currentTab = "";

function initCloseButton(){
	$("#btnclose").click(function(){
		$("#dropdown_wrapper").slideUp(function(){
			$("#"+currentTab).css('display','none');
		});
	});
	return false;
}

function showDropdown(id){
	currentTab = id;
	$("#"+id).css('display','block');
	$('#dropdown_wrapper').slideDown();
	return false;
}


function initMenu() {
	
	// This is the function if any conntent needs to collapse
	$('#text .collapseContent').hide();
	//$('#nav ul:first').show();
	$('#text .collapseTitle').click(function(){
		var checkElement = $(this).next();
		if((checkElement.is('.collapseContent')) && (checkElement.is(':visible'))) {
			$('#text .collapseContent:visible').slideUp('fast');
			return false;
		}
		if((checkElement.is('.collapseContent')) && (!checkElement.is(':visible'))) {
			$('#text .collapseContent:visible').slideUp('fast');
			checkElement.slideDown('fast');
			return false;
		}
	});
}
