$(document).ready(function() {

	/* Dropdown menu javascript, also neccesery for animation to appear at all in IE6/IE7 */
	MainNavAnimate();

	FixIE6Problems();

	ClickableTopColumns();

	/* Add proper quotes around quote-tag. This is done in javascript since IE doesn't support :before/:after content in CSS */
	$("#Article q").prepend("&#8220;");
	$("#Article q").append("&#8221;");

	//Add last-child
	$("*:last-child").addClass("jq-last-child");


});

function ClickableTopColumns() {
	/* Make whole Top Columns clickable */
	$("#TopColumns > div").click(function() {  
		window.location = $(this).find("h2:first a:first").attr("href");  
	}); 	
	/* Give user a hint(hand cursor) that the whole column is clickable */
	$("#TopColumns > div").hover(function() {  
		$(this).css("cursor", "pointer"); 
		$(this).find("h2:first a:first").addClass("jq-hover");
	}, function() {  
		$(this).find("h2:first a:first").removeClass("jq-hover");
	}); 
}

function FixIE6Problems() {
	if($.browser.msie && $.browser.version.substr(0,1) == "6") {
		// Fix li hover 
		$("#MainNav > ul > li").hover(function() {  
			$(this).addClass("jq-hover");
		}, function() {  
			$(this).removeClass("jq-hover");
		}); 

		// Add first-child
		$("*:first-child").addClass("jq-first-child");


		//$("#MainNav > ul > li > a").css("line-height", "22px");

		$("#MainNav, #MainNav > ul > li").css("position", "static");

		//IE6 doesn't support min-height, but height acts like min-height should
		$("#Content").css("height", "585px");
	}
}

function MainNavAnimate() {
	//Hover(mouse in) on listitems that have submenus
	$("#MainNav > ul > li:has(ul)").hover(function() {
		//Get our ul which we will later drop down
		var ul = $(this).children("ul");

		//If the ul is animating that means it is closing.
		//If someone hovers over it while it is closing we want it to
		//stop closing and open again
		if (ul.is(":animated")) {
			ul.stop()
				.css("height", "auto")
				.slideDown(130);
		}
		//Otherwhise just open it normally.
		else {
			//Overide the usual CSS hover to allow for animation
			ul.css("display", "none");
			ul.slideDown(130);
		}
	},
	//Mouse out 
	function() {
		var ul = $(this).children("ul");

		if (ul.is(":animated")) {
			ul.stop()
				.css("height", "auto")
				.slideUp(130);
		}
		else {
			ul.slideUp(130);
		}
	});
}
