/* Copyright (c) 2008 Extentech Inc. All Rights Reserved

##### Sheetster&trade; Web Application #####

This file is a part of the Sheetster&trade; Web Application

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

If you would like to redistribute this software in a closed-source application,
dual-licensed commercial versions are available from Extentech.

For a fully supported and redistributable commercial license, 
please visit www.extentech.com or contact us at:

 sales@extentech.com
 Extentech Inc.
 1032 Irving Street #910
 San Francisco, CA 94122
 415-759-5292
 
*/
/**
	ribbonManager is a javascript prototype class that manages
	simple modification of the edit ribbon.  Show/Hide labels, show/hide
	edit functions, etc
	
	@class ribbonManager manages modifications to the edit ribbon
*/
ribbonManager = Class.create();
ribbonManager.prototype = {

	/**
		constructor
	**/
	initialize: function(){
	},
	
	/**
		late binding of events, needs to occur after dom is loaded.
	**/
	init: function(){
		$('edit_menu').observe('mousedown', this.popDialog.bind(this));
		$('edit_menu').observe('contextmenu', function(e){
    		e.stop();
		});
		
		try{
			$('showLabels').observe('mousedown', this.toggleLabels);
		}catch(e){;}
		
		try{
			$('showClipboard').observe('mousedown', this.toggleClipboard);
		}catch(e){;}
		
		try{
			$('showFont').observe('mousedown', this.toggleFont);
		}catch(e){;}
		
		try{
			$('showAlignment').observe('mousedown', this.toggleAlignment);
		}catch(e){;}
		
		try{
			$('showNumber').observe('mousedown', this.toggleNumber);
		}catch(e){;}
		
		try{
			$('showData').observe('mousedown', this.toggleData);
		}catch(e){;}
		
		try{
			$('showObjects').observe('mousedown', this.toggleObjects);
		}catch(e){;}
		
		try{
			$('ribbondialog').hide();
		}catch(e){;}
		
		try{
			$('ribbondialog').observe('contextmenu', function(e){
	    		e.stop();
			});
		}catch(e){;}
		
	},
	
	falsefunc: function() { return false; }, // used to block cascading events
	
	/**
		show or hide labels based on form inputs
	**/
	toggleLabels: function(){
		var labelRule = toolkit.getExternalRule('.editLabel');
		if($F('showLabels')=='1'){
			toolkit.setExternalRule(labelRule, {display: 'none'});
		}else{
			toolkit.setExternalRule(labelRule, {display: 'block'});
		}
	},
	
	/**
		show or hide clipboard based on form inputs
	**/
	toggleClipboard: function(){
		if($F('showClipboard')=='1'){
			$('clipboardMenu').hide();
		}else{
			$('clipboardMenu').show();
		}
	},
	
	/**
		show or hide font based on form inputs
	**/
	toggleFont: function(){
		if($F('showFont')=='1'){
			$('fontMenu').hide();
		}else{
			$('fontMenu').show();
		}
	},
	
	/**
		show or hide alignment based on form inputs
	**/
	toggleAlignment: function(){
		if($F('showAlignment')=='1'){
			$('alignmentMenu').hide();
		}else{
			$('alignmentMenu').show();
		}
	},
	
		/**
		show or hide number based on form inputs
	**/
	toggleNumber: function(){
		if($F('showNumber')=='1'){
			$('numberMenu').hide();
		}else{
			$('numberMenu').show();
		}
	},
	
		/**
		show or hide data based on form inputs
	**/
	toggleData: function(){
		if($F('showData')=='1'){
			$('dataMenu').hide();
		}else{
			$('dataMenu').show();
		}
	},
	
		/**
		show or hide objects based on form inputs
	**/
	toggleObjects: function(){
		if($F('showObjects')=='1'){
			$('objectMenu').hide();
		}else{
			$('objectMenu').show();
		}
	},
	
	/**
		Pops the ribbon manager div up, pass an event for location.
		
		Checks the event type.  Right click opens, left click closes.
	**/ 
	popDialog: function(evt){
		if (evt==null)evt=window.event;
		evt = Event.extend(evt);
		var theDialog = $('ribbondialog');
		if(!evt.isLeftClick()){
			theDialog.setStyle({
				top: evt.pointerY() + 'px',
				left: evt.pointerX() + 'px'
			});		
			try{
				theDialog.show();
			}catch(e){;}
			return false;
		}else{
			try{
				theDialog.hide();
			}catch(e){;}
			return true;
		}		
	}
	  	
}
