// DEFINE VARS --
var top					= 250; // top of banner
var space				= 20;
var grassTop			= 0;

var bookHeight			= 0;
var youtubeHeight		= 0;
var supportersHeight	= 0;
var contactHeight		= 0;	

var introHeight			= 0;	
var	themesHeight 		= 0;
var	maggieHeight		= 0;
var	commentsHeight		= 0;

var advisoryPanelHeight		= 0;
// --------------

checkReady();

// --------------

function checkReady() {
	if($('#container').width() >= 960) {
		//alert($('#container').width());
		checkLayout();
	} else {
		setTimeout("checkReady()", 100);
	}
}

// --------------

function checkLayout() {
	// THESE NEED TO BE LOADED BEFORE THEY CAN BE CHECKED
	bookHeight					= $('#book').height();
	youtubeHeight				= $('#youtube').height();
	supportersHeight			= $('#supporters').height();
	contactHeight				= $('#contact').height();
	
	switch (PAGEID) {
		case "INDEX":			checkIndex(); break;
		case "PANEL":			checkPanel(); break;
		case "PROGRAMME":		checkProgramme(); break;
		case "PARTNERS":		checkPartners(); break;
		case "SPEAKERS":		checkSpeakers(); break;
		case "ACCESSIBILITY":	checkAccess(); break;
		case "PRIVACY":			checkPrivacy(); break;
		case "SURGERIES":		checkSurgeries(); break;
		case "EXHIBITORS":		checkExhibitors(); break;
		case "MEDIA":			checkMedia(); break;
	}
	
	$('#grass').css('top', grassTop + (space*3) + "px");
	
}

// --------------

function checkIndex() {
	
	bannerHeight	= $('#banner').height() + space;
	introHeight		= $('#intro').height();	
	themesHeight	= $('#themes').height();
	maggieHeight	= $('#maggie-philbin').height();
	commentsHeight	= $('#comments').height();
	
	// col 1
	$('#book').css('top', top + "px");
	$('#youtube').css('top', top + bookHeight + (space*1) + "px");
	
	// col 2
	$('#intro').css('top', top + bannerHeight + (space*1) + "px");
	$('#themes').css('top', top + bannerHeight + introHeight + (space*2) + "px");
	$('#maggie-philbin').css('top', top + bannerHeight + introHeight + themesHeight +  (space*3) + "px");
	
	// col 3
	$('#comments').css('top', top + bannerHeight + (space*1) + "px");
	$('#contact').css('top', top + bannerHeight + commentsHeight + (space*2) + "px");
		
	// check for lowest point
	col1 = top + bookHeight + youtubeHeight + /*supportersHeight +*/ (space*2);
	col2 = top + bannerHeight + introHeight + themesHeight + maggieHeight + (space*3);
	col3 = top + bannerHeight + commentsHeight + contactHeight + (space*2);
	
	if(col1 > col2) {
		if(col1 > col3) grassTop = col1;
		else grassTop = col3;
	} else {
		grassTop = col2;
	}
	
	return;
}

// --------------

function checkPanel() {
	advisoryPanelHeight = $('#advisory-panel-profiles').height();
	advisoryPanelHeadingHeight = $('#advisory-panel-heading').height();
	advisoryPanelMenuHeight = $('#advisory-panel-menu').height();
	commentsHeight = $('#comments').height();
	
	// col 1
	$('book').css('top', top + "px");
	$('#advisory-panel-menu').css('top', top + bookHeight + (space*2) + "px");
	$('#youtube').css('top', top + advisoryPanelMenuHeight + bookHeight + (space*4) + "px");
	
	// col 2
	$('#advisory-panel-heading').css('top', top + (space*1) + "px");
	$('#advisory-panel-profiles').css('top', top + advisoryPanelHeadingHeight + (space*2) + "px");	
	
	// col 3
	$('#comments').css('top', top + advisoryPanelHeadingHeight + (space*2) + "px");
	$('#contact').css('top', top + advisoryPanelHeadingHeight + commentsHeight + (space*3) + "px");
	
	// Check for lowest point
	col1 = top + advisoryPanelMenuHeight + bookHeight + youtubeHeight + (space*4);
	col2 = top + advisoryPanelHeadingHeight + advisoryPanelHeight + (space*2);
	col3 = top + advisoryPanelHeadingHeight + commentsHeight + contactHeight + (space*3);
	
	if(col1 > col2) {
		if(col1 > col3) grassTop = col1;
		else grassTop = col3;
	} else {
		grassTop = col2;
	}
		
	return;
}

// --------------

function checkContact() {
	bannerHeight = $('#banner').height() + space;
	
	introHeight = $('#intro').height();	
	themesHeight = $('#themes').height();
	maggieHeight = $('#maggie-philbin').height();
	commentsHeight = $('#comments').height();
	
	$('book').css('top', top + "px");
	$('#intro').css('top', top + bannerHeight + (space*1) + "px");
	$('#comments').css('top', top + bannerHeight + (space*1) + "px");
	
	$('#youtube').css('top', top + bookHeight + (space*1) + "px");
	$('#supporters').css('top', top + bookHeight + youtubeHeight + (space*2) + "px");
	
	$('#themes').css('top', top + bannerHeight + introHeight + (space*2) + "px");
	$('#maggie-philbin').css('top', top + bannerHeight + introHeight + themesHeight +  (space*3) + "px");
	
	$('#contact').css('top', top + bannerHeight + commentsHeight + (space*2) + "px");
		
	// Check for lowest point
	col1 = top + bookHeight + youtubeHeight + supportersHeight + (space*2);
	col2 = top + bannerHeight + introHeight + themesHeight + maggieHeight + (space*3);
	col3 = top + bannerHeight + commentsHeight + contactHeight + (space*2);
	
	if(col1 > col2) {
		if(col1 > col3) grassTop = col1;
		else grassTop = col3;
	} else {
		if(col1 > col2) grassTop = col1;
		else grassTop = col2;
	}
	
	return;
}

// --------------

function checkProgramme() {
	
	// bookHeight - see checkLayout
	// youtubeHeight - see checkLayout
	programmeHeadingHeight = $('#programme-heading').height();
	programmeHeight = $('#programme').height();
	commentsHeight = $('#comments').height();
	// contactHeight - see checkLayout
		
	// col 1
	$('book').css('top', top + "px");
	$('#youtube').css('top', top + bookHeight + (space*1) + "px");
		
	// col 2
	$('#programme-heading').css('top', top + (space*1) + "px");
	$('#programme').css('top', top + programmeHeadingHeight + (space*2) + "px");
	
	// col 3
	$('#comments').css('top', top + programmeHeadingHeight + (space*2) + "px");	
	$('#contact').css('top', top + programmeHeadingHeight + commentsHeight + (space*3) + "px");
		
	// Check for lowest point
	col1 = top + bookHeight + youtubeHeight + (space*2);
	col2 = top + programmeHeadingHeight + programmeHeight + (space*2);
	col3 = top + programmeHeadingHeight + commentsHeight + contactHeight + (space*3);
		
	if(col1 > col2) {
		if(col1 > col3) grassTop = col1;
		else grassTop = col3;
	} else {
		if(col1 > col2) grassTop = col1;
		else grassTop = col2;
	}
	
	return;
}

// --------------

function checkPartners() {
	
	// bookHeight - see checkLayout
	// youtubeHeight - see checkLayout
	partnersHeadingHeight = $('#partners-heading').height();
	partnersHeight = $('#partners').height();
	commentsHeight = $('#comments').height();
	// contactHeight - see checkLayout
	
	// Check Partner logo heights do not exceed the height of their corresponding text
	// or make alterations if they do.
	
	bbcH = $('#partner-bbc .partner-text').height();
	ch4H = $('#partner-channel4 .partner-text').height();
	itvH = $('#partner-itv .partner-text').height();
	skyH = $('#partner-sky .partner-text').height();
	pacH = $('#partner-pact .partner-text').height();
	rcH = $('#partner-radiocentre .partner-text').height();
	scH = $('#partner-scbg .partner-text').height();
	wfH = $('#partner-wftv .partner-text').height();
	
	LbbcH = $('#partner-bbc .partner-img').height();
	Lch4H = $('#partner-channel4 .partner-img').height();
	LitvH = $('#partner-itv .partner-img').height();
	LskyH = $('#partner-sky .partner-img').height();
	LpacH = $('#partner-pact .partner-img').height();
	LrcH = $('#partner-radiocentre .partner-img').height();
	LscH = $('#partner-scbg .partner-img').height();
	LwfH = $('#partner-wftv span').height();
		
	if(bbcH > LbbcH)	$('#partner-bbc').css(			'height', bbcH);
	if(ch4H > Lch4H)	$('#partner-channel4').css(		'height', ch4H);
	if(itvH > LitvH)	$('#partner-itv').css(			'height', itvH);
	if(skyH > LskyH)	$('#partner-sky').css(			'height', skyH);
	if(pacH > LpacH)	$('#partner-pact').css(			'height', pacH);
	if(rcH > LrcH)		$('#partner-radiocentre').css(	'height', rcH);
	if(scH > LscH)		$('#partner-scbg').css(			'height', scH);
	if(wfH > LwfH)		$('#partner-wftv').css(			'height', wfH);
	
	if(bbcH < LbbcH)	$('#partner-bbc').css(			'height', LbbcH);
	if(ch4H < Lch4H)	$('#partner-channel4').css(		'height', Lch4H);
	if(itvH < LitvH)	$('#partner-itv').css(			'height', LitvH);
	if(skyH < LskyH)	$('#partner-sky').css(			'height', LskyH);
	if(pacH < LpacH)	$('#partner-pact').css(			'height', LpacH);
	if(rcH < LrcH)		$('#partner-radiocentre').css(	'height', LrcH);
	if(scH < LscH)		$('#partner-scbg').css(			'height', LscH);
	if(wfH < LwfH)		$('#partner-wftv').css(			'height', LwfH);
	
	// Recheck '#partners' height!
	partnersHeight = $('#partners').height();
	
	// col 1
	$('book').css('top', top + "px");
	$('#youtube').css('top', top + bookHeight + (space*1) + "px");
		
	// col 2
	$('#partners-heading').css('top', top + (space*1) + "px");
	$('#partners').css('top', top + partnersHeadingHeight + (space*2) + "px");
	
	// col 3
	$('#comments').css('top', top + partnersHeadingHeight + (space*2) + "px");	
	$('#contact').css('top', top + partnersHeadingHeight + commentsHeight + (space*3) + "px");
		
	// Check for lowest point
	col1 = top + bookHeight + youtubeHeight + (space*2);
	col2 = top + partnersHeadingHeight + partnersHeight + (space*2);
	col3 = top + partnersHeadingHeight + commentsHeight + contactHeight + (space*3);
		
	if(col1 > col2) {
		if(col1 > col3) grassTop = col1;
		else grassTop = col3;
	} else {
		if(col1 > col2) grassTop = col1;
		else grassTop = col2;
	}
	
	return;
}

// --------------

function checkSpeakers() {
	speakersHeight = $('#speakers-profiles').height();
	speakersHeadingHeight = $('#speakers-heading').height();
	speakersMenuHeight = $('#speakers-menu').height();
	commentsHeight = $('#comments').height();
	
	// col 1
	$('book').css('top', top + "px");
	$('#speakers-menu').css('top', top + bookHeight + (space*2) + "px");
	$('#youtube').css('top', top + speakersMenuHeight + bookHeight + (space*4) + "px");
	
	// col 2
	$('#speakers-heading').css('top', top + (space*1) + "px");
	$('#speakers-profiles').css('top', top + speakersHeadingHeight + (space*2) + "px");	
	
	// col 3
	$('#comments').css('top', top + speakersHeadingHeight + (space*2) + "px");
	$('#contact').css('top', top + speakersHeadingHeight + commentsHeight + (space*3) + "px");
	
	// Check for lowest point
	col1 = top + speakersMenuHeight + bookHeight + youtubeHeight + (space*4);
	col2 = top + speakersHeadingHeight + speakersHeight + (space*2);
	col3 = top + speakersHeadingHeight + commentsHeight + contactHeight + (space*3);
	
	if(col1 > col2) {
		if(col1 > col3) grassTop = col1;
		else grassTop = col3;
	} else {
		grassTop = col2;
	}
		
	return;
}

// --------------

function checkPrivacy() {
	// bookHeight - see checkLayout
	// youtubeHeight - see checkLayout
	privacyPolicyHeadingHeight = $('#privacy-policy-heading').height();
	privacyPolicyHeight = $('#ldbc10-privacy-policy').height();
	commentsHeight = $('#comments').height();
	// contactHeight - see checkLayout
	
	// col 1
	$('book').css('top', top + "px");
	$('#youtube').css('top', top + bookHeight + (space*1) + "px");
	
	// col 2
	$('#privacy-policy-heading').css('top', top + (space*1) + "px");
	$('#ldbc10-privacy-policy').css('top', top + privacyPolicyHeadingHeight + (space*2) + "px");
	
	// col3
	$('#comments').css('top', top + privacyPolicyHeadingHeight + (space*2) + "px");
	$('#contact').css('top', top + privacyPolicyHeadingHeight + commentsHeight + (space*3) + "px");
	
	// Check for lowest point
	col1 = top + bookHeight + youtubeHeight + (space*2);
	col2 = top + privacyPolicyHeadingHeight + privacyPolicyHeight + (space*2);
	col3 = top + privacyPolicyHeadingHeight + commentsHeight + contactHeight + (space*3);
	
	if(col1 > col2) {
		if(col1 > col3) grassTop = col1;
		else grassTop = col3;
	} else {
		if(col1 > col2) grassTop = col1;
		else grassTop = col2;
	}
	
	return;
}

// --------------

function checkAccess() {
	
	// bookHeight - see checkLayout
	// youtubeHeight - see checkLayout
	accessibilityHeadingHeight = $('#accessibility-heading').height();
	accessibilityMenuHeight = $('#accessibility-menu').height();
	accessibilityDetailsHeight = $('#accessibility-details').height();
	commentsHeight = $('#comments').height(); // ?????????????????????????????????????????????????????
	// contactHeight - see checkLayout
	
	// col 1
	$('book').css('top', top + "px");
	$('#accessibility-menu').css('top', top + bookHeight + (space*2) + "px");
	$('#youtube').css('top', top + bookHeight + accessibilityMenuHeight + (space*4) + "px");
	
	// col 2
	$('#accessibility-heading').css('top', top + (space*1) + "px");
	$('#accessibility-details').css('top', top + accessibilityHeadingHeight + (space*2) + "px");
	
	// col3
	$('#comments').css('top', top + accessibilityHeadingHeight + (space*2) + "px");
	$('#contact').css('top', top + accessibilityHeadingHeight + commentsHeight + (space*3) + "px");
	
	// Check for lowest point
	col1 = top + bookHeight + youtubeHeight + (space*4);
	col2 = top + accessibilityHeadingHeight + accessibilityDetailsHeight + (space*3);
	col3 = top + commentsHeight + contactHeight + (space*2);
	
	if(col1 > col2) {
		if(col1 > col3) grassTop = col1;
		else grassTop = col3;
	} else {
		if(col1 > col2) grassTop = col1;
		else grassTop = col2; 
	}
	
	return;
}

// --------------

function checkSurgeries() {
	// bookHeight - see checkLayout
	// youtubeHeight - see checkLayout
	surgeriesHeadingHeight = $('#surgeries-heading').height();
	surgeriesDetailsHeight = $('#surgeries-details').height();
	commentsHeight = $('#comments').height(); // ?????????????????????????????????????????????????????
	// contactHeight - see checkLayout
	
	// col 1
	$('book').css('top', top + "px");
	$('#youtube').css('top', top + bookHeight + (space*2) + "px");
	
	// col 2
	$('#surgeries-heading').css('top', top + (space*1) + "px");
	$('#surgeries-details').css('top', top + surgeriesHeadingHeight + (space*2) + "px");
	
	// col3
	$('#comments').css('top', top + surgeriesHeadingHeight  + "px");
	$('#contact').css('top', top + surgeriesHeadingHeight + commentsHeight + (space*1) + "px");
	
	// Check for lowest point
	col1 = top + bookHeight + youtubeHeight + (space*4);
	col2 = top + surgeriesHeadingHeight + surgeriesDetailsHeight + (space*3);
	col3 = top + commentsHeight + contactHeight + (space*2);
	
	if(col1 > col2) {
		if(col1 > col3) grassTop = col1;
		else grassTop = col3;
	} else {
		if(col1 > col2) grassTop = col1;
		else grassTop = col2; 
	}
	
	return;
}

// --------------

function checkExhibitors() {
	// bookHeight - see checkLayout
	// youtubeHeight - see checkLayout
	exhibitorsHeadingHeight = $('#exhibitors-heading').height();
	exhibitorsMenuHeight = $('#exhibitors-menu').height();
	exhibitorsDetailsHeight = $('#exhibitors-details').height();
	commentsHeight = $('#comments').height(); // ?????????????????????????????????????????????????????
	// contactHeight - see checkLayout
	
	// col 1
	$('book').css('top', top + "px");
	$('#exhibitors-menu').css('top', top + bookHeight + (space*2) + "px");
	$('#youtube').css('top', top + exhibitorsMenuHeight + bookHeight + (space*3) + "px");
	
	// col 2
	$('#exhibitors-heading').css('top', top + (space*1) + "px");
	$('#exhibitors-details').css('top', top + exhibitorsHeadingHeight + (space*2) + "px");
	
	// col3
	$('#comments').css('top', top + exhibitorsHeadingHeight  + "px");
	$('#contact').css('top', top + exhibitorsHeadingHeight + commentsHeight + (space*1) + "px");
	
	// Check for lowest point
	col1 = top + bookHeight + youtubeHeight + (space*4);
	col2 = top + exhibitorsHeadingHeight + exhibitorsDetailsHeight + (space*3);
	col3 = top + commentsHeight + contactHeight + (space*2);
	
	if(col1 > col2) {
		if(col1 > col3) grassTop = col1;
		else grassTop = col3;
	} else {
		if(col1 > col2) grassTop = col1;
		else grassTop = col2; 
	}
	
	return;
}

// --------------

function checkMedia() {
	mediaHeadingHeight = $('#media-heading').height();
	mediaMenuHeight = $('#media-menu').height();
	mediaHeight = $('#media').height();
	
	// col 1
	$('book').css('top', top + "px");
	$('#youtube').css('top', top + bookHeight + (space*3) + "px");
	$('#contact').css('top', top + bookHeight + (space*4) + "px");
	
	// col 2
	$('#media-heading').css('top', top + (space*1) + "px");
	$('#media').css('top', top + mediaHeadingHeight + (space*2) + "px");
	
	// Check for lowest point
	col1 = top + bookHeight + youtubeHeight + commentsHeight + (space*4);
	col2 = top + mediaHeadingHeight + mediaHeight + (space*3);
	
	//alert(mediaHeight + " - " + $('#media').height());
	
	if(col1 > col2) {
		grassTop = col1;
	} else {
		grassTop = col2; 
	}
	
	return;
}

// --------------



