$(document).ready(function(){
	// Init splitter
	
	cookie_ready = 0; // Ugly hack (setCookie function in common.js 
					  //			involved in this as well): splitter could corrupt them 
					  //			so we switch it off for a while
	$("#maindiv").splitter({direction:'v', accessKey: "I"});
	$("#maindiv").trigger("resize");
	$(window).bind("resize", function(){
		height = $(window).height();    
		
		tmp = 24; 
		
		tmp += $("#pageheader").height();
		$("#content_container").height(height-tmp-$("#header").height()-10);
		$("#maindiv").height(height-tmp);
		$("#maindiv").trigger("resize");
	});        
	cookie_ready = 1;
	
	var myval = getCookie("splitterpos_v");
		
	
	if (myval == null){
		myval = "250px";
	}
	$("#left").width(myval);
	$(window).trigger("resize"); // adjust splitter's height

	// Init treeview
	$("#contents_tree > ul").find("ul").css('display', 'none');
	$("#contents_tree").treeview({persist: "location",collapsed: true});
	
	
	// Expand all parents of the selected node
	$("#contents_tree").find("span[active=1]").each(function(){
            $(this).parents('li.expandable').each(function(){
                $(this).find("span.hitarea").eq(0).click();                    
            });                                
        
            $(this).addClass("elemfocus");
    });
	
	
	
	// Treeview node: select/deselect logic	
	$("#contents_tree").find("span").mouseover(function(){
		if ($(this).attr('class') != 'hitarea')
			$(this).addClass("elemselected");
	}).mouseout(function(){
		if ($(this).attr('class') != 'hitarea')
			$(this).removeClass("elemselected");
	});

	// Ta-daam! Show the result to visitor.	
	$("#maindiv").css("visibility", "visible");	
	

});
