/* $Id: add-art.js 3 2010-07-29 15:57:09Z choman $ */

$(document).ready(function() {
	
	function initLinks(elems) {
		$(elems).each(function(idx) {
			$(this).data('origsrc', $(this).attr('src'));
		});
		$(elems).hover(function() {
			$(this).attr('src', $(this).data('origsrc').replace(/\.png/, '-ho.png'));
		},
		function() {
			$(this).attr('src', $(this).data('origsrc'));
		});
    }

    initLinks($('#top #menu li[class!=selected] img'));

	$('#slideshow').cycle({ 
	    speed:   1000, 
	    timeout: 7000
	});
	
	$('#logo-slideshow').cycle({ 
	    speed:   1000, 
	    timeout: 3000
	});
	
	if (!_lang_req) {
		var _lang_req = 'To pole jest wymagane.';
	}
	
	function setError(f, msg) {
		$('#' + f).closest('li').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;
	}
	
	$('#contact-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, _lang_req, '');
		});
		
		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();

});

