/* 
This function is executed once the page is loaded and checks the withs of the buttons. 
If a button is small than a specific width is set.
*/
$(document).ready(function() {

	// Resize buttons to fit long text strings
	$('.formButton,.userinputButtons').each(function(){
			var width = $(this).width();
			if(width < 100){
				$(this).width(120);
			}
	});
	
	// Add maxlength function to textareas
	if($('textarea[maxlength]')){
	    $('textarea[maxlength]').keyup(function(){
	        var max = parseInt($(this).attr('maxlength'));
	        if($(this).val().length > max){
	            $(this).val($(this).val().substr(0, $(this).attr('maxlength')));
	        }
	    });
	}
	
	//
	// Bind functions
	//
	
	// Make fieldsets collapsible
	$("fieldset.collapsible legend span a").bind("click",toggleFieldset);
	
	// Make sheets toggleble (show/hide using a slide effect
	$(".sheettoggle").bind("click",toggleSheet);
	
	// Add context menus
	contextMenu();
	
});