function fixHeight(holder, selector){
	var fixHeightProceed = function(pull, maxHeight){
		for(var i = 0; i < pull.length; i++){
			$(pull[i]).height(maxHeight);				
		}		
	};
	var width = $(holder).width();
	var pull = [];
	var totalWidth = 0;
	var maxHeight = 0;
	$('li', holder).each(function(){
		totalWidth += $(this).width();
		var p = $(this).find(selector);
		if(totalWidth >= width){
			fixHeightProceed(pull, maxHeight);
			pull = [];
			maxHeight = 0;
			totalWidth = 0;			
		}
		
		if(p.height() > maxHeight)
			maxHeight = p.height();
		pull[pull.length] = p;
	});
	fixHeightProceed(pull, maxHeight);
}


$(document).ready(function(){
	//fixHeight('.worklist', 'p:first');
	
	$('#email-field').click(function(){
		$(this).val('');
		$(this).removeClass('inactive');
		$(this).unbind("click");
	});
	
	$('#newsletter').submit(function(){
		$.ajax({
			dataType : 'text',
			url : $(this).attr('action'),
			type : 'POST',
			data : { 'email-field' : $('#email-field').val() },
			success : function(r){
								
				if(r == '1'){
					$('#newsletter').remove();
					$('.error-occured').remove();
					$('#newsletter-subscribe-success').show();
					return;
				}
				$('.error-occured').html(r).show();
				
			},
			error : function(){
				//$('#newsletter').remove();
				$('.error-occured').show();
			}
		});
		return false;
	});
	
	// unsubscribe
	$('#newsletter-unsubscribe').submit(function(){
		$.ajax({
			dataType : 'text',
			url : $(this).attr('action'),
			type : 'POST',
			data : { 'email-field' : $('#email-field').val() },
			success : function(r){
				$('.error-occured').hide();
				if(r == '1'){
					$('#newsletter-unsubscribe').remove();
					$('#newsletter-unsubscribe-success').show();
					return;
				}
				$('.error-occured').empty().html(r).show();
				
			},
			error : function(){
				//$('#newsletter').remove();
				$('.error-occured').show();
			}
		});
		return false;
	});
	
});
