// vim:set ts=8 sw=8 noet:
var tl;
function onLoad(timeline) {
	if (!timeline.length){
		return false;
	}
	timeline.css('height', '200px');
	var eventSource = new Timeline.DefaultEventSource(0);

	// Example of changing the theme from the defaults
	// The default theme is defined in
	// http://simile-widgets.googlecode.com/svn/timeline/tags/latest/src/webapp/api/scripts/themes.js
	var d = Timeline.DateTime.parseGregorianDateTime(timeline.attr('date'));
	var bandInfos = [
		Timeline.createBandInfo({
			width:          "70%",
			intervalUnit:   Timeline.DateTime.WEEK,
			intervalPixels: 200,
			eventSource:    eventSource,
			date:           d,
			layout:         'original'  // original, overview, detailed
		}),
		Timeline.createBandInfo({
			width:          "15%",
			showEventText:  false,
			trackHeight:    0.5,
			trackGap:       0.2,
			intervalUnit:   Timeline.DateTime.MONTH,
			intervalPixels: 150,
			eventSource:    eventSource,
			date:           d,
			layout:         'overview'  // original, overview, detailed
		}),
		Timeline.createBandInfo({
			width:          "15%",
			intervalUnit:   Timeline.DateTime.YEAR,
			intervalPixels: 150,
			eventSource:    eventSource,
			date:           d,
			layout:         'overview',
			showEventText:  false,
			trackHeight:    0.5,
			trackGap:       0.2,
		})
	];
	bandInfos[1].syncWith  = bandInfos[2].syncWith  = 0;
	bandInfos[1].highlight = bandInfos[2].highlight = true;

	SimileAjax.History.enabled = false;
	tl = Timeline.create(timeline[0], bandInfos, Timeline.HORIZONTAL);
	// Adding the date to the url stops browser caching of data during testing or if
	// the data source is a dynamic query...
	tl.loadJSON('timeline.js', function(json, url) {
		eventSource.loadJSON(json, url);
	});
}

var resizeTimerID = null;
$(window).resize(function() {
    if (resizeTimerID == null) {
        resizeTimerID = window.setTimeout(function() {
            resizeTimerID = null;
            tl.layout();
        }, 500);
    }
});

$(function (){

	// open external links in new window
	$('a[rel="external"]').click(function(){
		window.open($(this).attr('href'));
		return false;
	});

        onLoad($('#timeline'));

});

