﻿var initToggle	=	function(){
	$(".expandableDetail").hide();
	$(".expandableTitle").addClass("closed");
	$(".expandableTitle").click(function(){
		/* 
		bug in jquery 1.3 affecting toggle() in IE8
		http://stackoverflow.com/questions/975153/jquery-toggle-not-working-with-trs-in-ie
		*/
		//$(this).parents("tr").next(".expandableDetail").toggle();
		var elem = $(this).parents("tr").next(".expandableDetail")[0];
		if( elem.style.display == 'none' ) {
			$(this).parents("tr").next(".expandableDetail").show();		
		} else {
			$(this).parents("tr").next(".expandableDetail").hide();		
		}
		$(this).toggleClass("closed");
		$(this).toggleClass("expanded");
		return false;
	});
	// Create toggleAll link
	var toggleAllLink	=	document.createElement("a");
	$(toggleAllLink).attr("href","#").text("Expand all").addClass("toggleAllLink");
	$(toggleAllLink).click(function(){
		if(this.innerHTML == "Expand all"){
			$(this).text("Titles only");
			$(".expandableDetail").show();
		} else {
			$(this).text("Expand all");
			$(".expandableDetail").hide();
		}
		$(".expandableTitle").toggleClass("closed");
		$(".expandableTitle").toggleClass("expanded");
		return false;
	});
	$("#detailColumn").append(toggleAllLink);
};
var initRowHover = function(){
	$(".expandableHead").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
}
$(function(){
	initToggle();
	initRowHover();
});
