$(function() {
	$('.sub').css('top', $('.nav').height() + 'px');
	$('.nav-list > li').mouseover(function() {
		$(this).addClass('active');
		$(this).children('.sub').show();
	});
	$('.nav-list > li').mouseout(function() {
		$(this).removeClass('active');
		$('.nav-list .sub').hide();
	});
	
	if ($('#archiwum').length) {
		$('.wybrany-okres').each(function(index, el) {
			var $this = $(el);
			var $lista = $this.children('.lista-wyboru');
			
			$lista.css('top', $this.height() + 'px');
			
			$this.mouseover(function() {
				$lista.show();
			});
			
			$this.mouseout(function() {
				$lista.hide();
			});
		});
		
		if (typeof($.datepicker) == 'object') {
		
			$.datepicker.regional['pl'] = {
				closeText: 'Zamknij',
				prevText: '&#x3c; Poprzedni',
				nextText: 'Następny &#x3e;',
				currentText: 'Dziś',
				monthNames: ['Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień'],
				monthNamesShort: ['Sty', 'Lut', 'Mar', 'Kwi', 'Maj', 'Cze', 'Lip', 'Sie', 'Wrz', 'Paź', 'Lis', 'Gru'],
				dayNames: ['Niedziela', 'Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota'],
				dayNamesMin: ['Nd', 'Pn', 'Wt', 'Śr', 'Cz', 'Pt', 'So'],
				weekHeader: 'Tydz',
				dateFormat: 'yy-mm-dd',
				firstDay: 1,
				isRTL: false,
				showMonthAfterYear: false,
				yearSuffix: ''
			};
				
			$.datepicker.setDefaults($.datepicker.regional['pl']);

			$('.datepicker').datepicker({
				showOn: 'both',
				buttonImage: 'http://szlachta.wroclaw.pl/static/_i/archiwum/kalendarz.gif',
				buttonImageOnly: true,
				dateFormat: 'yy-mm-dd',
				changeYear: true,
				minDate: new Date(2006, 0, 1),
				maxDate: new Date(2009, 9, 0),
			});
			
			$('.data').click(function() {
				$('input[name=okres_szukania]').attr('checked', '');
				$(this).children('input[name=okres_szukania]').attr('checked', 'checked');
			});
			
			$('img.ui-datepicker-trigger').click(function() {
				$('input[name=okres_szukania]').attr('checked', '');
				$(this).parent().children('input[name=okres_szukania]').attr('checked', 'checked');
			});
		}
	}
});
