// JavaScript Document

Timeline.DefaultEventSource.Event.prototype.fillInfoBubble = function(elmt,theme,labeller){
	var doc=elmt.ownerDocument;
	
	var title=this.getText();
	var link=this.getLink();
	var image=this.getImage();

	if(image!=null){
		var img=doc.createElement("img");
		img.src=image;
		
		theme.event.bubble.imageStyler(img);
		elmt.appendChild(img);
	}

	var divTitle=doc.createElement("div");
	var textTitle=doc.createTextNode(title);
	if(link!=null){
		var a=doc.createElement("a");
		a.href=link;
		a.target = '_blank';
		a.appendChild(textTitle);
		divTitle.appendChild(a);
	}else{
		divTitle.appendChild(textTitle);
	}
	theme.event.bubble.titleStyler(divTitle);
	elmt.appendChild(divTitle);
	
	var divTime=doc.createElement("div");
	this.fillTime(divTime,labeller);
	theme.event.bubble.timeStyler(divTime);
	elmt.appendChild(divTime);
	
	var divBody=doc.createElement("div");
	this.fillDescription(divBody);
	theme.event.bubble.bodyStyler(divBody);
	elmt.appendChild(divBody);
	
	var divWiki=doc.createElement("div");
	this.fillWikiInfo(divWiki);
	theme.event.bubble.wikiStyler(divWiki);
	elmt.appendChild(divWiki);
};




Timeline.DefaultEventSource.Event.prototype.fillTime = function(elmt, labeller) {
    if (this._instant) {
		if (this.isImprecise()) {
			elmt.appendChild(elmt.ownerDocument.createTextNode((this._start).getUTCFullYear()));
			elmt.appendChild(elmt.ownerDocument.createTextNode(" - "));
			elmt.appendChild(elmt.ownerDocument.createTextNode((this._end).getUTCFullYear()));
		} else {
			elmt.appendChild(elmt.ownerDocument.createTextNode((this._start).getUTCFullYear()));
		}
	} else {
		if (this.isImprecise()) {
			elmt.appendChild(elmt.ownerDocument.createTextNode(
				(this._start).getUTCFullYear() + " ~ " + (this._latestStart).getUTCFullYear()));
			elmt.appendChild(elmt.ownerDocument.createTextNode(" - "));
			elmt.appendChild(elmt.ownerDocument.createTextNode(
				(this._earliestEnd).getUTCFullYear() + " ~ " + (this._end).getUTCFullYear()));
		} else {
			elmt.appendChild(elmt.ownerDocument.createTextNode((this._start).getUTCFullYear()));
			elmt.appendChild(elmt.ownerDocument.createTextNode(" - "));
			elmt.appendChild(elmt.ownerDocument.createTextNode((this._end).getUTCFullYear()));
		}
	}
};


var tl;
//------------- Modified Script----------------- >
		function centerTimeline(year) {
            tl.getBand(0).setCenterVisibleDate(new Date(year, 0, 1));
        }
        
        function getqueryString(qName) {
				fullURL = window.location.search.substring(1);
				splitpart = fullURL.split("&");
				for (i=0;i<splitpart.length;i++) {
				qsty = splitpart[i].split("=");
				if (qsty[0] == qName) {
				return qsty[1];
				}
				}
				}
//------------ End Modified -------------------- >
function onLoad() {
  var eventSourceDeans = new Timeline.DefaultEventSource();
  var eventSourceLaw = new Timeline.DefaultEventSource();
  var eventSourceHistory = new Timeline.DefaultEventSource();
  var eventSourceAll = new Timeline.DefaultEventSource();
  
  var theme = Timeline.ClassicTheme.create();
  theme.event.bubble.width = 320;
  theme.event.bubble.height = 220;
  theme.ether.backgroundColors = [
  	"#FFF1CE",
    "#FFEBB4",
    "#E8E8F4",
	"#000000",
    "#D0D0E8"
  ];
  theme.event.duration.color = "#41404E";
  theme.ether.interval.line.color = "#757575";
  theme.ether.interval.marker.hAlign = "Top";

  var theme2 = Timeline.ClassicTheme.create();
  theme2.event.bubble.width = 320;
  theme2.event.bubble.height = 220;
  theme2.ether.backgroundColors = [
  	"#D1CECA",
    "#E7DFD6",
    "#E8E8F4",
	"#000000",
    "#D0D0E8"
  ];
  theme2.event.duration.color = "#014582";
  theme2.ether.interval.line.color = "#757575";
  theme2.ether.interval.marker.vAlign = "Left";

  var theme3 = Timeline.ClassicTheme.create();
  theme3.ether.backgroundColors = [
  	"#D1CECA",
    "#E7DFD6",
    "#E8E8F4",
	"#616161",
    "#D0D0E8"
  ];
  theme3.ether.interval.line.color = "#616161";
  theme3.ether.interval.marker.hAlign = "Top";

  
  var d = "Jan 1 1861 00:00:00 GMT";
  
  var bandInfos = [
    Timeline.createBandInfo({
        eventSource:    eventSourceDeans,
        date:           d,
        width:          "15%", 
        intervalUnit:   Timeline.DateTime.YEAR, 
        intervalPixels: 100,
        theme:          theme        
    }),
	Timeline.createBandInfo({
        eventSource:    eventSourceLaw,
        date:           d,
        width:          "35%", 
        intervalUnit:   Timeline.DateTime.YEAR, 
        intervalPixels: 100,
        theme:          theme
    }),
    Timeline.createBandInfo({
        eventSource:    eventSourceHistory,
        date:           d,
        width:          "35%", 
        intervalUnit:   Timeline.DateTime.YEAR, 
        intervalPixels: 100,
        theme:          theme2
    }),
    Timeline.createBandInfo({
        date:           d,
        width:          "1%", 
        intervalUnit:   Timeline.DateTime.YEAR, 
        intervalPixels: 100,
        theme:          theme3
    }),
	Timeline.createBandInfo({
        showEventText:  false,
        trackHeight:    0.5,
        trackGap:       0.2,
        eventSource:    eventSourceAll,
        date:           d,
        width:          "14%", 
        intervalUnit:   Timeline.DateTime.DECADE, 
        intervalPixels: 50,
        theme:          theme2
    })
  ];
  bandInfos[1].syncWith = 0;

  bandInfos[2].syncWith = 0;

  bandInfos[4].syncWith = 0;
  bandInfos[4].highlight = true;
  
  tl = Timeline.create(document.getElementById("my-timeline"), bandInfos);
  Timeline.loadXML("/historyandtraditions/timeline/Documents/eventSourceDeans.xml", function(xml, url) { eventSourceDeans.loadXML(xml, url); });
  Timeline.loadXML("/historyandtraditions/timeline/Documents/eventSourceLaw.xml", function(xml, url) { eventSourceLaw.loadXML(xml, url); });
  Timeline.loadXML("/historyandtraditions/timeline/Documents/eventSourceHistory.xml", function(xml, url) { eventSourceHistory.loadXML(xml, url); });
  Timeline.loadXML("/historyandtraditions/timeline/Documents/eventSourceAll.xml", function(xml, url) { eventSourceAll.loadXML(xml, url); });
  
  //----------------Modified -----------
  getEventID = getqueryString("EventYear");
	  if (getEventID==null){
	  	centerTimeline(1861);
	  }else if (getEventID==""){
		centerTimeline(1861);
	  }else{
	  	centerTimeline(getEventID);	
	  }
   //---------------End Modified ----------	  
  }
  
  _spBodyOnLoadFunctionNames.push("onLoad");