SimpleCalendar.ONE_SECOND = 1000;
SimpleCalendar.ONE_MINUTE = 60000;
SimpleCalendar.ONE_HOUR = 3600000;
SimpleCalendar.ONE_DAY = 86400000;

SimpleCalendar.JANUARY = 0;
SimpleCalendar.FEBRUARY = 1;
SimpleCalendar.MARCH = 2;
SimpleCalendar.APRIL = 3;
SimpleCalendar.MAY = 4;
SimpleCalendar.JUNE = 5;
SimpleCalendar.JULY = 6;
SimpleCalendar.AUGUST = 7;
SimpleCalendar.SEPTEMBER = 8;
SimpleCalendar.OCTOBER = 9;
SimpleCalendar.NOVEMBER = 10;
SimpleCalendar.DECEMBER = 11;
//SimpleCalendar.UNDECIMBER = 12;

SimpleCalendar.SUNDAY = 1;
SimpleCalendar.MONDAY = 2;
SimpleCalendar.TUESDAY = 3;
SimpleCalendar.WEDNESDAY = 4;
SimpleCalendar.THURSDAY = 5;
SimpleCalendar.FRIDAY = 6;
SimpleCalendar.SATURDAY = 7;

// Start of gregorian Calendar
SimpleCalendar.MINIMUM_YEAR = 1582;

function SimpleCalendar( dateToSet ) {
    if( arguments.length == 1 ) {
        this.calendarDate = dateToSet;
    } else {
        this.calendarDate = new Date();
    }
};

SimpleCalendar.prototype.getTime = function() {
    if( this.calendarDate == null ) {
        this.calendarDate = new Date();
    }
    return this.calendarDate;
};

SimpleCalendar.prototype.isMonthInRange = function( month ) {
    return month >= SimpleCalendar.JANUARY && month <= SimpleCalendar.DECEMBER;
};

SimpleCalendar.prototype.isYearSupported = function( year ) {
    return year >= SimpleCalendar.MINIMUM_YEAR;
};

SimpleCalendar.prototype.isLeapYear = function( year ) {
    var leap = false;
    if( this.isYearSupported( year ) ) {
        leap = ( (year%4 == 0) && ( (year%100 != 0) || (year%400 == 0) ) );
    }
    return leap;
};

SimpleCalendar.prototype.getDaysInMonth = function( month, year ) {
	var days = 0;
	if( arguments.length < 2 ) {
	    year = this.getTime().getFullYear();
	    if( arguments.length < 1 ) {
	        month = this.getTime().getMonth();
	    }
	}

	if( this.isMonthInRange( month) && this.isYearSupported( year ) ) {
		var leapYear = this.isLeapYear( year );
		var monthDays = new Array( 31,(leapYear?29:28),31,30,31,30,31,31,30,31,30,31 );
		days = monthDays[ month ];
	}
	return days;
};

SimpleCalendar.prototype.getDaysInYear = function( year ) {
    var days = 0;
    if( arguments.length == 0 ) {
        year = this.getTime().getFullYear();
    }
    if( this.isYearSupported( year ) ) {
        days = this.isLeapYear( year ) ? 366 : 365;
    }

    return days;
};

SimpleCalendar.prototype.getDayInYear = function() {
    var days = 0;

    for( var month = SimpleCalendar.JANUARY; month < this.getTime().getMonth(); month++ ) {
        days = days + this.getDaysInMonth( month );
    }
    days += this.getTime().getDate();

    return days;
};


SimpleCalendar.prototype.addDays = function( days ) {
    var currentTime = this.getTime();
    this.calendarDate = new Date( currentTime.getFullYear(), currentTime.getMonth(), currentTime.getDate() +  days );
    // month and year shifts should occure automatically, does this hold true for adding any amount of days ?
    //this.calendarDate.setDate( currentTime.getDate() + days );
};

SimpleCalendar.prototype.addMonths = function( months ) {
    var currentTime = this.getTime();
    this.calendarDate = new Date( currentTime.getFullYear(), currentTime.getMonth(), currentTime.getDate() );
    // do shifts occure automatically in setMonth(...) ?
    this.calendarDate.setMonth( currentTime.getMonth() + months );

    /*if( months > 0 ) {
        var currentTime = this.getTime();
        var currentYear = currentTime.getFullYear();
        var currentMonth = currentTime.getMonth();
        var nextMonth = currentMonth;
        var nextYear = currentYear;

        for( var i=1; i <= months; i++ ) {

            nextMonth = nextMonth + 1;

            if( nextMonth > SimpleCalendar.DECEMBER ) {
                // year shift
                nextYear = nextYear + 1;
                nextMonth = SimpleCalendar.JANUARY;
            }
            var daysToAdd = this.getDaysInMonth( nextMonth, nextYear );
            this.addDays( daysToAdd );
        }
    }*/
    //var currentTime = this.getTime();
    //this.calendarDate = new Date( currentTime.getFullYear(), currentTime.getMonth() + months , currentTime.getDate() );

};

