jQuery(function()
{
	var todayTmp = new Date();
	var startDateTmp = '1/1/' + todayTmp.getFullYear();
	var endDateTmp = '31/12/' + (todayTmp.getFullYear()+1);

jQuery('<option value="' + todayTmp.getFullYear() + '">' + todayTmp.getFullYear() + '</option>').appendTo((jQuery('#aa')[0]))
jQuery('<option value="' + (todayTmp.getFullYear()+1) + '">' + (todayTmp.getFullYear()+1) + '</option>').appendTo((jQuery('#aa')[0]))

	//(jQuery('#aa')[0]).item.add('<option value="' + todayTmp.getFullYear() + '">' + todayTmp.getFullYear() + '</option>')
	//(jQuery('#aa')[0]).item.add('<option value="' + (todayTmp.getFullYear()+1) + '">' + (todayTmp.getFullYear()+1) + '</option>');


	// initialise the "Select date" link
	jQuery('#date-pick')
		.datePicker(
			// associate the link with a date picker
			{
				createButton:false,
				startDate:startDateTmp,
				endDate:endDateTmp
			}
		).bind(
			// when the link is clicked display the date picker
			'click',
			function()
			{
				updateSelects(jQuery(this).dpGetSelected()[0]);
				jQuery(this).dpDisplay();
				return false;
			}
		).bind(
			// when a date is selected update the SELECTs
			'dateSelected',
			function(e, selectedDate, jQuerytd, state)
			{
				updateSelects(selectedDate);
			}
		).bind(
			'dpClosed',
			function(e, selected)
			{
				updateSelects(selected[0]);
			}
		);
		
	var updateSelects = function (selectedDate)
	{
		selectedDate = new Date(selectedDate);
		var d = selectedDate.getDate();
		var m = selectedDate.getMonth();
		var y = selectedDate.getFullYear();
		(jQuery('#gg')[0]).selectedIndex = d - 1;
		(jQuery('#mm')[0]).selectedIndex = m;
		(jQuery('#aa')[0]).selectedIndex = y - todayTmp.getFullYear();
	}
	// listen for when the selects are changed and update the picker
	jQuery('#gg, #mm, #aa')
		.bind(
			'change',
			function()
			{
				var d = new Date(
							jQuery('#aa').val(),
							jQuery('#mm').val()-1,
							jQuery('#gg').val()
						);
				jQuery('#date-pick').dpSetSelected(d.asString());
			}
		);
	
	// default the position of the selects to today
	var today = new Date();
	(jQuery('#gg')[0]).selectedIndex = today.getDate() - 1;
	(jQuery('#mm')[0]).selectedIndex = today.getMonth();
	(jQuery('#aa')[0]).selectedIndex = today.getFullYear() - todayTmp.getFullYear();
	
	// and update the datePicker to reflect it...
	jQuery('#gg').trigger('change');



});