$(document).ready(function() {
	$("#mag").hide();
	$("#tada").click(toggleLink);
	$("#tada").click(toggleMag);
	$(window).load(mensubHeight);
});

function toggleLink() {
	if ($("#mag").is(":visible")) {
		$("#tada").attr("title","View the magazine on screen (requires Flash)");
		$("#tada").text("View the mag");
	}
	else
	{			
		$("#tada").attr("title","Hide the mag");
		$("#tada").text("Hide the mag");
	}	
}


function toggleMag() {
	$("#mag").toggle("medium");
}


function mensubHeight() {
	var menu_sub = $("#menu_sub").height();
	var ht = "height: ";
	
	// vertical padding total in styles for menu_sub 
	var pad = 43;

	// If menu_sub doesn't exist do nothing 
	if (menu_sub == null) {
		return;
	}
	else {
		var content = $("#content").height();
		var content_sub = $("#content_sub").height();

		// if content_sub doesn't exist we need only compare menu_sub with content
		if (content_sub == null) {
			
			// If menu_sub is taller than content do nothing 
			if (menu_sub > content) {
				return;
			}
			else {
			// Set ht to the same as content
			ht = ht + (content-pad) + "px;";
			}

		}
		else {
		
			// if content_sub does exist, check if it is taller than content
			if (content > content_sub) {
				
				// If menu_sub is taller than content do nothing 
				if (menu_sub > content) {
					return;
				}
				else {
				// Set ht to the same as content_sub
				ht = ht + (content-pad) + "px;";
				}
			}
			else {
			// content_sub is taller than content
			
				// If menu_sub is taller than content_sub do nothing 
				if (menu_sub > content_sub) {
					return;
				}
				else {
				// Set ht to the same as content_sub
				ht = ht + (content_sub-pad) + "px;";
				}
				
			}
		}
		
		// set CSS height of menu_sub
		$("#menu_sub").attr("style",ht);
	}	
	
}


