/* $Id: 4gtr.js 3 2009-12-10 20:40:17Z choman $ */

$(document).ready(function() {
	
	$('#home').hover(
		function() { $('#home img').attr('src', NFW.static_root + '/gfx/home-ho.png'); },
		function() { $('#home img').attr('src', NFW.static_root + '/gfx/home.png'); }
		);
	$('#logo').hover(
		function() { $('#logo img').attr('src', NFW.static_root + '/gfx/logo-ho.png'); },
		function() { $('#logo img').attr('src', NFW.static_root + '/gfx/logo.png'); }
	);
	$('#online-shop').hover(
		function() { $('#online-shop img').attr('src', NFW.static_root + '/gfx/online-shop-ho.png'); },
		function() { $('#online-shop img').attr('src', NFW.static_root + '/gfx/online-shop.png'); }
	);


	$('#contact-form').submit(function(ev) {
		function setError(f, msg) {
			$('#req-' + f).text(msg);
			$('#req-' + f).closest('li').addClass('error');
		}
		
		function clearError(f) {
			$('#req-' + f).text('*');
			$('#req-' + f).closest('li').removeClass('error');
		}
		
		function validateField(f, min_l, e_msg, s_msg) {
			var s = $('#' + f)[0].value;
			if (s == '') {
				setError(f, e_msg);
				return false;
			}
			if (s.length < min_l) {
				setError(f, s_msg);
				return false;
			}
			clearError(f);
			return true;
		}
		
		var b = validateField('name', 7, '* to pole jest wymagane', '* zbyt krótkie imię i nazwisko');
		b &= validateField('email', 0, '* to pole jest wymagane', '* zbyt krótkie imię i nazwisko');
		b &= validateField('msg', 0, '* to pole jest wymagane', '* zbyt krótkie imię i nazwisko');
		b &= validateField('result', 0, '* to pole jest wymagane', '* zbyt krótkie imię i nazwisko');
		
		if (b) {
			return;
		}
		
		ev.preventDefault();
		
	});
	
	$('.gallery a').lightBox({
		imageLoading: NFW.static_root + '/gfx/lightbox-ico-loading.gif', // (string) Path and the name of the loading icon
		imageBtnPrev: NFW.static_root + '/gfx/lightbox-btn-prev.gif', // (string) Path and the name of the prev button image
		imageBtnNext: NFW.static_root + '/gfx/lightbox-btn-next.gif', // (string) Path and the name of the next button image
		imageBtnClose: NFW.static_root + '/gfx/lightbox-btn-close.gif', // (string) Path and the name of the close btn
		imageBlank: NFW.static_root + '/gfx/lightbox-blank.gif'
	});


	function equalColumns() {
		var max = 0;
		$('#main').css('height', 'auto');
		$('#sidebar,#main').each(function(i) {
			var h = $(this).height();
			if (h > max) {
				max = h;
			}
		});
		$('#sidebar,#main').each(function(i) {
			$(this).height(max);
		});
	}
	
	equalColumns();

});
