function cl(msg){
	if(typeof(console) != "undefined"){
		console.log(msg);
	}
}

function cle(msg){
	if(typeof(console) != "undefined"){
		console.error(msg);
	}
}
function clt(msg){
	if(typeof(console) != "undefined"){
		console.trace(msg);
	}
}

jQuery.fn.inputBlankify = function (){

	//Make sure default values aren't sent in form submission
	this.each(function(){
		$(this).focus(function(){
			//Make form blank if form contains default value
			if($(this).val() == $(this).attr('title')){
				$(this).val('');
				$(this).data('useTitle', true);
			}
		});

		$(this).blur(function(){
			if($(this).val() == ''){
				$(this).val($(this).attr('title'));
			}		
		});
	});
}

/**
 * Accepts element object. Loops through child inputs of passed form, and adds
 * submit event handler that removes all default data from input before form submits
 */
jQuery.fn.formClean = function(){
	$(this).each(function(){
		$(this).submit(function(){
			$(this).find('input').each(function(){
				if($(this).val() == $(this).attr('title')){
					$(this).val('');
				}
			});
		});
	});
}

jQuery.fn.addHoverClass = function(){

	$(this).hover(
		function(){
			$(this).addClass('hover');
		},
		function(){
			$(this).removeClass('hover');
		}
	)
}



function createPageIndex(){
	pageIndex = [];
	
	//Add anchors to H3s and insert name and text into array
	$('#content h1, #content h2, #content h3, #content h4, #content h5').each(function(count){
		if( !$(this).hasClass('page-header') ){ //Don't add page header
			$(this).wrapInner('<a name="content_section_' + count + '" href="#content_section_' + count + '"></a>');
			//$(this).attr('name', 'content_section_' + count);
			pageIndex.push([$(this).text(), 'content_section_' + count]);
		}
	});
	
	//Create links to h3 sections
	pageIndexListItems = '';
	jQuery.each(pageIndex, function(){
		pageIndexListItems += '<li><a href="#' + this[1] + '">' + this[0] + '</a></li>';
	});
	
	pageIndexListItems = $("<div class='page-index'><h3>Content Index</h3><div class='content'><p>Click any link below to jump to that section:</p><ul>" + pageIndexListItems + "</ul></div></div>");
	
	if(pageIndex.length < 5){ pageIndexListItems = ''; }
	
	return pageIndexListItems; 
}

//Inject page index into main content section
// $('h2.page-header').after(createPageIndex());