jQuery.fn.pixartSection=function(opt){
  
	var open = false;
	if(opt==null)var opt={};
  
   if(opt.func == 'init'){
	   this.each(function(){
		    if($(this).data('pixart-section-init')!=null && $(this).data('init'))return;
		    $(this).data('pixart-section-init',true);
	   		$(this).addClass('pixart-section');
	   		
	   		/* set TOP */
		    var icon = $('<div class="expander pixart-ui-icon pixart-ui-icon-plus-gray"  ></div>');
		    
		    var text = $(this).children('.top').html();
		    var color = $(this).children('.top').css('color');
		    
		    
		    $(this).children('.top').prepend(icon);
		    
		    if(opt.topStyle!=null)$(this).children('.top').css(opt.topStyle);
		    
		    icon.attr('title','massimizza');
		    
		    if(!$(this).children('.body').is(':visible') && $(this).is(':visible') ){
		        $(this).children('.top').addClass('top-closed');
		    }else{
		        icon.removeClass('pixart-ui-icon-plus-gray').addClass('pixart-ui-icon-minus-gray');
		        icon.attr('title','minimizza');
		    } 
		    
		    
		    
		    if(opt.bodyStyle!=null)$(this).children('.body').css(opt.bodyStyle);
		    
		    
		    
	   });

   }
  
  if(opt.func == 'slideUp'){
	  this.each(function(){
		  
		  var top = $(this);
		  if($(this).hasClass("noSlide"))$(this).parent().children('.body').hide();
		  else $(this).parent().children('.body').slideUp('',function(){ top.addClass('top-closed'); });

		  
		  $(this).parent().height('auto');
		  
		  $(this).children('.expander').attr('title','massimizza');
		  $(this).children('.expander').removeClass('pixart-ui-icon-minus-gray').addClass('pixart-ui-icon-plus-gray');
		  
		  
		  //evento associato
		  var event = $(this).parent().attr('close');
		  if(event != null)
			  	eval(  event.replace("$(this)","$(this).parents('.pixartSection:first')") );
	  });

  }
  
  if(opt.func == 'slideDown'){
	  this.each(function(){
		  if($(this).hasClass("noSlide"))$(this).parent().children('.body').show();
		  else $(this).parent().children('.body').slideDown();
		  $(this).children('.expander').attr('title','minimizza');
		  $(this).children('.expander').removeClass('pixart-ui-icon-plus-gray').addClass('pixart-ui-icon-minus-gray');
		  $(this).removeClass('top-closed');
		  
		  
		  $(this).parent().height('auto');
		 //evento associato
		  var event = $(this).parent().attr('open');
		  if(event != null)
			  	eval(  event.replace("$(this)","$(this).parents('.pixartSection:first')") );
		  
		  
	  });
  }
   
  if(opt.func == 'slide'){
	  this.each(function(){
	      if($(this).parent().children('.body').is(':visible'))$(this).pixartSection({func : 'slideUp'});
	      else $(this).pixartSection({func : 'slideDown'});
	  });
  }
 
  if(opt.func == null){
	  this.each(function(){

		  if($(this).data('pixart-section-init'))return;
		  $(this).pixartSection({func : 'init'});
		  if($(this).hasClass('locked'))return;
		  if($(this).hasClass('hover')){
			  $(this).hover( function(){ $(this).children('.top').pixartSection({func : 'slideDown'})}, function(){$(this).children('.top').pixartSection({func : 'slideUp'})});
			  return;
		  }

		  if($(this).hasClass('draggable')){
			  $(this).children('.top').css('cursor','move');
		  }
		  
		  $(this).children('.top').children('.expander').click(function(){
			  	$(this).parent().pixartSection({func : 'slide'}); 
		  });
		 
	  });
  }
  
};
