// window load function - this currently sets up the login dialog
$(function() 
{
	// set up the login dialog
	$("#dlgLogin").dialog(
	{
		bgiframe: true,
		autoOpen: false,
		modal: true,
		buttons: {
			'Log in': function() { document.frmLogin.submit(); },
			Cancel: function() 
			{
				$(this).dialog('close');
			}
		},
		close: function() {
		},
		resizable:false
	});
});

// function used for toggling blog years
function toggleBlogYear(year)
{
	var liYear = $('#blog_year_' + year);
	var liMonths = $('.blog_month_' + year);

	// check to see if there are any months loaded - if not we need to fire off an ajax query
	if (liMonths.length == 0)
	{
		liYear.after('<li class="blog_month blog_month_' + year + '"><span>Loading...</span></li>');
		$.ajax({
			type: "GET",
			url: "services/get_blog_months.php",
			data: "year=" + year,
			success: function(msg)
			{
				$('.blog_month_' + year).remove();
				liYear.after(msg);
				
				// highlight the selected month
				var month = $('#month').attr('value');
				if (month.length > 0)
				{
					var selMon = $('#blog_year_' + year + '_' + month);
					//selMon.css('background-color', 'red');//
					selMon.addClass('blog_month_selected');
				}
				
			}
		});
		
	}
	else
	{
		liMonths.toggle();
	}
	
	// update the background image of the clicked year
	var aYear = $('#ba_' + year);
	var aYearBg = aYear.css('backgroundImage');
	if (aYearBg.indexOf('arrowd') == -1)
		aYear.css('backgroundImage', aYearBg.replace('arrowr', 'arrowd'));
	else
		aYear.css('backgroundImage', aYearBg.replace('arrowd', 'arrowr'));
}			
