// bof dom ready
$(function() {

	// input element value toggler
	$('#root .value_toggle').each(function() {

		// some variables
		var els = {},
			data = $(this).attr('title');
			
		// cache this
		els.it = $(this).addClass('default_value');
		
		// change type and set default value if password field
		if ('password' == els.it.attr('type')) {
			
			// create a second element
			els.clone = $('<input>').attr({
				type: "text",
				value: data,
				title: data,
				id: 'clone_'+els.it.attr('id')
			}).addClass('input_text').addClass('default_value');
			
			// add the second element
			els.it.after(els.clone);
			
			// set value to blank if needed (take care of webkit autogeneration bug)
			if (els.it.val() != '') els.it.val("");
			els.it.hide();
			
		};
		
		// binding
		$.each(els, function() {
			$(this).bind({
				focus: function() {
					if ($('#'+$(this).attr('id').replace('clone_','')).attr('type') == 'password') {
						$(this).hide().prev().show().unbind('focus').focus().removeClass('default_value');
					}
					else {
						if ($(this).val() == data) $(this).val('').removeClass('default_value');
					};
				},
				blur: function() {				
					if ($(this).attr('type') == 'password') {
						if ($(this).val() == '') $(this).hide().next().show().addClass('default_value');
					}
					else {
						if ($(this).val() == '') $(this).val(data).addClass('default_value');
					};
				}
			});
		});
	});
	
	// make message box blink
	$("p.message").fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn();
	
	// open URL in a new window
	$('#root a.new_window').bind({
		click: function(ev) {
			ev.preventDefault();
			window.open($(this).attr('href'));
		}
	});

// eof dom ready
});
