var ndToolbar = {};

ndToolbar = 
{
		initToolBar				:	function()
		{
			ndToolbar.initNewspaperList();
			ndToolbar.initDateList();
			ndToolbar.initResPerPageList();
		},
		
		initNewspaperList		:	function()
		{
			$("#newspaperSourceList .triangle").bind("click", ndToolbar.showNewspaperList);
			$("#timeline .triangle").bind("click", ndToolbar.hideNewspaperList);
			$("#resPerPage #resperpageCursor").bind("click", ndToolbar.hideNewspaperList);
			return (true);
		},
		
		showNewspaperList		:	function (event, ui)
		{
			var newspaperNumber = $("#newspaperSourceList #newspaperSourceListBoxes .newspapers").length;
			var newspaperBorderSize = $("#newspaperSourceList #newspaperSourceListBoxes .newspapers").length;
			$("#toolbar .resperpagebox.selected").css("visibility", "hidden");
			$("#toolbar .dateBox.selected").css("visibility", "hidden");
			$("#newspaperSourceList .triangle").unbind("click", ndToolbar.showNewspaperList);
			$("#newspaperSourceList #newspaperSourceListBoxes").css("width", 
					( newspaperNumber * $("#newspaperSourceList #newspaperSourceListBoxes .newspapers").width() + newspaperBorderSize) + "px");
			$("#newspaperSourceList #newspaperSourceListBoxes").css("left", "auto");
			$("#newspaperSourceList #newspaperSourceListBoxes").css("margin-left", "auto");
			$("#newspaperSourceList #newspaperSourceListBoxes .newspapers").css("display", "block");
			window.setTimeout("$('#newspaperSourceList .triangle').bind('click', ndToolbar.hideNewspaperList);", 100);
			return (true);
		},
		
		hideNewspaperList		:	function (event, ui)
		{
			$("#newspaperSourceList .triangle").unbind("click", ndToolbar.hideNewspaperList);
			$("#newspaperSourceList #newspaperSourceListBoxes").css("width", "");
			$("#newspaperSourceList #newspaperSourceListBoxes").css("left", "");
			$("#newspaperSourceList #newspaperSourceListBoxes").css("margin-left", "");
			$("#newspaperSourceList #newspaperSourceListBoxes .newspapers").css("display", "");
			$("#toolbar .resperpagebox.selected").css("visibility", "visible");
			$("#toolbar .dateBox ").css("visibility", "visible");
 			window.setTimeout("$('#newspaperSourceList .triangle').bind('click', ndToolbar.showNewspaperList);", 100);
		},
		
		initDateList		:	function()
		{
			$("#timeline .triangle").bind("click", ndToolbar.showDateList);
			$("#resPerPage #resperpageCursor").bind("click", ndToolbar.hideDateList);
			$("#newspaperSourceList .triangle").bind("click", ndToolbar.hideDateList);
			return (true);
		},
		
		showDateList		:	function (event, ui)
		{
			$("#timeline .triangle").unbind("click", ndToolbar.showDateList);
			$("#timeline #dateBoxes .dateBox").css("display", "block");
			window.setTimeout("$('#timeline .triangle').bind('click', ndToolbar.hideDateList);", 100);
			return (true);
		},
		
		hideDateList		:	function (event, ui)
		{
			$("#timeline .triangle").unbind("click", ndToolbar.hideDateList);
			$("#timeline #dateBoxes .dateBox").css("display", "");
 			window.setTimeout("$('#timeline .triangle').bind('click', ndToolbar.showDateList);", 100);
		},
		
		initResPerPageList		:	function()
		{
			$("#resPerPage #resperpageCursor").bind("click", ndToolbar.showResPerPageList);
			$("#timeline .triangle").bind("click", ndToolbar.hideResPerPageList);
			$("#newspaperSourceList .triangle").bind("click", ndToolbar.hideResPerPageList);
			return (true);
		},
		
		showResPerPageList		:	function (event, ui)
		{
			$("#resPerPage #resperpageCursor").unbind("click", ndToolbar.showResPerPageList);
			$("#resPerPage #resPerPageBoxes").css("margin-left", "0");
			$("#resPerPage #resPerPageBoxes").css("width", ($("#resPerPage #resPerPageBoxes .resperpagebox").length * $("#resPerPage #resPerPageBoxes .resperpagebox").width()) + "px");
			$("#resPerPage #resPerPageBoxes .resperpagebox").css("display", "block");
			window.setTimeout("$('#resPerPage #resperpageCursor').bind('click', ndToolbar.hideResPerPageList);", 100);
			return (true);
		},
		
		hideResPerPageList		:	function (event, ui)
		{
			$("#resPerPage #resperpageCursor").unbind("click", ndToolbar.hideResPerPageList);
			$("#resPerPage #resPerPageBoxes").css("margin-left", "");
			$("#resPerPage #resPerPageBoxes").css("width", $("#resPerPage #resPerPageBoxes .resperpagebox").width() + "px");
			$("#resPerPage #resPerPageBoxes .resperpagebox").css("display", "");
 			window.setTimeout("$('#resPerPage #resperpageCursor').bind('click', ndToolbar.showResPerPageList);", 100);
		}
};
