jQuery(document).ready(function(){
	/*
	// nixing this - too much overhead
	
	// expand the posts for the current month
	var d = new Date();
	var month = d.getMonth();
	var year = d.getFullYear();
	
	month = str_pad(month+1, 2, "0", 'STR_PAD_LEFT');
	jQuery("#arrow_"+year+"-"+month).trigger("click");
	*/
});

function toggleYear(e, year){
	// icon swap first, so we can read the :visible
	if(!jQuery("#year_"+year+":visible").length){
		jQuery("img", e).attr("src", jQuery("img", e).attr("src").replace("_right", "_down"));
	}else{
		jQuery("img", e).attr("src", jQuery("img", e).attr("src").replace("_down", "_right"));
	}
	
	jQuery("#year_"+year).slideToggle("fast");
	e.blur();
}

// note: month should be a two-digit string (eg. "03" not 3)
function toggleMonth(e, year, month){
	var monthYear = year+"-"+month;
	var doToggle = true;
	// icon swap first, so we can read the :visible
	if(!jQuery("#month_"+monthYear+":visible").length){
		jQuery("img", e).attr("src", jQuery("img", e).attr("src").replace("_right", "_down"));
		// if we don't have blog posts, get via AJAX
		if(!jQuery("#month_"+monthYear+" li").length){
			doToggle  = false;
			jQuery.ajax({
				type: "POST",
				url: site_url+"ephemera/month_posts/"+year+"/"+month+"/",  // MUST HAVE TRAILING SLASH!
				cache: false,
				data: "",
				success: function(msg){
					jQuery("#month_"+monthYear).html(msg);
					jQuery("#month_"+monthYear).slideToggle("fast");
				}
			});
		}
	}else{
		jQuery("img", e).attr("src", jQuery("img", e).attr("src").replace("_down", "_right"));
	}
	
	if(doToggle) jQuery("#month_"+monthYear).slideToggle("fast");
	e.blur();
}

function str_pad( input, pad_length, pad_string, pad_type ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // + namespaced by: Michael White (http://getsprink.com)
    // *     example 1: str_pad('Kevin van Zonneveld', 30, '-=', 'STR_PAD_LEFT');
    // *     returns 1: '-=-=-=-=-=-Kevin van Zonneveld'
    // *     example 2: str_pad('Kevin van Zonneveld', 30, '-', 'STR_PAD_BOTH');
    // *     returns 2: '------Kevin van Zonneveld-----'
 
    var half = '', pad_to_go;
 
    var str_pad_repeater = function(s, len) {
        var collect = '', i;
 
        while(collect.length < len) {collect += s;}
        collect = collect.substr(0,len);
 
        return collect;
    };
 
    input += '';
 
    if (pad_type != 'STR_PAD_LEFT' && pad_type != 'STR_PAD_RIGHT' && pad_type != 'STR_PAD_BOTH') { pad_type = 'STR_PAD_RIGHT'; }
    if ((pad_to_go = pad_length - input.length) > 0) {
        if (pad_type == 'STR_PAD_LEFT') { input = str_pad_repeater(pad_string, pad_to_go) + input; }
        else if (pad_type == 'STR_PAD_RIGHT') { input = input + str_pad_repeater(pad_string, pad_to_go); }
        else if (pad_type == 'STR_PAD_BOTH') {
            half = str_pad_repeater(pad_string, Math.ceil(pad_to_go/2));
            input = half + input + half;
            input = input.substr(0, pad_length);
        }
    }
 
    return input;
}