$(document).ready(function()
{
	$('a[@rel=external]').click(function()
	{
		$(this).attr('target', '_blank');
	});

	$('a[@rel*=lightbox]').lightBox(
	{
		imageLoading: '/images/lightbox/lightbox-ico-loading.gif',
		imageBtnPrev: '/images/lightbox/lightbox-btn-prev.gif',
		imageBtnNext: '/images/lightbox/lightbox-btn-next.gif',
		imageBtnClose: '/images/lightbox/lightbox-btn-close.gif',
		imageBlank: '/images/lightbox/lightbox-blank.gif',
		txtImage: '',
		txtOf: ' / '
	});
});


function validate(f)
{
	var failed = false;

	$('form#' + f.id + ' .required').each(function()
	{
		var id = $(this).attr('id');
		var label = $('label[@for=' + id + ']');

		label.removeClass('error');
		if ($(this).val() == '')
		{
			label.addClass('error');
			failed = true;
		}
	});

	if (failed)
	{
		$('#error').html('Užpildykite visus privalomus laukus.');
		$('#error').fadeIn(400);
	}

	return !failed;
}

function initialize()
{
	$('.place').each(function()
	{
		var id = $(this).attr('id').replace('place', '');

		var map = null;
		var geocoder = null;

		if (GBrowserIsCompatible())
		{
			map = new GMap2(document.getElementById("map" + id));
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());

	        geocoder = new GClientGeocoder();
		}

		var address = $('#address' + id).html();	

		if (geocoder)
		{
			geocoder.getLatLng(address, function(point)
			{
				if (!point)
				{
					GUnload();
					$('#map' + id).remove();
				}
				else
				{
					map.setCenter(point, 15);
					map.enableDoubleClickZoom();

					var marker = new GMarker(point);
					map.addOverlay(marker);
				}
			});
		}
	});
}
