var dateObj=new Date();
var month=dateObj.getMonth();
var year=dateObj.getFullYear();
var monthName='';
$(document).ready(function(){
    $.getJSON("/execplugin/?plg=events&plugFunc=calendar_get_days", {}, function(data){
        month=data['month'];
        year=data['year'];
        monthName=data['monthName'];
        var html=TrimPath.processDOMTemplate("calendar_tpl", data);
        $("#calendar_output").html(html);
    });

$("#calendar #ago").live("click", function(){
    $.getJSON("/execplugin/?plg=events&plugFunc=calendar_get_days", {month:parseInt(month)-1, year:year}, function(data){
        month=data['month'];
        year=data['year'];
        monthName=data['monthName'];
        var html=TrimPath.processDOMTemplate("calendar_tpl", data);
        $("#calendar_output").html(html);
    });
    return false;
});

$("#calendar #ahead").live("click", function(){
    $.getJSON("/execplugin/?plg=events&plugFunc=calendar_get_days", {month:parseInt(month)+1, year:year}, function(data){
        month=data['month'];
        year=data['year'];
        monthName=data['monthName'];
        var html=TrimPath.processDOMTemplate("calendar_tpl", data);
        $("#calendar_output").html(html);
    });
    return false;
});

$("#calendar a").live("click", function(){return false;});

$("#calendar tr:gt(1) a[class]").live("click", function(){
    $.getJSON("/execplugin/?plg=events&plugFunc=getDayEvents", {year:year, month:month, day:$(this).text()}, function(data){
        $("#content").html(TrimPath.processDOMTemplate("events_tpl", data));
    });
    return false;
});
    
});
