// Version 1.6, modified by Jon Ippolito to add new graph section and FAQ link.

function menubarInit(){
	Loader.include('artPanel');
	topMenu = new menuBar("topMenu");
	topMenu.newButton("FAQ","Frequently Asked Questions","javascript:window.open('http://pool.newmedia.umaine.edu/faq.html');","help");
	topMenu.newButton("Walkthrough","A tour of key features","javascript:window.open('http://pool.newmedia.umaine.edu/walkthrough/');","help");
	//topMenu.newButton("Tour","Slideshow introduction to The Pool","javascript:location = 'intro/';","help");
	topMenu.buttonHeader("media/help_header.png");
	topMenu.newButton("Balance","Adjust the graph to balance accuracy and legibility","javascript:workingBasin.setAccuracy(4, 4, 4);","graph");
	topMenu.newButton("Accuracy","Optimize the graph for accuracy","javascript:workingBasin.setAccuracy(9, 9, 9);","graph");
	topMenu.newButton("Legibility","Optimize the graph for legibility","javascript:workingBasin.setAccuracy(0, 0, 0);","graph");
	topMenu.columnBreak();
	topMenu.newButton("Advanced", "Change the axes, accuracy, and objects shown in the graph", "javascript:GraphPanel('art');", "graph");	
	topMenu.newButton("Reset", "Reset the Pool to the default display options.", "javascript:workingBasin.resetPool();", "graph");
	topMenu.newButton("Fullscreen", "Allow the Pool to use your entire screen.", "javascritp:openFullScreen();", "graph");
	topMenu.buttonHeader("media/graph_header.png");
	//topMenu.newButton("Art","Go to the Art Pool","javascript:location = 'pool.php?choice=art';","pool");
	topMenu.newButton("Log In", "Log in to The Pool", "javascript:GenericPanel('Login', panelContent.login, 'loginPanel');", "nav");
	topMenu.newButton("Log Out","Log out of The Pool","javascript:topMenu.doLogout();","nav");
	topMenu.newButton("My Account", "See information on my account", "javascript:topMenu.showAccount();", "nav");
	topMenu.newButton("Intro", "Go back to the Pool's home page.", "javascript:window.location='/index.php'", "nav");
	topMenu.buttonHeader("media/home_header.png");
	topMenu.newButton("Creation","Add a new intent to the Art Pool","javascript:ArtPanel.openIntentInput();", "add");
	topMenu.newButton("Reference","Add a new art reference to the Pool","javascript:Loader.require('artReferencePanel', 'ArtReferencePanel.loadInput', []);", "add");
	//topMenu.columnBreak();
	//topMenu.newButton("Theme","Go to the Theme Pool","javascript:location = 'theme_pool_v02.0.html';","pool");
	topMenu.buttonHeader("media/add_header.png");
	topMenu.newButton("Art Creation", "Go to the Art Pool", "javascript:window.location='art_pool.php'", "pool");
	topMenu.newButton("Art Ref.", "Go to the Art Reference Pool", "javascript:window.location='artreference_pool.php'", "pool");
	topMenu.newButton("Code Creation", "Go to the Code Pool", "javascript:window.location='code_pool.php'", "codePool");
	topMenu.newButton("Code Ref.", "Go to the Code Reference Pool", "javascript:window.location='codereference_pool.php'", "codePool");
	topMenu.buttonHeader("media/pools_header.png");
	//topMenu.newButton("Lounge","Go to your Lounge","javascript:location = 'home.php';","nav");

	topMenu.newGeneric("Search",{	top: 2,
									left: 130,
									width: 400,
									html: "<form name='searchForm' id='searchForm' class='menuText'>...or do a title search: <input type='text' id='searchBox' name='searchBox' onKeyUp='workingBasin.searchFilter(this.value, this.name)' class='searchbox' /></form>"});
	topMenu.newGeneric("FilterLabel",{	top: 2,
										left: 40,
										width: 80,
										html: "<span class='bigMenuText'>Filter Pool</span>" });
	 topMenu.newGeneric("MenuHelpText",{	top:	0,
										right:	10,
										width:	500,
										textAlign: "right",
										color: [180,180,0],
										fontSize: 16,
										zIndex: 2,
										html: ""});
	topMenu.newSelector("Master", "selectorDialog.display();");
	/*topMenu.newGeneric("sliderText", {	top: 35,
										left: 240,
										fontSize: 12,
										textAlign: "center",
										height: 16,
										width: 210,
										lineHeight: 16,
										color: [255,255,255],
										zIndex: 2,
										html: "legibility <---> accuracy"});
	topMenu.newGeneric("horizontalSliderText", {	top: 50,
													left: 240,
													fontSize: 10,
													html: "Recognition"});
	topMenu.newGeneric("verticalSliderText", {		top: 70,
													left: 240,
													fontSize: 10,
													html: "Approval"});
	topMenu.newSlider("horizontalSlider", 11, 3,"sliderHandler();", {	top: 55,
																	left: 300,
																	width: 150,
																	height: 10});
	topMenu.newSlider("verticalSlider", 11, 3,"sliderHandler();", {	top: 75,
																	left: 300,
																	width: 150,
																	height: 10}); 																	
*/																		
 	//Hide/display login/logout buttons as appropriate	
	topMenu.loginToggle = function(state){
		if(state=='logout') {
			topMenu.agreed = true;
			topMenu.buttons['Log In'].setDisplay('none');
			topMenu.buttons['Log Out'].setDisplay('block');
			topMenu.buttons['My Account'].setDisplay('block');
		} else {
			topMenu.agreed = false;
			topMenu.buttons['Log Out'].setDisplay('none');
			topMenu.buttons['Log In'].setDisplay('block');
			topMenu.buttons['My Account'].setDisplay('none');
		}
	}

	if(browsers.readCookie('poolauth')) topMenu.loginToggle('logout');
	else topMenu.loginToggle('login');
	
	if(browsers.readCookie('agreed')) topMenu.agreed = true;
	
	//Set up login form submission.  Maybe move this to menuBar.js later
	topMenu.doLogin = function(formObj){
		//First make sure the fields are full
		if(formObj.login.value == '' || formObj.pass.value == ''){
			alert('Please type your name and password before trying to log in.');
			return false;
		}
		/* 
		for(var i = 0; i<formObj.length; i++){
			alert(formObj[i].value);
		} */
		
		//fields are full, run the ajax request
		var loginCallback = function(ajaxData){
			var loginResult = eval('('+ajaxData+')');
			if(loginResult.success == true){
				alert('Logged in as '+loginResult.written);
				singlePanelManager['loginPanel'].panelHandle.style.display = 'none';
				topMenu.loginToggle('logout');
		//		browsers.setCookie('PoolId', loginResult.id, 365);
			} else {
				alert('Login failed: incorrect name or password');
			}
		}
		
		var loginFormData = {	hr_id: 'per_'+formObj.login.value,
								password: formObj.pass.value }
		ajax.post(siteBaseDir+'ajaxHandlers/login_handler.js.php', loginFormData, loginCallback);
		
		return false;
	}
	
	topMenu.doLogout = function(){
		alert('Logged out');
		browsers.eraseCookie('poolauth');
		browsers.eraseCookie('poolid');
		browsers.eraseCookie('poollevel');
		topMenu.loginToggle('login');
	}
	
	topMenu.showAccount = function(){
		if(browsers.readCookie('poolid')){
			var person = new PersonFish(browsers.readCookie('poolid'), 'My Account');
			person.launchPanel();
		}
	}
}



function openFullScreen() {
    window.moveTo(0,0);
    window.resizeTo(screen.availWidth,screen.availHeight);
}

function sliderHandler(){
	workingBasin.setAccuracy(topMenu.sliders.x.sliderValue, topMenu.sliders.y.sliderValue, topMenu.sliders.z.sliderValue);
//	resetFishPlot({plotType: 'newPlot', accuracyHorizontal: topMenu.sliders.horizontalSlider.sliderValue, accuracyVertical: topMenu.sliders.verticalSlider.sliderValue})
}