
$(document).ready(function() {

	Cufon.replace('#top .ncms-menu > li > a > span');

	$('#newsletter input').focus(function() {
		if (this.value == 'Wpisz adres e-mail') {
			this.value = '';
		}
		$(this).removeClass('empty');
	});
	$('#newsletter input').blur(function() {
		if (this.value == '') {
			this.value = 'Wpisz adres e-mail';
			$(this).addClass('empty');
		}
	});

	$("#slideshow").easySlider({
		auto: true,
		continuous: true,
		numeric: true,
		pause: 10000,
		speed: 800
	});
	
	$('#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();

	function setError(f, msg) {
		$('#' + f).closest('li').children('label').append('<strong>' + msg + '</strong>');
		$('#' + f).closest('li').addClass('error');
	}
	
	function clearError(f) {
		$('#' + f).closest('li').find('strong').remove();
		$('#' + f).closest('li').removeClass('error');
	}

	function validateField(f, min_l, e_msg, s_msg) {
		var s = $('#' + f)[0].value;
		clearError(f);
		if (s == '') {
			setError(f, e_msg);
			return false;
		}
		if (s.length < min_l) {
			setError(f, s_msg);
			return false;
		}
		return true;
	}

	function validateSelect(f, e_msg) {
		var s = $('select[name=\'' + f + '\']')[0].value;
		clearError(f);
		if (parseInt(s) == 0) {
			setError(f, e_msg);
			return false;
		}
		return true;
	}

	$('form.ncms-form').submit(function(ev) {
		
		var b = true;
		
		$('form li.required input, form li.required textarea, form li.required select').each(function() {
			b &= validateField(this.id, 0, 'To pole jest wymagane', '');
		});
		
		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 initLinks(elems) {
		$(elems).attr('origsrc', function(attr) {
			return $(this).attr('src');
		});
		$(elems).hover(function() {
			$(this).attr('src', $(this).attr('origsrc').replace(/\.png/, '-ho.png'));
		},
		function() {
			$(this).attr('src', $(this).attr('origsrc'));
		});
	}
	
	initLinks($('#logos img'));


});

