
/**
 *
 * The Toolbar object is used to maintain information about a group of button widgets
 *
 * @constructor
 */

function Toolbar( id ) {

  this.id = id;
  this.buttons = new Array();
  this.button_selected = -1;
  this.button_focus = -1;

}  //end Toolbar

/**
 * init is a subclass of Toolbar and is used to initialize the event handlers 
 *
 * @member Toolbar
 *
 * @return none
 */

Toolbar.prototype.init = function() {
  
  var obj = this;
  this.node = document.getElementById(this.id);
  
  // Initialize Buttons
  for(var i = 0; i < this.buttons.length; i++ ) {
  this.buttons[i].init();
  } // end for 
  
  // Check to see if any buttons are selected in the toolbar from markup
  for(var i = 0; i < this.buttons.length; i++ ) {

	  this.buttons[i].node.className="unpressed";
	  
	  if( this.buttons[i].node.getAttribute("aria-pressed") =="true") {
	  selectButton( this, i, false );
	  }
	  
  } // endfor  
   
  // Add event handlers for first and last buttons to emulate IE button behavior for TAB navigation
  browser.addEvent(this.buttons[0].node, "focus", function(event) {handleButtonFirstFocus(event, obj);}, false); 
  browser.addEvent(this.buttons[0].node, "blur", function(event) {handleButtonFirstBlur(event, obj);}, false); 
  browser.addEvent(this.buttons[this.buttons.length-1].node, "focus", function(event) {handleButtonLastFocus(event, obj);}, false); 
  browser.addEvent(this.buttons[this.buttons.length-1].node, "blur", function(event) {handleButtonLastBlur(event, obj);}, false); 
    
  // Add event handlers for selecting a button
  browser.addEvent(this.node, "keydown", function(event) {handleToolbarKeyDownEvent(event, obj);}, false);

} // end Toolbar.prototype.init

/**
 * add is a subclass of Toolbar and adds a Button object to the Toolbar list
 *
 * @member Toolbar
 *
 * @param ( Button object ) obj button to be added to button list
 *
 * @return none
 */
 
Toolbar.prototype.add = function( obj ) {

  this.buttons[this.buttons.length] = obj;

} // end Toolbar.prototype.add

/**
 * selectButton is called by event handlers to select one of the buttons in a toolbar
 *
 * @param ( Toolbar object ) toolbar  Toolbar to change selected button
 * @param ( integer ) index Index of button to be selected
 * @param ( integer ) focus_flag If value is set to 1 then keyboard focus will be moved to the selected button
 *
 * @return none
 */
 
function selectButton( toolbar, index, focus_flag ) {

  // Check to see if index is larger than the number of buttons, if so wrap to first button
  
  if( index >= toolbar.buttons.length )
    index = 0;

  // Check to see if index is less than zero, if so wrap to last button
  
  if( index < 0)
    index = toolbar.buttons.length - 1;

  // Check to make sure the index value is valid before changin states

  if( (index >= 0 ) && (index < toolbar.buttons.length) ) {

    // Set all buttons to not selected
    // CSS selectors based on the "pressed" attribute value change the visual rendering
    // The pressed attribute is used communicate button state information to assitive technologies
    // Tabindex is set to -1 so the control can still receive focus, but is removed from tab order

    for(var i = 0; i < toolbar.buttons.length; i++ ) {
	      toolbar.buttons[i].node.tabIndex = -1;
    }  // endfor

    // Set radio button based on the index value
    // CSS selectors based on the "pressed" attribute change the visual rendering
    // The pressed attribute is used communicate radio button state information to assitive technologies
    // Tabindex is set to 0 so the control is added to tab order
	
    
    toolbar.buttons[index].node.tabIndex = 0;
	toolbar.buttons[index].node.className="pressed";
	
	// Check focus flag to see if keyboard focus should be moved to selected control
	if( focus_flag ) {
      toolbar.buttons[index].node.focus();
	}  // endif
	
	toolbar.button_focus = index;

    // Keep track of the last button selected
    
    toolbar.button_selected = index;

  } // endif
	
} // end selectButton

/**
 * Button Object
 *
 * @param ( id ) id of text to style
 * 
 * @return none
 */

function Button( id ) {

   this.id = id;
   
} // end Button

/**
 * Button Object
 *
 * @param ( id ) id of text to style
 *
 * @return none
 */

Button.prototype.init = function() {

  this.node = document.getElementById(this.id);
   
  var obj = this; 
  
  // Add event handlers for pressing a button
  browser.addEvent(this.node, "keydown", function(event) {handleButtonKeyDownEvent(event, obj);}, false);
  browser.addEvent(this.node, "keyup",   function(event) {handleButtonKeyUpEvent(event, obj); },  false);
  
  browser.addEvent(this.node, "mousedown", function(event) {handleButtonMouseDownEvent(event, obj);}, false);
  browser.addEvent(this.node, "mouseup",   function(event) {handleButtonMouseUpEvent(event, obj); },  false);

  // Add event handlers for a button geeting and losing focus
  browser.addEvent(this.node, "focus", function(event) {handleButtonFocusEvent(event, obj);}, false);
  browser.addEvent(this.node, "blur",  function(event) {handleButtonBlurEvent(event, obj); }, false);
  

} // end Button.prototype.init



/**
 * handleButtonFocusEvent processes keys associated with a button
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Button object ) button is the Button object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by button, else true
 */

handleButtonFocusEvent = function(event, button) {
  if( button.node.getAttribute("aria-pressed") == "true" ) {
	//use the focus highlighting for a pressed button
	button.node.className = "focuspressed";
  } else {
	//use the focus highlighting for an unpressed button  
    button.node.className = "focusunpressed";
  } // endif

  return true;

} // end handleButtonFocusEvent

/**
 * handleButtonBlurEvent processes keys associated with a button
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Button object ) button is the Button object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by button, else true
 */

handleButtonBlurEvent = function(event, button) {

   if( button.node.getAttribute("aria-pressed") == "true" ) {
	//use the focus highlighting for a pressed button
	button.node.className = "pressed";
  } else {
	//use the focus highlighting for an unpressed button  
    button.node.className = "unpressed";
  } // endif

  return true;

} // end handleButtonBlurEvent

/**
 * handleButtonFirstFocus processes onFocus event when TAB has been pressed  
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Toolbar object ) toolbar is the Toolbar object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by toolbar, else true
 */
 

function handleButtonFirstFocus( event, toolbar ) {

  // check to see if any buttons are selected
  if( toolbar.button_selected < 0 ) {
	  
	// if a button is not selected, remove the last button to tab order  
    toolbar.buttons[toolbar.buttons.length-1].node.tabIndex = -1;

	// keep track of the last button with focus
	toolbar.button_focus = 0;
	
	//focus on first by adding the highlight
	if(toolbar.buttons[0].node.getAttribute("aria-pressed") == "true"){
	toolbar.buttons[0].node.className = "focuspressed";
	}else{
	toolbar.buttons[0].node.className = "focusunpressed";	
	}//endif
		  
  } // end if
  return true;

} // end handleButtonFirstFocus

/**
 * handleButtonFirstBlur processes onBlur event when TAB has been pressed  
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Toolbar object ) toolbar is the Toolbar object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by toolbar, else true
 */
 

function handleButtonFirstBlur( event, toolbar ) {

  // check to see if any buttons are selected
  if( toolbar.button_selected < 0 ) {
	  
	// if a button is not selected, add the last button to tab order  
    toolbar.buttons[toolbar.buttons.length-1].node.tabIndex = 0;
	
	//blur button
	if(toolbar.buttons[0].node.getAttribute("aria-pressed") == "true"){
	toolbar.buttons[0].node.className = "pressed";
	}else{
	toolbar.buttons[0].node.className = "unpressed";	
	}//endif
  } // end if
  
  return true;

} // end handleButtonFirstBlur

/**
 * handleButtonLastFocus processes onFocus event when SHIFT+TAB has been pressed  
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Toolbar object ) toolbar is the Toolbar object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by toolbar, else true
 */
 

function handleButtonLastFocus( event, toolbar ) {

  // check to see if any buttons are selected
  if( toolbar.button_selected < 0 ) {
	  
	// if a button is not selected, remove the first button to tab order  
    toolbar.buttons[0].node.tabIndex = -1;
		  
	// keep track of the last button with focus
	toolbar.button_focus = toolbar.buttons.length-1;
	
	//highlight the button that is in focus
	if(toolbar.buttons[toolbar.buttons.length-1].node.getAttribute("aria-pressed") == "true"){
	toolbar.buttons[toolbar.buttons.length-1].node.className = "focuspressed";
	}else{
	toolbar.buttons[toolbar.buttons.length-1].node.className = "focusunpressed";
	}//endif
		  
  } // end if
  
  return true;

} // end handleButtonLastFocus

/**
 * handleButtonLastBlur processes onBlur event when SHIFT+TAB has been pressed  
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Toolbar object ) toolbar is the Toolbar object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by toolbar, else true
 */
 

function handleButtonLastBlur( event, toolbar ) {

  // check to see if any buttons are selected
  if( toolbar.button_selected < 0 ) {
	  
	// if a button is not selected, then add the first button to tab order  
    toolbar.buttons[0].node.tabIndex = 0;
	
	//blur button
	if(toolbar.buttons[toolbar.buttons.length-1].node.getAttribute("aria-pressed") == "true"){
	toolbar.buttons[toolbar.buttons.length-1].node.className = "pressed";
	}else{
	toolbar.buttons[toolbar.buttons.length-1].node.className = "unpressed";	
	}//endif
		  
  } // end if
  
  return true;

} // end handleButtonLastBlur

/**
 * handleToolbarKeyDownEvent processes keys associated with a toolbar
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Toolbar object ) toolbar is the Toolbar object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by toolbar, else true
 */

function handleToolbarKeyDownEvent( event, toolbar ) {
	// If IE get the IE event object
	var e = event || window.event;
	
	// If any modifier keys are pressed do not process this event
	if( e.altKey || e.ctrlKey || e.shiftKey )
	  return true;

  switch( e.keyCode ) {
   
    case KEY_RIGHT:
	     // Hitting right will switch the focus and selected to the next item in the toolbar
         if( (toolbar.button_selected < 0 )  &&	 (toolbar.button_focus >= 0 ) ){
		   selectButton( toolbar, (toolbar.button_focus + 1), true);
		   toolbar.buttons[toolbar.button_focus ].node.className += ""; 
		 }
		   
         else	{
			 
           selectButton( toolbar, (toolbar.button_selected + 1), 1);
		   toolbar.buttons[toolbar.button_selected ].node.className += "";
		 }
		 // Tell browser we handled this event and not to process any other actions   
		 return browser.stopPropagation( e );
	     break;
	
	case KEY_LEFT:
	     // Hitting left will switch the focus and selected to the previous item in the toolbar
         if( (toolbar.button_selected < 0 )  &&	 (toolbar.button_focus >= 0 ) )
		   selectButton( toolbar, (toolbar.button_focus - 1), true);
		   
         else	
           selectButton( toolbar, (toolbar.button_selected - 1), true);
		 if(toolbar.buttons[toolbar.button_focus].node.getAttribute("aria-pressed") == "true"){
			
			toolbar.buttons[toolbar.button_focus].node.setAttribute("aria-pressed", "true")			
		 }
		 else
		 {
			toolbar.buttons[toolbar.button_focus].node.setAttribute("aria-pressed", "false")			
		 }
		 // Tell browser we handled this event and not to process any other actions    
		 return browser.stopPropagation( e );
	     break;
		 
	case KEY_SPACE:
	     // Hitting space will select the current item in the toolbar
         if( (toolbar.button_selected < 0 )  &&	 (toolbar.button_focus >= 0 ) ){
		   selectButton( toolbar, toolbar.button_focus, true);
		 }
		 
		 // Tell browser we handled this event and not to process any other actions    
		 return browser.stopPropagation( e );
	     break;	
  
  } // end switch
} //end handleToolbarKeyDownEvent

/**
 * handleButtonKeyDownEvent processes keys associated with a button
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Button object ) button is the Button object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by button, else true
 */

handleButtonKeyDownEvent = function(event, button) {
	// If IE get the IE event object
	var e = event || window.event;

  switch( browser.keyCode(e) ) {

    case KEY_SPACE:
	     // Tell assistive technologies that the button is currently pressed
	     button.node.setAttribute("aria-pressed", "true");
		 // Change the styling of the button to indicate it is pressed
         button.node.className = "focuspressed";
		 // Tell browser we handled this event and not to process any other actions
         return browser.stopPropagation(e);
         break;

  }  // end switch

  return true;

} // end handleButtonKeyDownEvent

/**
 * handleButtonKeyUpEvent processes keys associated with a button
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Button object ) button is the button object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by button, else true
 */

handleButtonKeyUpEvent = function(event, button) {
	// If IE get the IE event object
	var e = event || window.event;

  switch( browser.keyCode(e) ) {

    case KEY_SPACE:
	     // Tell assistive technologies that the button is not currently pressed
	     button.node.setAttribute("aria-pressed", "false");
	     button.node.className = "focusunpressed";
         browser.simulateOnClickEvent( button.node );
		 // Tell browser we handled this event and not to process any other actions
         return browser.stopPropagation(e);
         break;

  }  // end switch

  return true;

} // end handleButtonKeyUpEvent

/**
 * handleButtonMouseDownEvent processes keys associated with a button
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Button object ) button is the Button object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by button, else true
 */

handleButtonMouseDownEvent = function(event, button) {
	// If IE get the IE event object
	var e = event || window.event;

  if( browser.target(e) == button.node ) {
	 // Tell assistive technologies that the button is currently pressed 
     button.node.setAttribute("aria-pressed", "true");
	 // Change the styling of the button to indicate it is pressed
     button.node.className = "focuspressed";
	 //set focus
	 button.node.focus();
	 // Tell browser we handled this event and not to process any other actions
    return browser.stopPropagation(e);

  }  // end if

  return true;

} // end handleButtonMouseDownEvent

/**
 * handleButtonMouseUpEvent processes keys associated with a button
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Button object ) button is the button object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by button, else true
 */

handleButtonMouseUpEvent = function(event, button) {
	// If IE get the IE event object
	var e = event || window.event;
  // Tell assistive technologies that the button is not currently pressed
  button.node.setAttribute("aria-pressed", "false");
  button.node.className = "focusunpressed";

  if( browser.target(e) == button.node ) {
	  
     browser.simulateOnClickEvent( button.node );
	 // Tell browser we handled this event and not to process any other actions
     return browser.stopPropagation(e);
		 
   }  // end if

  return true;

} // end handleButtonMouseUpEvent


/**
 * ButtonToggle Object
 *
 * @param ( id ) id of text to style
 *
 * @return none
 */

function ButtonToggle( id ) {

   this.id = id;
   
} // end ButtonToggle

/**
 * ButtonToggle Object
 *
 * @param ( id ) id of text to style
 *
 * @return none
 */

ButtonToggle.prototype.init = function() {

  this.node = document.getElementById(this.id);
   
  var obj = this; 
  
  // Add event handlers for toggling a button
  browser.addEvent(this.node, "keydown",   function(event) {handleButtonToggleKeyDownEvent(event, obj);},   false);
  browser.addEvent(this.node, "mousedown", function(event) {handleButtonToggleMouseDownEvent(event, obj);}, false);
  
  // Add event handlers for a button getting and losing focus
  browser.addEvent(this.node, "focus", function(event) {handleButtonFocusEvent(event, obj);}, false);
  browser.addEvent(this.node, "blur",  function(event) {handleButtonBlurEvent(event, obj); }, false);
  
} // end ButtonToggle.prototype.init

/**
 * toggleButton is called by event handlers to toggle the state of the button
 *
 * @param ( Button object ) button  Button to toggle state
 *
 * @return none
 */

toggleButton = function( button ) {

  if( button.node.getAttribute("aria-pressed") == "true" ) {

    // If the button is currently pressed set the state to not pressed	

    button.node.setAttribute("aria-pressed", "false");
    button.node.className = "focusunpressed";

  } else {

    // If the button is not currently pressed set the state to pressed	

    button.node.setAttribute("aria-pressed", "true");
    button.node.className = "focuspressed";

  }  // endif
  
  
} // end toggleButton

/**
 * handleButtonToggleKeyDownEvent processes keys associated with a button
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Button object ) button is the Button object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by radio group, else true
 */

handleButtonToggleKeyDownEvent = function(event, button) {
	// If IE get the IE event object
	var e = event || window.event;
 
  switch( browser.keyCode(e) ) {

    case KEY_SPACE:
	     // Toggle the button
         toggleButton( button );
         browser.simulateOnClickEvent( button.node );
	     // Tell browser we handled this event and not to process any other actions
         return browser.stopPropagation(e);
         break;

  }  // end switch

  return true;

} // end handleButtonToggleKeyDownEvent

/**
 * handleButtonToggleMouseDownEvent processes keys associated with a button
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Button object ) button is the button object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by button, else true
 */

handleButtonToggleMouseDownEvent = function(event, button) {
	// If IE get the IE event object
	var e = event || window.event;

  if( browser.target(e) == button.node ) {
	// Toggle button
    toggleButton( button );
    browser.simulateOnClickEvent( button.node );
	//set focus on mouse press
	button.node.focus();
	// Tell browser we handled this event and not to process any other actions
    return browser.stopPropagation(e);
  }  // end if

  return true;

} // end handleButtonToggleMouseDownEvent


/**
 * StateButton Object
 *
 * @param ( id ) id of text to style
 *
 * @return none
 */

function ButtonState( id ) {

   this.id = id;
   
} // end ButtonState

/**
 * ButtonState Object
 *
 * @param ( id ) id of text to style
 *
 * @return none
 */

ButtonState.prototype.init = function() {

  this.node = document.getElementById(this.id);
   
  var obj = this; 

  // Add event handlers for toggling a button state
  browser.addEvent(this.node, "keydown",   function(event) {handleButtonStateKeyDownEvent(event, obj); },   false);
  browser.addEvent(this.node, "mousedown", function(event) {handleButtonStateMouseDownEvent(event, obj); }, false);
  
  // Add event handlers for a ButtonState getting and losing focus
  browser.addEvent(this.node, "focus", function(event) {handleStateFocusEvent(event, obj);}, false);
  browser.addEvent(this.node, "blur", function(event) {handleStateBlurEvent(event, obj);}, false);


  
} // end ButtonState.prototype.init


/**
 * handleStateFocusEvent processes keys associated with a buttonstate
 *
 * @param ( event ) event is the event handler for the event
 * @param ( ButtonState object ) button_state is the ButtonState object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by button, else true
 */

handleStateFocusEvent = function(event, button) {
  if( button.node.getAttribute("aria-pressed") == "true" ) {
	//use the focus highlighting for a pressed button
	button.node.className = "focuspressed";
  } else {
	//use the focus highlighting for an unpressed button  
    button.node.className = "focusunpressed";
  } // endif

  return true;

} // end handleStateFocusEvent

/**
 * handleStateBlurEvent processes keys associated with a button_state
 *
 * @param ( event ) event is the event handler for the event
 * @param ( ButtonState object ) button_state is the ButtonState object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by button_state, else true
 */

handleStateBlurEvent = function(event, button) {

   if( button.node.getAttribute("aria-pressed") == "true" ) {
	//use the focus highlighting for a pressed button
	button.node.className = "pressed";
  } else {
	//use the focus highlighting for an unpressed button  
    button.node.className = "unpressed";
  } // endif

  return true;

} // end handleStateBlurEvent

/**
 * handleButtonStateKeyDownEvent processes keys associated with a button
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Button object ) button is the Button object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by radio group, else true
 */

handleButtonStateKeyDownEvent = function(event, button) {
	// If IE get the IE event object
	var e = event || window.event;

    switch( browser.keyCode(e)  ) {

    case KEY_SPACE:

     // press the button
     button.node.setAttribute("aria-pressed","true");
	 button.node.className = "focuspressed";
	 
	 browser.simulateOnClickEvent( button.node );
	     // Tell browser we handled this event and not to process any other actions
         return browser.stopPropagation(e);
         break;

  }  // end switch

  return true;

} // end handleButtonStateKeyDownEvent

/**
 * handleButtonStateMouseDownEvent processes keys associated with a button
 *
 * @param ( event ) event is the event handler for the event
 * @param ( Button object ) button is the button object that is the target of the keyboard event
 *
 * @return false if keyboard event was used by button, else true
 */

handleButtonStateMouseDownEvent = function(event, button) {
	// If IE get the IE event object
	var e = event || window.event;

  if( browser.target(e) == button.node ) {

      //press the button
      button.node.setAttribute("aria-pressed","true");
	  button.node.className = "focuspressed";
	 
	 //set focus on mouse press
	 button.node.focus();
	 // Tell browser we handled this event and not to process any other actions
     return browser.stopPropagation(e);
		 
  }  // end if

  return true;

} // end handleButtonStateMouseDownEvent



/**
 * StyledText Object
 *
 * @param ( id ) id of text to style
 *
 * @return none
 */

function StyledText( id ) {

   this.id = id;
   
   this.fontSize = 3;
   this.fontSizes = ['85%', '90%', '95%', '100%', '105%', '110%', '120%', '140%', '180%'];
  
} // end StyledText

/**
 * init is a subclass of StyledText
 * tabs in a menu bar.
 * 
 * @member StyleText
 *
 * @return none
 */
 
StyledText.prototype.init = function() {

  this.node = document.getElementById(this.id);
  
} // end StyledText.prototype.init

/**
 * handleStyledTextFontSize
 *
 * @param ( StyledText object) styled text to have its font changed
 * @param ( integer ) size index of font desired size
 *
 * @return none
 */

function handleStyledTextFontSize( stext, size ) {

  // Make sure that size is no less than 0
  if( size < 0 )
     size = 0;
  // Make sure we access a valid element	 
  if( size >= stext.fontSizes.length )
    size = stext.fontSizes.length -1;
  // Set our fontSize to size
  stext.fontSize = size;
  // Use the corresponding fontSize among the fontSizes
  stext.node.style.fontSize = stext.fontSizes[stext.fontSize];

} // end handleStyledTextFontSize

/**
 * handleStyledTextFontSizeLarger
 * handlers changing 
 *
 * @param ( StyledText object) styled text to have its font changed
 *
 * @return none
 */

function handleStyledTextFontSizeLarger( stext ) {
  // Increment fontSize
  stext.fontSize++;
  // Make sure we access valid elements
  if( stext.fontSize >= stext.fontSizes.length )
    stext.fontSize = stext.fontSizes.length - 1;
  // Use the corresponding fontSize among the fontSizes
  stext.node.style.fontSize = stext.fontSizes[stext.fontSize];
	
} // end handleStyledTextFontSizeLarger

/**
 * handleStyledTextFontSizeSmaller
 *
 * @param ( StyledText object) styled text to have its font changed
 *
 * @return none
 */

function handleStyledTextFontSizeSmaller( stext ) {
  // Decrement fontSize
  stext.fontSize--;
  // Make sure that it doesn't go below 0
  if( stext.fontSize < 0 )
    stext.fontSize = 0;
  // Use the corresponding fontSize among the fontSizes
  stext.node.style.fontSize = stext.fontSizes[stext.fontSize];
	
} // end handleStyledTextFontSizeSmaller

function handleTextAlignLeft(stext, toolbar, button){
	
	stext.node.style.textAlign = "left";
	
	//unpress all of the other state buttons
	for(var i = 0; i < toolbar.buttons.length; i++ ) {
    toolbar.buttons[i].node.setAttribute("aria-pressed", "false");
    toolbar.buttons[i].node.className="unpressed";
	}
    
	 //press the button
      button.node.setAttribute("aria-pressed","true");
      button.node.className="focuspressed";

}

function handleTextAlignCenter(stext, toolbar, button){
    
	stext.node.style.textAlign = "center";

	//unpress all of the other state buttons
	for(var i = 0; i < toolbar.buttons.length; i++ ) {
    toolbar.buttons[i].node.setAttribute("aria-pressed", "false"); 
    toolbar.buttons[i].node.className="unpressed";
	}
	 
	 //press the button
      button.node.setAttribute("aria-pressed","true");
      button.node.className="focuspressed";

	  
}

function handleTextAlignRight(stext, toolbar, button){
    
	stext.node.style.textAlign = "right";

	//unpress all of the other state buttons
	for(var i = 0; i < toolbar.buttons.length; i++ ) {
    toolbar.buttons[i].node.setAttribute("aria-pressed", "false"); 
    toolbar.buttons[i].node.className="unpressed";
    }
	
	 //press the button
      button.node.setAttribute("aria-pressed","true");
      button.node.className="focuspressed";

}

function handleTextAlignJustify(stext, toolbar, button){
    
	stext.node.style.textAlign = "justify";
	
	//unpress all of the other state buttons
	for(var i = 0; i < toolbar.buttons.length; i++ ) {
    toolbar.buttons[i].node.setAttribute("aria-pressed", "false"); 
    toolbar.buttons[i].node.className="unpressed";
	}	 
	 
	 //press the button
      button.node.setAttribute("aria-pressed","true");
      button.node.className="focuspressed";

}

/**
 * handleStyledTextToggleBold
 * handlers changing 
 *
 * @param ( MenuBar object) styled text to have its font changed
 * @param ( StyledText object) styled text to have its font changed
 *
 * @return none
 */

function handleStyledTextToggleBold( button, stext ) {
  
  if( button.node.getAttribute("aria-pressed") == "true" ) {
	// If button is pressed set text to bold
    stext.node.style.fontWeight = "bold";
  } else {
    // If button is not pressed set text to normal
    stext.node.style.fontWeight = "normal";
  } // endif
	
} // end handleStyledTextToggleBold

/**
 * handleStyledTextToggleItalic
 * handlers changing 
 *
 * @param ( MenuBar object) styled text to hav its font changed
 * @param ( StyledText object) styled text to have its font changed
 *
 * @return none
 */

function handleStyledTextToggleItalic( button, stext ) {
  
  if( button.node.getAttribute("aria-pressed") == "true" ) {
	// If button is pressed set text to italic
    stext.node.style.fontStyle = "italic";
  } else {
	// If button is not pressed set text to normal
    stext.node.style.fontStyle = "normal";
  } // endif
	
} // end handleStyledTextToggleItalic



