$( document ).ready( function(){
	$.extend( {
		CcClickMenu: function( elm ){
			var container = $( elm );

			$( 'li', container ).css( {
				'float':'left',
				'position': 'relative'
			} );

			$( 'li > a', container ).css( {
				'display':'block',
				'width': '100%'
			} );

			$( 'li:first-child', container ).addClass( 'first-child' );
			$( 'li:last-child', container ).addClass( 'last-child' );

			$( 'ul li', container ).css( {
				'float': 'none',
				'width': 'auto',
				'height': 'auto'
			} );

			$( 'ul:visible', container ).hide();

			$( 'li:has(ul)', container ).each( function(){ 
				$( this ).css( 'cursor', 'pointer' );
				$( 'ul', this ).before( '▼' );
				$( 'ul', this ).css( {
					'position': 'absolute',
					'cursor': 'pointer'
				} );
				$( this ).click( function( e ){
					if( !$( 'ul', this ).hasClass( 'active' ) ){
						$( 'ul:visible', container ).removeClass( 'active' );
						$( 'ul:visible', container ).slideUp( 100 );
						$( 'ul', this ).addClass( 'active' );
						$( 'ul', this ).slideDown( 200 );
						e.stopPropagation();
					}
				} );
			} );

			$( 'body' ).click( function( e ){
				$( 'ul:visible', container ).removeClass( 'active' );
				$( 'ul:visible', container ).slideUp( 100 );
			});

		}
	} );
} );

