/* $Id: higashi.js 2 2009-10-14 18:16:27Z choman $ */

$(document).ready(function() {

	$('.imagesList 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'
	});
	
	$('#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', 0, '* to pole jest wymagane', '* zbyt krótkie imię i nazwisko');
		b &= validateField('phone', 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();
		
	});
	
	function initLinks(elems) {
		$(elems).attr('origsrc', function(attr) {
			return $(this).attr('src');
		});
		$(elems).hover(function() {
			$(this).attr('src', $(this).attr('origsrc').replace(/\.png/, '-h.png'));
		},
		function() {
			$(this).attr('src', $(this).attr('origsrc'));
		});
	}
	
	initLinks($('#menu li[class!=selected] img'));

	$('.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'
	});
});

