if (null == String.prototype.toCamelCase) {
	String.prototype.toCamelCase = function() {
		var result = this.valueOf();
		result = result.replace(/\_[a-z]/g, function($1){return $1.toUpperCase().replace('_','');});
		return result;
	}
}

function addIdToRowDiv() {
	$('.row .id').each(function() {
		var rowType = $(this).parent().attr('class');
		rowType = rowType.slice(rowType.indexOf(' ')+1);
		if (-1 != rowType.indexOf(' ')) {
			rowType = rowType.slice(0, rowType.indexOf(' '));
		}
		$(this).parent().attr('id', rowType + '_' + $(this).text());
	});
}

function removeUnwantedFields(fieldList) {
	$.each(fieldList, function(index,value) {
		$('.row .' + value).remove();
	});
}

function runFieldScripts() {
	var rowType = $('.rows .row:first').attr('class');
	if ('undefined' == typeof(rowType)) {return false;}
	rowType = rowType.slice(rowType.indexOf(' ')+1);
	if (-1 != rowType.indexOf(' ')) {
		rowType = rowType.slice(0, rowType.indexOf(' '));
	}
	$('.rows .row:first > div').each(function() {
		var fieldType = $(this).attr('class');
		if (-1 != fieldType.indexOf('subrows ')) {
			fieldType = fieldType.slice('subrows '.length);
		}
		if (-1 != fieldType.indexOf(' ')) {
			fieldType = fieldType.slice(0, fieldType.indexOf(' '));
		}
		var rowFieldFunction = 'handle_' + rowType + '_' + fieldType + '_field';
		rowFieldFunction = rowFieldFunction.toCamelCase();
		var fieldFunction = 'handle_' + fieldType + '_field';
		fieldFunction = fieldFunction.toCamelCase();
		if ('function' == typeof(window[rowFieldFunction])) {
			window[rowFieldFunction]();
		} else if ('function' == typeof(window[fieldFunction])) {
			window[fieldFunction]();
		} else {
$.log.log('No script defined: ' + rowFieldFunction);
		}
	});
}

function stripeRows() {
	$('.row:even').addClass('even');
}

$(function() {
	$.log.startLogging().log('START');
});
