$(document).ready(function(){
   // Use the each() method to gain access to each of the elements attributes
   $('a.descriptionText').each(function() {
      $(this).qtip({
         content: $(this).parent().children('div.toolText').html(), // Give it some content
         position: 'topRight', // Set its position
         hide: {
            fixed: true // Make it fixed so it can be hovered over
         },
				 style: {
					 width: {
							min: 150,
							max: 250
					 },
					 background: 'transparent',
					 classes: {tooltip: 'toolTextBlock'}
				 }
      });
   });

	/* --------- obsługa kalendarza ---------------*/

	$('a.ui-state-default').mouseover( function(){$( this ).addClass('ui-state-hover');});
	$('a.ui-state-default').mouseout( function(){$( this ).removeClass('ui-state-hover');});
	$('a#calendar_next, a#calendar_prev').click( function(){getCalendar( this );});
	$('select#monthSelectList, select#yearSelectList').change(function(){
		getCalendar( $(this).children('option:selected') );
	});

	function blockCalendar(){
		$('div#calendarData').append( '<div style="position: absolute; width: 100%; height: 100%; padding: 5px; background: #F1F1F1; opacity: .8; top: 0px; left: 0px;"><div class="spacer40"></div><div class="spacer40"></div><img src="/_images/loading_green.gif"><br/><b>proszę czekać</b></div>' );
	}

	function unblockCalendar(){
		
	}

	function getCalendar( calendar ){
		var month	= $( calendar ).attr('month');
		var year	= $( calendar ).attr('year');

		$.ajax({
			type: "POST",
			url: "/pobierzKalendarz.html",
			data: "month="+month+"&year="+year,
			beforeSend: function(){
				blockCalendar();
//				$('div#calendarData').block({
//						message: '<div><img src="/_images/loading_green.gif"></div><div style="font-weight: bold;">proszę czekać</div>',
//						css:{background: 'transparent', border: '0px', width: '100px'},
//						overlayCSS: {backgroundColor: '#F6F0DA', opacity: .75}
//				});
			},
			success: function( data ){
				$('div#calendarData').html( data );
				$('a.ui-state-default').mouseover( function(){$( this ).addClass('ui-state-hover');});
				$('a.ui-state-default').mouseout( function(){$( this ).removeClass('ui-state-hover');});
				$('a#calendar_next, a#calendar_prev').click( function(){getCalendar( this );});
				$('select#monthSelectList, select#yearSelectList').change(function(){
					getCalendar( $(this).children('option:selected') );
				});

				// obsługa axajowych informacji
			 $('a.descriptionText').each(function() {
					$(this).qtip({
						 content: $(this).parent().children('div.toolText').html(), // Give it some content
						 position: 'topRight', // Set its position
						 hide: {
								fixed: true // Make it fixed so it can be hovered over
						 },
						 style: {
							 width: {
									min: 150,
									max: 250
							 },
							 background: 'transparent',
							 classes: {tooltip: 'toolTextBlock'}
						 }
					});
			 });

			},
			complete: function(){
//				$('div#calendarData').unblock();
			}
		});
	}

	/* --------- obsługa kalendarza ---------------*/

	 $('a#search').click(function(){
		$('div#search').slideToggle('fast');
	});



	// obsługa galerii zdjęć
	if( $('a.galeryImage').length > 0 ){
		$('a.galeryImage').lightBox({txtImage: 'Zdjęcie', txtOf: 'z'});
	}



	$('#probe_title_1').click(function(){
		$('#probe_content_1').slideToggle();
	});

	$('#probe_title_2').click(function(){
		$('#probe_content_2').slideToggle();
	});

});
