$(function(){
	$('a[rel="lightbox"]').lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.6,
		imageLoading: config[0] + '/img/loading.gif',
		imageBtnClose: config[0] + '/img/close.gif',
		imageBtnPrev: config[0] + '/img/prev.gif',
		imageBtnNext: config[0] + '/img/next.gif',
		containerResizeSpeed: 350,
		txtImage: i18n[0],
		txtOf: i18n[1]
	});
	
	$('a[rel="external"]').click(function(){
		window.open($(this).attr('href'), '_blank');
		return false;
	});
   
   	function selectItem()
   	{
		$('#searchField').get(0).focus();
		$('#searchField').get(0).form.submit();
	}
   
	$('#searchField').autocomplete(config[1] + '/search', {
		autoFill: true, 
		onItemSelect:selectItem
	});
	
	$('#contactsForm').submit(function(){
		$('#contactsForm .success').remove();
		$('#contactsForm .error').remove();
		
		allowSubmit = true;
		
		if ($('#name').val().length < 1)
		{
			$('#name').after($('<span class="error">' + i18n[2] + '</span>'));
			allowSubmit = false;
		}
		
		if ($('#email').val().length < 1)
		{
			$('#email').after($('<span class="error">' + i18n[2] + '</span>'));
			allowSubmit = false;
		}
		else if (!/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test($('#email').val()))
		{
			$('#email').after($('<span class="error">' + i18n[3] + '</span>'));
			allowSubmit = false;
		}
		
		if ($('#phone').val().length < 1)
		{
			$('#phone').after($('<span class="error">' + i18n[2] + '</span>'));
			allowSubmit = false;
		}
		else if (!/^[0-9\s\(\)\+]+$/.test($('#phone').val()))
		{
			$('#phone').after($('<span class="error">' + i18n[3] + '</span>'));
			allowSubmit = false;
		}		
		if ($('#message').val().length < 1)
		{
			$('#message').after($('<span class="error">' + i18n[2] + '</span>'));
			allowSubmit = false;
		}
		
		return allowSubmit;
	});
	
	$('#road_map a').lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.6,
		imageLoading: config[0] + '/img/loading.gif',
		imageBtnClose: config[0] + '/img/close.gif',
		imageBtnPrev: config[0] + '/img/prev.gif',
		imageBtnNext: config[0] + '/img/next.gif',
		containerResizeSpeed: 350,
		txtImage: i18n[0],
		txtOf: i18n[1]
	});
});