jQuery(document).ready(function(){


/**[ Table: CSS decorations and TD unit tooltips  ]**/

$("table.data").each(function(){
// Decorate the TH with row/col attribute so CSS can style properly	 
 $(this).find("tr:first th:gt(0)").attr( "id", "col" );
 $(this).find("tr:gt(0) th").attr( "id", "row" );

// Copy units from TR and add as tooltips to TD 
for (i=1;i<=5;i++)
{
$(this).find("tr:gt(0)").each(function(){
    $unit = $(this).parent().find("tr:first th").eq(i).attr("unit");
	if ($unit) {
	$td = $(this).children().eq(i);
	$td.attr("title",$td.text() + " " + $unit); 
	}
});
}

});



/**[ Sidebar min/max ]**/

$margin = $("#content").css("margin-left");

$("a#minmax").toggle(function(){
//$("#sidebar").animate({width:'hide'}, 5000);
$(".sidebar").animate({marginLeft:'-180px'}, { queue: false, duration: 1000 } )
             .animate({opacity:'hide'},500)

$("#content").animate( { marginLeft:'20px' }, 1000 ); 
$(this).attr("title","maximise sidebar");
$(this).text("[+]");
},function(){ 
$(".sidebar").animate({marginLeft:'10px'}, { queue: false, duration: 1000 } )
             .animate({opacity:'show'},1500);
$("#content").animate( { marginLeft:$margin }, 1000 ); 
$(this).attr("title","minimise sidebar");
$(this).text("[-]");
});



/**[ Table animations / highlighting ]**/

   $("table.data tr:gt(0) td").mouseenter(function() {
     $(this).addClass("purple");
		
	 $(this).parent().find("td").stop().animate( { backgroundColor:"#fffcf0" }, 400 )
	 $(this).parent().find("th").stop().animate( { backgroundColor:"#D7B2FF" }, 400 )
	 
     var index = $(this).parent().children().index($(this)); 
	 $col_th = $(this).parent().parent().find("tr:first").find("th").eq(index);
	 
	 $col_th.stop().animate( { backgroundColor:"#CDA8FF" }, 400 )
	 });
	 
   $("table.data tr:gt(0) td").mouseleave(function() {
	 $(this).removeClass("purple");
   
	 $(this).parent().find("td").stop().animate( { backgroundColor:"#FFFFFF" }, 600 )
     $(this).parent().find("th").stop().animate( { backgroundColor:"#EAD8FF" }, 600 )
	 
     var index = $(this).parent().children().index($(this)); 
	 $col_th = $(this).parent().parent().find("tr:first").find("th").eq(index);
	 
	 $col_th.stop().animate( { backgroundColor:"#E8D6FF" }, 600 );
	 });	 
  
});