$(document).ready(function() {

	/* labels in input boxes */
	/* Depreciated
	$('form.lib input[type="text"]').each(function() {
		var label = $('form.lib label[for="'+$(this).attr('id')+'"]');
		if($(this).val() == '') {
			$(this).val(label.text());
		}
	});
	
	$('form.lib input[type="text"]').focus(function() {
		var label = $('form.lib label[for="'+$(this).attr('id')+'"]');
		if($(this).val() == label.text()) {
			$(this).val('');
		}
	});
	
	$('form.lib input[type="text"]').blur(function() {
		if($(this).val() == '') {
			var label = $('form.lib label[for="'+$(this).attr('id')+'"]');
			$(this).val(label.text());
		}
	});
	
	$('form.lib').submit(function() {
		$('form.lib input[type="text"], form.lib input[type="password"]').each(function() {
			var label = $('form.lib label[for="'+$(this).attr('id')+'"]');
			if($(this).val() == label.text()) {
				$(this).val('');
			}
		});
	});
	*/

	/* labels in password boxes */
	/* Depreciated!
	$('form.lib input[type="password"]').each(function() {
		var label = $('form.lib label[for="'+$(this).attr('id')+'"]');
		if($(this).val() == '') {
			$(this).hide();
			var newPassword = document.createElement("input");
			newPassword.setAttribute('type', 'text');
			newPassword.setAttribute('id', $(this).attr('id')+'_dyn');
			newPassword.setAttribute('class', 'password');
			newPassword.value = label.text();
			newPassword.onfocus = function(){
				var label = $('label[for="'+($(this).attr('id')).replace(/_dyn/, '')+'"]');
				if($(this).val() == label.text()) {
					$(this).hide();
					$('form.lib #'+label.attr('for')).show().focus();
				}
			}
			$(this).after(newPassword);
		}
	});

	$('form.lib input[type="password"]').blur(function() {
		if($(this).val() == '') {
			$(this).hide();
			$('form.lib #'+$(this).attr('id')+'_dyn').show();
		}
	});
	*/
	
	/* heading arrows */
	$('h2').each(function() {
		if($(this).find('span').length) {
			$(this).find('span').before('<span class="arrow"></span>');
		} else {
			$(this).append('<span class="arrow"></span>');
		}
	});

	/* Link Ul on homepage to the register page */
	$('#steps').click(function(){document.location='/register/';});
	$('#steps').css('cursor', 'pointer');

	/* Shorten Blog feed description */

	desc = $('#callouts').children().eq(1).find('.description').children().eq(1);
	if (desc.length==0) desc = $('.blog-description').children().eq(1);
	if (desc){
		h = desc.height();
		code = desc.html();
		if (code){
			code = code.substr(0, code.length-5) + "&hellip;";
			desc.html(code);
			while (h>100 && code){
				code = code.substr(0, code.length-9) + "&hellip;";
				desc.html(code);
				h = desc.height();
			}
		}
	}
});
