$(document).ready(function(){

toogleWidget();

activateClearWidgets();

$(".collapseWidget").each(function(){
	var _content = $(this);
    $(this).find(".collapseButton").each(
		function(){
			if($(this).attr("checked")){
				_content.find(".collapseContent").css("display","block");
			}
			$(this).click(function(){
  		  	_subContent = _content.find(".collapseContent").slideToggle("slow");		  
    	});
	});
	
		
});

	
});


function activateClearWidgets(){
	
$(".clearWidget").each(function(){
	var _content = $(this);
	var controls = _content.find("input[type=text]");
	$(this).find(".clearButton").click(function(a, b, c){
		controls.each(function(i){ 
			if(i == 0) $(this).focus();
			$(this).val("")
		});
	});
});
}

var aux = Array();
aux['id'] = null ;
aux['object'] = null ;

function toogleWidget(){
	
$(".toggleWidget").each(function(i){
	var _content = $(this);
    $(this).find(".toggleButton").click(function(){
			var button = $(this);
  		  _subContent = _content.find(".subcontent").slideToggle("fast", function(){button.toggleClass('active');_subContent.find("input[type=text]:first, textarea:first").focus();
  		  
  		  if(aux['id']!= i){  
  		  try{
  			  if(aux['object'].css("display") != "none"){
  				  aux['object'].slideToggle();
  			  }
		  }catch(e){}
		  aux['object']  = _subContent;
		  aux['id']      = i;
  		}  
  		  });
  		  
  		  
		  return false;
    });
});	
}


