
// --- calendar.js

/*
 *
 *  This is the single file loader for the javascript calendar.
 *
 *  Users may include this file, it will pull all dependencies automatically.
 *
 *
 */


// define calendar package

var calendar = {
	Version         : '1.0',
	prototypeVersion: parseFloat(Prototype.Version.split(".")[0] + "." + Prototype.Version.split(".")[1])
}

// give IDEA some hints that we know what we are doing :)

/**
  * @namespace document.layers
  *
  * @namespace exception.name
  * @namespace exception.stack
  * @namespace console.debug
  *
  */


// force load all required libraries for using the javascript calendar

Object.extend(calendar, {
	require: function(libraryName) {
		// inserting via DOM fails in Safari 2.0, so brute force approach
		document.write('<script type="text/javascript" src="' + libraryName + '"></script>');
	},

	load: function() {
		var includes = [
				'Event',
				'Date',
				'Position',
				'RicoUtil',
				'stringutils/StringBuffer',
				'calendar/DefaultTextBehavior',
				'calendar/DefaultTextPlusComboBehavior',
				'calendar/Month',
				'calendar/Week',
				'calendar/Day',
				'calendar/MarkedDays',
				'calendar/MarkedDay',
				'calendar/CalendarGenerator',
				'calendar/Calendar'
				];

		$A(document.getElementsByTagName("script")).findAll(function( s ) {
            return (s.src && s.src.match(/prototype\.js$/))
        }).each(function( s ) {
            var path = s.src.replace(/prototype\.js$/, '');
            includes.each(
                    function( include ) {
                        calendar.require(path + include + '.js')
                    } );
        });
	}
});


calendar.load();


Event.observe(window, 'load', function() {
	if (calendar.prototypeVersion < 1.5) throw("calendar requires prototype 1.5");

	if (typeof(console) == 'undefined') {
		//alert("adding fake def for console.debug");
		console = {
			debug: function(msg) {
				var sval = msg;
				if (typeof(msg) == 'object') {
					sval = Object.toJSON(msg);
				}
				alert(sval);
			}
		};
	}
});
