/*
 * Main Controller Classes for JS Framework
 * Uses the very nice - Mootools Framework
 * @Author Andy Johnston (andy [at] parca [dot] com [dot] au)
 * @Updated July 2007
 *  
 * Sets up base controlling class, and view controller class.
 * Extend at view level to implement controller like so :
 
	<script>
	var View = {
		controller: null,
		init: function(){
			// Here we are overriding some properties for the tooltip module in this view
			this.controller = new ViewController({
				tooltipProps : {
					maxTitleChars : 50,
				}
			});		
			// Example of calling controller methods on setup
			this.controller.setupTips();
		},
	}
	// Fires the init super chain on Dom Ready event
	window.onDomReady(View.init.bind(View));	
	</script>

 * 
 */

var Controller = new Class({

	/* Public Properties */

	options: {
		codeName : "Controller Class",
		accordionProps : {
			id : "dl.Accordion",
			toggleClass : "dt.acc_toggle",
			elements : "dd.acc_content",
			show : 0
		},
		tooltipProps : {
			tipClass : ".hasTip",
			timeOut : 500,
			maxTitleChars : 50,
			maxOpacity : 0.9
		}
	},
	
	/* Constructor */

    initialize: function(options){
	    this.setOptions(options);
    },
    
   	/* Public setupAccordions - activate all accordions in the view */
    
    setupAccordions: function(){		
    	props = this.options.accordionProps;

		$$(props.id).each(function(el){
			new Accordion(el.getElements(props.toggleClass), el.getElements(props.elements),{
                show: props.show
            } );
		});
	},		
	
	
	
	/* Public setupTips - activate all tips in the view */
	
	setupTips: function(){
		props = this.options.tooltipProps;
		
		var myTips = new Tips($$(props.tipClass), {
			timeOut: props.timeOut,
			maxTitleChars: props.maxTitleChars,
			maxOpacity: props.maxOpacity
		});
	}
	
});

Controller.implement(new Events);
Controller.implement(new Options);

var ViewController = Controller.extend({
	options: {
		codeName : "View Controller Class"
	},
	initialize: function(options){
		this.parent(options);
	}
});




