__log = function(text){
		try{
		console.log(text);
	}catch(err){}
};

l = function(text){
	__log(text);
};

$( function() {
	
	/*
	 * $( '.category' ).click( function() { __log($( this )); $( this
	 * ).toggleClass( 'active' ) $( this ).siblings( '.dropdown' ).toggle(); $(
	 * this ).find( '.indicator' ).toggleClass( 'indicator-active' ); return
	 * false; } );
	 */			
	$( '#dock > li' ).hover( function() {
		// $( '.latest' ).fadeOut( 'fast' );
		$( this ).addClass( 'dock-active' );
		// $( this ).children( 'span' ).fadeIn( 200 );
	}).bind( "mouseleave", function() {		
		$( this ).removeClass( 'dock-active' );	
		// $( this ).children( 'span' ).fadeOut( 200 );
	} );
			
	$( '#dock' ).bind( "mouseleave", function() {
		$( '.latest' ).fadeIn( 1000 );
	} );
  
} );



Ext.onReady(function(){

Ext.namespace("panoropia");
	
Ext.Array.each(Ext.query("div.category-menu div.menuCtn"),function(htmlNode, index, htmlNodes){
	
	var catCtn = Ext.get(htmlNode);
	
	Ext.get(catCtn.query(".btn")).on({
		click:{
			fn: function(evt, self, eOpts){
				
				var ctn = eOpts.options.parent;
				var showDD = false;
				if(!Ext.get(ctn.query(".category")[0]).hasCls("active")){
					showDD = true;
				};
				
				Ext.Array.each(eOpts.options.allParents,function(n){
					panoropia.hideDropDown(Ext.get(n));
				});

				if(showDD){
					panoropia.showDropDown(ctn);
				}
				
			},
			options :{
				parent: catCtn,
				allParents: htmlNodes
			}
		}
	});

});
	
	panoropia.showDropDown = function(ctn){
		Ext.get(ctn.query(".category")[0]).addCls("active");
		Ext.get(ctn.query(".indicator")[0]).addCls("indicator-active");
		var ddown = Ext.get(ctn.query(".dropdown")[0]);
		ddown.setLeft(-344+Ext.get(ctn.query(".btn")[0]).getWidth());
		ddown.setVisible(true);
	};
	
	panoropia.hideDropDown = function(ctn){
		Ext.get(ctn.query(".category")[0]).removeCls("active");
		Ext.get(ctn.query(".indicator")[0]).removeCls("indicator-active");
		var ddown = Ext.get(ctn.query(".dropdown")[0]).setVisible(false);
	};
	
});




			




