function custom_resize_fieldgroups(){
	
	
	$('.fieldset-clear').remove();
	
	$('fieldset.fieldgroup,fieldset.node-categories').each(function(){
		if($(this).width()>300){
			$(this).width(300);
		}	
		
	}).each(function(){
		var p=$(this).prev('fieldset.fieldgroup,fieldset.node-categories');
		if(p.length && p.offset().top != $(this).offset().top){
			$(this).before('<div class="fieldset-clear" style="clear:both"></div>');
			
			return;
		}
		//alert(this.offsetTop);
	});	
	
	$('.faceted-search-guided').each(function(){
		var p=$(this).prev('.faceted-search-guided');
		if(p.length && p.offset().top != $(this).offset().top){
			$(this).before('<div class="fieldset-clear" style="clear:both"></div>');
			
			return;
		}

	});	
	
	
}

$(window).resize(function(){
	
	custom_resize_fieldgroups();
	
});

$(document).ready(function(){
	
	
	$('.form-submit').hover(
		function(){
			$(this).addClass('.form-submit-hover');
		},
		function(){$(this).removeClass('.form-submit-hover');}
	);
	
	
	$('#faceted-search-ui-form .form-submit').val('').attr('hidefocus',1);
	
	$('.node .icon-link,#faceted-search-ui-form .form-submit').hover(function(){
		$(this)
			.css('top','-1px')
			.css('left','-1px')
		;
	},function(){
		$(this)
			.css('top','0px')
			.css('left','0px')
		;	
	}).mousedown(function(){
		$(this)
			.css('top','1px')
			.css('left','1px')
		;
	});	

	$('table').each(function(){
		var t=246	;
		var c='rgb(' + parseInt(t+Math.random()*(256-t))+','+
		parseInt(t+Math.random()*(256-t))+','+parseInt(t+Math.random()*(256-t))+')';
		$(this).find('.odd').css('background',c);

		var c='rgb(' + parseInt(t+Math.random()*(256-t))+','+
		parseInt(t+Math.random()*(256-t))+','+parseInt(t+Math.random()*(256-t))+')';
		$(this).find('.even').css('background',c);
		
	});
	$('.form-file').attr('size',35);
	$('textarea').removeAttr('cols').css('width','100%');
	
	custom_resize_fieldgroups();
	
	//$('.node-form .form-item.title,.field-name-english,.node-form .form-item.body').wrapAll('<fieldset class="info">');
	
	$('fieldset').each(function(){
		var t=246	;
		var c='rgb(' + parseInt(t+Math.random()*(256-t))+','+
		parseInt(t+Math.random()*(256-t))+','+parseInt(t+Math.random()*(256-t))+')';
		$(this).css('background',c);
	});
	
	$('.combo .label').click(function(){
		if($(this).is('.collapsed')){
			$(this).removeClass('collapsed').addClass('expanded').next().show(100);
		}else{
			$(this).removeClass('expanded').addClass('collapsed').next().hide(100);	
		}
	});
	
	
	$('.combo :checkbox').click(function(){
		if($(this).is(':checked')	){
			$(this).parent().addClass('checked');
		}else{
			$(this).parent().removeClass('checked');
		}
	});
	
	$('.combo input:checked').parents('.combo-folder').children('.label').click();
	$('.combo input:checked').parent().addClass('checked');
	
	
	$('.view-field').each(function(){
		$(this).find('img:eq(0)').show();	
	});
	
});