/* $Id: atb.js 13 2009-07-23 10:49:11Z choman $ */

$(document).ready(function() {
	
	function start_slideshow(id, start_frame, end_frame, delay, speed) {
		setTimeout(switch_slides(id, start_frame,start_frame,end_frame, delay, speed), delay);
	}
	                        
	function switch_slides(id, frame, start_frame, end_frame, delay, speed) {
		return (function() {
			setTimeout("$('#" + id + frame + "').fadeOut(" + speed + ")");
			if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
			setTimeout("$('#" + id + frame + "').fadeIn(" + speed + ")");
			setTimeout(switch_slides(id, frame, start_frame, end_frame, delay, speed), delay + speed);
		})
	}
	
	start_slideshow('logo', 1, 10, 2000, 2000);
	
	$('#button-1-1').hover(
		function() { $('#button-1-1').attr('src', NFW.static_root + '/gfx/button-1-1-ho.jpg') },
		function() { $('#button-1-1').attr('src', NFW.static_root + '/gfx/button-1-1.jpg') }
	);
	$('#button-1-2').hover(
		function() { $('#button-1-2').attr('src', NFW.static_root + '/gfx/button-1-2-ho.jpg') },
		function() { $('#button-1-2').attr('src', NFW.static_root + '/gfx/button-1-2.jpg') }
	);


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

