var browser = navigator.userAgent.toLowerCase();

window.ie = false;
window.ie6 = false;
window.ie7 = false;

if(browser.indexOf("msie") != -1)
{
	window.ie = true;

	if(browser.indexOf("msie 6.0") != -1)
	{
		window.ie6 = true;
	}

	if(browser.indexOf("msie 7.0") != -1)
	{
		window.ie7 = true;
	}
}

Event.onDOMReady(function()
{
	inputOnFocus();

//	tableHover();

/*
	makeCountrySelector();
*/

	if($('flashBox'))
		showFlashBox('flashBox', 'switchOn');

	$$('pre').each(function(pre)
	{
		var _height = pre.offsetHeight;

		pre.setStyle({opacity: 0.85, overflow: 'hidden'});
		new Draggable(pre);
		Event.observe(pre, 'dblclick', function()
		{
			if(pre.offsetHeight > 40)
			{
				new Effect.Morph(pre,
				{
					style:
					{
						height: '18px',
						opacity: '0.2'
					},
					duration: 0.6
				});
			}
			else
			{
				new Effect.Morph(pre,
				{
					style:
					{
						height: _height + 'px',
						opacity: '0.85'
					},
					duration: 0.6
				});
			}
		});
	});

/*
	$('languageSelect').hide();
	$('languageSelect').style.visibility = 'visible';
*/

	$$('.questionMark').each(function(img)
	{
		img.observe('mouseover', function()
		{
			img.style.cursor = 'help';
			showTooltip(img);
		});
		img.observe('mouseout', function()
		{
			hideTooltip(img);
		});
	});
});

function inputOnFocus()
{
	$$('input').each(function(input)
	{
		if(input.type != 'submit' && input.type != 'button' && input.type != 'file')
		{
			Event.observe(input, 'focus', function()
			{
				input.addClassName('active');
			});

			Event.observe(input, 'blur', function()
			{
				input.removeClassName('active');
			});

			if(input.disabled)
				input.addClassName('inputDisabled');

			if(window.ie)
			{
				if(input.type == 'checkbox' || input.type == 'radio')
				{
					input.addClassName('ie_checkboxRadio');
				}
			}
		}
/*
		else
		{
			if(window.ie)
			{
				if(input.type != 'file')
					input.addClassName('buttonInput');
/*
				if(input.type == 'file')
				{
					input.style.height = input.offsetHeight + 2 + 'px';
				}
			}
		}
*/
	});

	$$('textarea').each(function(textarea)
	{
		Event.observe(textarea, 'focus', function()
		{
			textarea.addClassName('active');
		});

		Event.observe(textarea, 'blur', function()
		{
			textarea.removeClassName('active');
		});

		if(textarea.disabled)
			textarea.addClassName('inputDisabled');
	});

	if(window.ie)
	{
		$$('button').each(function(button)
		{
			button.addClassName('buttonInput');
			button.style.marginLeft = '5px';
		});
	}

	$$('select').each(function(select)
	{
		Event.observe(select, 'focus', function()
		{
			select.addClassName('active');
		});

		Event.observe(select, 'blur', function()
		{
			select.removeClassName('active');
		});

		if(select.disabled)
			select.addClassName('inputDisabled');
	});
}

function tableHover()
{
	$$('table.list tr').each(function(tr)
	{
		Event.observe(tr, 'mouseover', function()
		{
			tr.addClassName('trHover');
		});

		Event.observe(tr, 'mouseout', function()
		{
			tr.removeClassName('trHover');
		});
	});

	$$('.listTable table tr').each(function(tr)
	{
		Event.observe(tr, 'mouseover', function()
		{
			tr.addClassName('trHover');
		});

		Event.observe(tr, 'mouseout', function()
		{
			tr.removeClassName('trHover');
		});
	});
}

function makeCountrySelector()
{
	if(!$('countrySelectOptions'))
		return false;

	$$('#countrySelectOptions .countrySelectOption').each(function(countryOption)
	{
		Event.observe(countryOption, 'mouseover', function()
		{
			countryOption.addClassName('hover');
		});

		Event.observe(countryOption, 'mouseout', function()
		{
			countryOption.removeClassName('hover');
		});
	});
}
