var	filesToLoadTemplate		= new Array();
	filesToLoadTemplate[0]	= 'JQuery.Plugins.Tooltip.js';
var	currentFileTemplate		= 0;
function loadFilesTemplate()
{
	if (typeof filesToLoadTemplate[currentFileTemplate] == 'string')
	{
		$.getScript(SCORE_URL + 'Includes/Javascripts/' + filesToLoadTemplate[currentFileTemplate], loadFilesTemplate);
		currentFileTemplate++;
	}
	else
	{
		executeTemplate();
	}
}

$(document).ready(loadFilesTemplate);

function executeTemplate()
{
	selfLabelledInit();


	$('*[title]').not('#promotool').tooltip({
    	delay	: 500,
    	fade	: 250,
    	track	: true
	});
}

/*	Self labeled fields for login	*/
function selfLabelledBlur()
{
	var	parent	= $(this).parent().get(0);
	while (parent.tagName != 'FORM')
		parent	= $(parent).parent().get(0);

	$('label[for=' + $(this).attr('name') + ']', parent).hide();
	var	label	= $('label[for=' + $(this).attr('name') + ']', parent).html();

	if ($(this).attr('type') == 'password' && $(this).val() == '')
	{
		$(this).hide();
		$('input.passwordLabel', $(this).parent().get(0)).show();
	}
	else
	{
		if ($(this).val() == '')
			$(this).val(label);
	}
}
function selfLabelledFocus(event)
{
	var	parent	= $(this).parent().get(0);
	while (parent.tagName != 'FORM')
		parent	= $(parent).parent().get(0);

	var	label	= $('label[for=' + $(this).attr('name') + ']', parent).html();

	if ($(this).hasClass('passwordLabel'))
	{
		$(this).hide();
		$('input[name=' + $(this).attr('rel') + ']', $(this).parent().get(0)).show().focus();
	}
	else
	{
		if ($(this).val() == label)
			$(this).val('');
	}
}
function selfLabelledInit()
{
	$('input.self').each(function ()
	{
		var	parent	= $(this).parent().get(0);
		while (parent.tagName != 'FORM')
			parent	= $(parent).parent().get(0);

		$('label[for=' + $(this).attr('name') + ']', parent).hide();
		var	label	= $('label[for=' + $(this).attr('name') + ']', parent).html();

		if ($(this).attr('type') == 'text')
		{
			$(this).val(label).focus(selfLabelledFocus).blur(selfLabelledBlur);
		}
		else if ($(this).attr('type') == 'password')
		{
			var	passwordLabel	= $('<input class="' + $(this).attr('class') + ' passwordLabel" rel="' + $(this).attr('name') + '" type="text" value="' + label + '" />').focus(selfLabelledFocus);
			$(this).blur(selfLabelledBlur);
			$(this).parent().prepend(passwordLabel);
			$(this).hide();
		}
	});
}
