// JavaScript Document

$(document).ready(function(){
	$('#divisions .division').each(function() {
		var index = $('#divisions .division').index(this);
		$(this).addClass('division-' + (index + 1));
	});
	$('#boxes .box').each(function() {
		var index = $('#boxes .box').index(this);
		$(this).addClass('box-' + (index + 1));
	});
	
	$('#divisions .division .middlePart, #boxes .box .middlePart').wrapInner('<div class="innerContent"></div>');
	
	$('.studentInfo .quote').append('&#8221;').prepend('&#8222;');
	
	$('#schoolContent .left ul ul > li:last').addClass('last');
	$('#schoolContent .left ul li a.active').each(function() {
		$(this).parents('li').addClass('selected');
	});
		
	$('#topContent .banner h1, #topContent .banner .school').each(function() {
		var height = $(this).height();
		var subHeight = 0;
		var parentHeight = $(this).parent('.banner').height();
		
		$('#topContent .banner h2, #topContent .banner .division').each(function() {
			if ($(this).text().length > 0) {
				subHeight = $(this).height();
				$(this).css('top', (parentHeight - subHeight - 12) + 'px');
			}
		});
		
		if (subHeight > 0) {
			subHeight += 2;
			$(this).addClass('hasDivision');
		}
		
		var top = parentHeight - height - subHeight - 12;
		$(this).css('top', top + 'px');
	});
	
	
	$('ul.courseTabs').tabs();
	
	$('.diplomaSupplement dl dt:last, .diplomaSupplement dl dd:last').addClass('last');
	$('.diplomaSupplement dl dt').each(function() {
		var index = $('.diplomaSupplement dl dt').index(this);
		var dd = $('.diplomaSupplement dl dd:eq(' + index + ')');
		
		var dtHeight = $(this).height();
		var ddHeight = dd.height();
		
		var height = ddHeight;
		if (ddHeight < dtHeight) {
			height = dtHeight;	
		}
		
		$(this).css('height', height + 'px');
		dd.css('height', height + 'px');
	});
	
	$('.subNavigation').each(function() {
		if($(this).find('ul').text().length == 0) {
			$(this).hide();
		}
	});

	$('.banner').each(function() {
		if($(this).find('h1').text().length == 0) {
			$(this).hide();
		}
	});
});

function resizeIndicator(tab) {
	tab.append('<span class="schoolIndicator"></span>');
	var width = tab.width() - 8;
	$('.schoolIndicator').css('width', width + 'px');
}

function resizeBoxes() {
	var maxHeight = 0;
	$('#divisions .division, #boxes .box').each(function() {
		var height = $(this).children().find('.innerContent').height();
		if (height > maxHeight) {
			maxHeight = height;
		}
	}).children('.middlePart').css('height', maxHeight + 'px');
}

function resizeSimpleBoxes() {
	var maxHeight = 0;
	$('#bottomContent .simpleBox').each(function() {
		var height = $(this).height();
		if (height > maxHeight) {
			maxHeight = height;
		}
	}).children('.middlePart').css('height', (maxHeight + 20) + 'px');
	
	$('#news .buttons, #events .buttons, #students .buttons').css('top', (maxHeight - 4) + 'px');
}

function resetBoxes() {
	$('#divisions .division, #boxes .box').css('min-height', 'auto');
}