// JavaScript Document
$(document).ready(function() {
						 
	/* empty the lpassword field */
	$('#pwd').val("");

	/* hide the sub-navigation */
	$('#sidebar .nav li ul').hide();
	
	/* add class "sub" to all the lists that have sub-navigation */
  	$('.nav li:has(ul)').find('a:first').addClass('sub');
	
	/* function to handle slide-ins and slide-outs of the sub-navigation */
  $('#sidebar .nav li').click(
  		function() {
				var li_sub = $(this).children("ul");
				if ( li_sub.length == 0)
					return; /* it's either top-level list without sub or one of the sub-menues */
				var open_class = li_sub.attr("class"); /* check if this is currently opened submenu */
				if (open_class != "open")  {
					/* this one is not currently opened, first close any opened ones */
					$('.nav li:has(ul)').children("ul").removeClass("open").slideUp(500);
					$(this).children("ul").slideDown(500).addClass("open");
					return false; /* don't process click */
					}
				else
					return; /* don't do anything if it currently opened */
				});
	
	
	/* for sidebar .bigLink box */			
	 var target = '.bigLink';
  	 var hoverClass = 'hoverBigLink';

  	$(target).each(function() {
		$(this).hover(
      		function() {
         		$(this).addClass(hoverClass);
         		status=$(this).find('a').attr('href'); /* status is a global var */
      		},
      		function () {
         		$(this).removeClass(hoverClass);
      		}); /* end hover */

    	$(this).click(function() { /* click on specials box */
       		location = $(this).find('a').attr('href'); /* go to specials page */
    	}); /* end of click functions */

    	$(this).css('cursor','pointer'); /* turn cursor to poiter */
		}); /* end of each function */


	/******* password tooltip **********/
	$('input.tip').cluetip( {
			splitTitle: '|',
			/*arrows:true,*/
			width: 300,
			fx: {
				open:'fadeIn',
				openSpeed: 500
				}
	});			
	
	/* password process form **************/
	var ngma_pwd ="";
	var security_level = 0; /* default security level for non-students */
	var belt_name = "";
	var pwd_array = [
							['white', 'white'], ['yellow', 'yellow'], ['orange', 'orange'], ['purple', 'purple'],
							['purple1', 'purple with stripe'], ['blue', 'blue'], ['blue1', 'blue with stripe'], ['green', 'green'],
							['green1', 'green with stripe'], ['green2', 'green with 2 stripes'], 
							['brown', 'brown'], ['brown1', 'brown with stripe'],
						    ['brown2', 'brown with 2 stripes'], ['brown3', 'brown with 3 stripes'],
							['black', 'black']
							];
		/* On password submit form */
//		$('#login_form').submit(function(){
//    	
//			ngma_pwd=$('#pwd').val();
//			if (ngma_pwd == '') /* empty password -> default security */
//				{
//					security_level = 0;
//					$('#view_level #level').text(' public');
//					return false; 
//				}
//			/* check the password against store values */
//			var found = 0;
//			for (var i = 0; i<pwd_array.length; i++)
//				{
//					if (pwd_array[i][0] == ngma_pwd) /* found match */
//						{
//							security_level = i + 1; /* one more then index */
//							belt_name = pwd_array[i][1];
//							/*alert('Your secutity is: ' + security_level + 'belt: ' + belt_name);*/
//							found = 1;
//							$('#view_level #level').text(belt_name + ' belt');
//							break;
//						} 
//				}
//			if (!found) {
//				alert ('No matching password found. You will not be able to view password-protected data.');
//				$('#view_level #level').text(' public');
//			}
//   		return false;  
//   			}); /* end of submit */
		
}); /* end of ready */