/**
 * JavaScript support for the main world enough timeline 
 * (c) Simon Brooke 2007
 *
 * $Revision: 1.7 $
 *
 */

/*
 * $Log$
 */

/**
 * Called on page load to instantiate the timeline in the first place.
 * return the timeline object.
 */

function setupTimeline() 
{
	var eventSource = new Timeline.DefaultEventSource();
	var bandInfos = [
    			Timeline.createBandInfo({
    	    		eventSource:    eventSource,
        			date:           "Jun 28 2006 00:00:00 GMT",
        			width:          "50%", 
        			intervalUnit:   Timeline.DateTime.MONTH, 
        			intervalPixels: 400}),
    			Timeline.createBandInfo({
        			eventSource:    eventSource,
        			date:           "Jun 28 2006 00:00:00 GMT",
        			width:          "50%", 
        			intervalUnit:   Timeline.DateTime.YEAR, 
        			intervalPixels: 200})
  				];
	bandInfos[1].syncWith = 0;
	bandInfos[1].highlight = true;
	var timeline = Timeline.create(document.getElementById("timelinediv"), bandInfos);
	timeline.eventSource = eventSource;

	/* highjack the timeline bubble pop-up - thanks to joern@techfak.uni-bielefeld.de */
    Timeline.DurationEventPainter.prototype._showBubble = 
    	function(x, y, evt) 
    	{
    		var marker = evt.mapmarker;
    		map.closeInfoWindow();
       		map.panTo( marker.getPoint());
       		map.openInfoWindowHtml( marker.getPoint(), marker.content);
		}
		
	return timeline;
}

var resizeTimerID = null;
		
function onResize() 
{
	if (resizeTimerID == null) 
	{
   		resizeTimerID = window.setTimeout(
   			function() 
   			{
       			resizeTimerID = null;
       			timeline.layout();
   			}, 500);
	}
}

/**
 * centres timeline on selected date
 */
function centerTimeline(date) 
{
   	timeline.getBand(0).setCenterVisibleDate(Timeline.DateTime.parseGregorianDateTime(date));
}