$(window).ready(function(){
	$('.what-page').change(function(){
		$('.dodatkowe-what-page').toggle();
	});
	$('.what-event').change(function(){
		$('.dodatkowe-what-event').toggle();
	});
	$('.what-program').change(function(){
		$('.dodatkowe-what-program').toggle();
	});

	$('.dodatkowe-what-program, .dodatkowe-what-event, .dodatkowe-what-page').not('.active').hide();
	
	$('.what-program:not(:checked) + .dodatkowe-what-program').hide();
	
		$('.dodatkowe-what-program, .dodatkowe-what-event, .dodatkowe-what-page').not('.chore').click(function(){
			$(this).addClass('chore').val('');
		});

	$('#galleryIndex a').click(function(){
		var $old = $('#galleryPhoto img');
		var newSrc = $(this).find('img').attr('src');
		
		$('#galleryPhoto')
		.append('<img style="display: none;" src="' + newSrc + '" alt="' + newSrc + '">');

		$('#galleryPhoto img')
		.animate({
			opacity: 'toggle'
		}, 1000, function(){
			$old.remove();
		});

		$(this).parent().css('opacity', 1);

		return false;
	});

	$('#galleryIndex li').css('opacity', .5);
	$('#galleryIndex li').hover(
		function(){
			$(this).stop(true, true).animate({ opacity: 1 }, 250);
		},
		function(){
			$(this).stop(true, true).animate({ opacity: .5 }, 250);
		}
	);

	$('#newsletter input[type=email]').click(function(){
		$(this).val('');
	});

	$('#partnerzyReklama').cycle();

	$('#clubSelect select').change(function(){
		$('#clubSelect').submit();
	});

	$('#clubSelect :submit').remove();
	$('#welcome').append('<ul id=welcomeSlideshowNav></ul>');
	$('#welcomeSlideshow').cycle({
		speed: 1500,
		timeout: 4000,
		pause: true,
		pauseOnPagerHover: true,
		pager: '#welcomeSlideshowNav',
		pagerAnchorBuilder: function(idx, slide){
			return '<li><a href="#">' + idx + '</a>';
		}
	});

	$('#facebookBox').hover(
		function(){
			$(this).animate({
				right: -35
			}, 500);
		},
		function(){
			$(this).animate({
				right: -327
			}, 500);
		}
	);

	$('#facebookBox').css('right', '-327px');

	$('#arrowTop').click(function(){
		$('#galleryIndex').animate({
			scrollTop: '-=93'
		}, 500);
	});

	$('#arrowBottom').click(function(){
		$('#galleryIndex').animate({
			scrollTop: '+=88'
		}, 500);
	});

	if($('#galleryIndex img').lenght > 8){
		$('#arrowTop, #arrowBottom').hide();
	}
});

$(window).load(function(){
	var imgw = $('#overlay-container img').width();
	var imgh = $('#overlay-container img').height();

	$('#overlay-container')
	.css({
		width: imgw,
		height: imgh,
		top: $(window).height() / 2 - imgh / 2,
		left: $(window).width() / 2 - imgw / 2
	});

	$('#overlay-popup, #overlay-close')
	.click(function(){
		$('#overlay-popup, #overlay-container').hide();
	});
});
