$(document).ready(function() {
	// Render lightbox on links of .lightbox class
	$('a.lightbox').lightBox();
	
	// Animate submenu
	$('#submenu li').each(function(i) {
		$(this).hide();
		setTimeout('$("#submenu li:eq('+ i +')").fadeIn(200)', (50 * i));
	});
	
	// Do focus/blur of input fields
	$('input[@type=text], input[@type=password], textarea').focus(function() {
		showInputFrame($(this));
	});
	
	$('input[@type=text], input[@type=password], textarea').blur(function() {
		hideInputFrame($(this));
	});
	
	// Do default values (smart fields):
	// (If the form has not been submitted)
	if(!pageRequestIsPost) {
		document.getElementById('idClientPassword').type = 'text';
		$('#idClientUsername').defaultvalue();
		$('#idClientPassword').defaultvalue({
			defaultValueInputType : 'text',
			inputType : 'password'
		});
	}
});

// Functions to add/remove focus frame on input fields
function showInputFrame($inputControl) {
	// Local variables
	var offset, tWidth, tHeight;
	
	// Get the input control's position on the page:
	offset = $inputControl.offset();
	
	// Target width + height of the frame:
	tWidth  = $inputControl.width()  + 10;
	tHeight = $inputControl.height() + 6;
	
	// Create frame, if not existing yet:
	if(! document.getElementById('inputControlFrame')) {
		//$('body').append('<div id="inputControlFrame" style="display: none"></div>');
		$('body').append('<div id="inputControlFrame"></div>');
		$('#inputControlFrame').css({
			width: tWidth + 'px',
			height: tHeight + 'px',
			position: 'absolute',
			top: (offset.top - 20),
			left: offset.left,
			border: '2px solid #0a65b1',
			opacity: 0
		});
	}
	
	// Stop any ongoing animation:
	$('#inputControlFrame').stop();
	
	// We animate the frame, adjusting position and size
	$('#inputControlFrame').animate({ 
        width : tWidth  + 'px',
        height : tHeight + 'px',
        top : offset.top,
        left : offset.left,
        opacity: 1
	}, 300);
}

function hideInputFrame($inputControl) {
	$('#inputControlFrame').stop();
	$('#inputControlFrame').fadeOut(500);
}
