$(document).ready(function() {
	$('#flickr_badge_wrapper a').each(function() {
		$(this).attr('rel','lightbox-flickr');
		var imgSrc = $(this).children().attr('src');
		$(this).attr('href',imgSrc.replace('_s.jpg','.jpg'))
	});

	$('a[rel*=lightbox-flickr]').slimbox();

  $('#button-unsubscribe').click(function() {
    $('#email').val($('#tkuluu-tkuluu').val());
    $('#unsubscribe').submit();
  });
});

$(function() {
  $('#images').cycle();

  $(".scrolling").jCarouselLite({
    btnNext: ".next",
    btnPrev: ".prev",
    auto: 6000,
    speed: 3000,
    circular: false
  });

	var updateBegin = function (selectedDate)
	{
		var selectedDate = new Date(selectedDate);
		$('#begind option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
		$('#beginm option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
		$('#beginY option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
		updateEnd(selectedDate);
	}
	var updateEnd = function (selectedDate)
	{
		var selectedDate = new Date(selectedDate);
		$('#endd option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
		$('#endm option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
		$('#endY option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
	}
	var today = new Date();
	
	$('#datepick-begin').datePicker({ createButton: false } // begin
    ).bind(
			'click', function() {
				updateBegin($(this).dpGetSelected()[0]);
				$(this).dpDisplay();
				return false;
			}
		).bind(
			'dateSelected', function(e, selectedDate, $td, state) {
				updateBegin(selectedDate);
			}
		).bind(
			'dpClosed', function(e, selected) {
				updateBegin(selected[0]);
	});
	$('#begind, #beginm, #beginY')
		.bind(
			'change', function() {
				var d = new Date(
							$('#beginY').val(),
							$('#beginm').val()-1,
							$('#begind').val()
						);
				$('#datepick-begin').dpSetSelected(d.asString());
				$('#datepick-end').dpSetSelected(d.asString());
	});
	updateBegin(today.getTime());
	$('#begind').trigger('change');
});