Ext.ns("Util");
Ext.ns("Tools");
/*
Dynamic ajax accordion (OXX 2009)

2Do: 
-Get dynamic height of expansion for elements
-Set width of accordion according to parent(content, leftbar or rightbar)
-?

OXX.Accordion = Ext.extend(Object, {

    constructor: function() {

    },

    futureHeight: {},

    init: function() {

        var rootEl = Ext.get('accordion');
        var bodyEls = rootEl.select('div.inner-body');
        bodyEls.each(function(item, i) {
            var el = item.load({
                url: 'DocumentJSON.aspx?did=' + item.dom.id.replace('document_', ''),
                method: 'get',
                callback: function() {
                    // console.log('here we go again....');
                }
            });

        }, this);

        Ext.select('.body').setHeight(1);

        rootEl.on('click', function(evt, el) {
            Ext.select('.expand').each(function(el, th, index) {
                Ext.fly(el).toggleClass('expand');
                Ext.fly(el).down('.body').setHeight(1, {
                    duration: 1.4, callback: function() {
                        OXX.Application.resizeLayout();
                    }
                });
            });


            //La til 10 for å kompansere for padding
            var targetHeight = (Ext.fly(el).parent('.expand') == null) ? Ext.fly(el).parent('.container').down('.body .inner-body').getHeight() + 5 : 1;

            Ext.fly(el).parent('.container').toggleClass('expand');

            Ext.fly(el).parent('.container').down('.body').setHeight(targetHeight, {
                duration: 1.4, callback: function() {
                    OXX.Application.resizeLayout();
                }
            });



        }, this, { delegate: '.icon' });
    }
});
*/






Tools.decorateLeftmenu = function() {	
	/* 
    */	
	Ext.select('.leftbar .level-1').hover(function(el) { 
		Util.log(this);	
		Ext.fly(this).replaceClass('level-1', 'level-1-active');
	},	function(el) { 
		Ext.fly(this).replaceClass('level-1-active', 'level-1');				 
	});
	
	Ext.select('.leftbar .level-2').hover(function(el) { 
		Util.log(this);	
		Ext.fly(this).replaceClass('level-2', 'level-2-active');
	},	function(el) { 
		Ext.fly(this).replaceClass('level-2-active', 'level-2');				 
	});

	
};


Tools.applyEvents = function() {		
	/* All elements with class hover will implement this 
    */
        Ext.select('.hover').on('mouseover', function(e, t) {
            Ext.get(t).setStyle('cursor', Ext.isIE ? 'hand' : 'pointer');
        }, this);
		
	Ext.select('.boxclick').on('click', function(el) {
		document.location.href  = Ext.fly(this).dom.id;	
	});

}



Ext.onReady(function() {

	if (Ext.isFirefox)
		Util.log = console.log;
	else
		Util.log = function(){};
	
	
	Tools.decorateLeftmenu();
	Tools.applyEvents();

});
