
/*!
 * jQuery UI Widget-factory plugin boilerplate (for 1.8/9+)
 * Author: @addyosmani
 * Further changes: @peolanha
 * Licensed under the MIT license
 *http://jqueryui.com/demos/widget/
 TIMER
 http://bililite.com/blog/extending-jquery-ui-widgets/ GUTE ADDRESSE
 */



;(function ( $, window, document, undefined ) {
 

/*  ! ... CE.SLIDE ........................................................................................ (Bookmark for Coda)  */    
    $.widget( "CE.SLIDE" , {
	
        //Options to be used as defaults
        options: { 
                ElementID: '',
                TableID:'Probe',
                last_change_number:0,
                ObjName: 'Dataelement',
                maxHeight:1000,
                minHeight:500,
                maxWidth:1000,
                minWidth:350,
                standardHeight:800,
                standardWidth:900,
                isMinimized: false,
                isMaxView: false,
                MaxView_enabled: false,
                Minimzed_enabled: false,
                useDbClick: false
        },
        _create: function () {},
        _init: function(){

        	var w=this; var e=w.element; var o=w.options;
        	
        	e.addClass('CE-SLIDE'); 
        	e.append('<div class="CE-SLIDE-Content"></div>');   
        	e.resizable({animate: false, maxHeight: o.maxHeight, maxWidth: o.maxWidth, minHeight: o.minHeight, minWidth: o.minWidth});			
			e.animate({width: o.standardWidth+'px',height: o.standardHeight+'px'  }, 'fast');

			e.append('<div class="CE-SLIDE-ToogleViewButton CE-Button"></div>');
			e.find('.CE-SLIDE-ToogleViewButton').click(function()
			{
				 w.toogleView();
			});
			
			if(!o.Minimzed_enabled) e.find('.CE-SLIDE-ToogleViewButton').fadeOut();
			
			e.dblclick(function()
			{
				 if(o.useDbClick) w.toogleMaxView();
			});
			
			$(window).resize(function() {
  				if(o.isMaxView) w.toogleMaxView(true);
			});	
			
			if(o.isMaxView) w.toogleMaxView(true);
        },
        destroy: function () { $.Widget.prototype.destroy.call(this); },
        
        setOption: function ( key, value, animate, commitToDatabase ) {
        	var w=this; var e=w.element; var o=w.options;
        	
        	if(key!=null && key!=undefined)
            {
            	debug(o.ElementID+' setValue '+key+' = '+value,false, o.debug_it);
            	switch (key) 
            	{        	
            		default:
               	 		o.key = value;
               	 		//e.attr(key, value);
               	 		if(commitToDatabase) w.commitDataToDatatables(key, value, CountToTrigger, TriggerTimeInMS, IsImportantChange);   
                		break;
           		}
            }
            $.Widget.prototype._setOption.apply( this, arguments );
        },
        toogleView: function(maximize_it)
        {
        	var w=this; var e=w.element; var o=w.options;
        	
        	if(o.Minimzed_enabled)
        	{
        	
        		if(maximize_it==true || (o.isMinimized && maximize_it!=false))
        		{
        			debug('maximized it', true, o.debug_it);
        			e.find('.CE-SLIDE-Content').fadeIn('fast');
        			e.find('.ui-resizable-handle').fadeIn('fast');         		     		
        			e.animate({height:o.standardHeight+'px'});
        		
        			o.isMinimized=false;
        		}else 
        		{
        			debug('minimize it', true, o.debug_it);
        			e.find('.CE-SLIDE-Content').fadeOut('fast');
        			e.find('.ui-resizable-handle').fadeOut('fast');  
        			e.animate({height:40+'px'});
        			o.isMinimized=true;
        			return false;
        	
        		}
        	}
        },
        toogleMaxView: function(maximize_it)
        {
        	
        	var w=this; var e=w.element; var o=w.options;
        	
        	if(o.MaxView_enabled)
        	{
        		if(maximize_it==true || (!o.isMaxView && maximize_it!=false))
        		{
        			debug('maximized MAX it', false, o.debug_it);
        		
        			var window_width=($(document).width()-80);     		
        			e.animate({width:window_width+'px'});
        		
        			o.isMaxView=true;
        		}else 
        		{
        			debug('minimize MAX it', false, o.debug_it);
        			e.animate({width:(o.standardWidth-80)+'px'});
        			o.isMaxView=false;
        		}
        	}       	
        }
    });
	


})( jQuery, window, document );
