PathwayBrowser = function () {};

Object.extend(PathwayBrowser.prototype, {
	
	pathwayDiagramPane : null,
	eventHierarchyPane : null,
	detailsPane : null,
	searchResults : null,
	tabView : null,
	lastSearchResults : null,
	default_focus_species_id : 48887,
	db : null,
	focus_pathway_id : null,
	current_instance_id : null,

	loadAndProcessDataUrl : '/cgi-bin/entitylevelview/pathwaybrowserdata',
    pathwayLoadedEvent : new YAHOO.util.CustomEvent(
        "pathwayLoadedEvent", this),
    
    new_current_instance_id : 0,
	
	setViewerSize: function() {
	    var oClipwindow   = $("clipwindow");
	    var leftpanel = $("leftpanel");
	    var details = $("details");
	    var availableHeight = YAHOO.util.Dom.getViewportHeight() - 13 - Position.cumulativeOffset(oClipwindow)[1];
	    // 4 is the height of the little triangle for opening/closing details
	    var clipHeight;
	    /*
	     * Tabs in leftpanel are slightly smaller to allow room for scroll bars.
	     */
	    var tabHeight;
	    var tabHeightOffset = 60;
	    if ((details != null) && details.visible()) {
	    	details.style.height = Math.floor(availableHeight * 0.4) + "px";
	    	clipHeight = (Math.ceil(availableHeight * 0.6) - 4) + "px";
	    	tabHeight = (Math.ceil(availableHeight * 0.6) - tabHeightOffset) + "px";
            this.pathwayDiagramPane.resetExpressionKey(0.7);
	    } else {
	    	clipHeight = (availableHeight - 4) + "px";
	    	tabHeight = (availableHeight - tabHeightOffset) + "px";
            this.pathwayDiagramPane.resetExpressionKey(1);
	    }
	    oClipwindow.style.height = clipHeight;
	    this.pathwayDiagramPane.positionThumbnail();
	    if (leftpanel != null) {
<<<<<<< PathwayBrowser.js
	        leftpanel.style.height = clipHeight;
	    }       
=======
	        //leftpanel.style.height = clipHeight;
	    	leftpanel.style.height = clipHeight;
	        leftpanel.style.overflow = "hidden";
	    }   
	    
	    /*
	     * Set up tabs for scroll bar
	     */
	    var hierarchyTab = $("hierarchytab");
    	hierarchyTab.className += " leftpaneltab";
    	hierarchyTab.style.height = tabHeight;
	    
	    var searchResultsTab = $("searchresultstab");
	    searchResultsTab.className += " leftpaneltab";
	    searchResultsTab.style.height = tabHeight;
	    
	    var helpTab = $("helptab");
	    helpTab.className += " leftpaneltab";
	    helpTab.style.height = tabHeight;
	    
	    var pos = Position.cumulativeOffset(document.getElementById("leftpaneltogglerplaceholder"));
        this.placeToggleArrow(pos[0], pos[1], "leftpaneltogglercontainer", "leftpaneltoggler");

        pos = Position.cumulativeOffset(document.getElementById("detailstogglerplaceholder"));
        this.placeToggleArrow(pos[0], pos[1] -6, "detailstogglercontainer", "detailstoggler");

	},
		
	initDisplayExpressionLevels: function(){
		 var details = $("details");
		 if((details != null ) && details.visible()){
			this.pathwayDiagramPane.initDisplayExpressionLevels(0.7);
		 }else{
			this.pathwayDiagramPane.initDisplayExpressionLevels(1);
		 }
>>>>>>> 1.29
	},
	
	
	
	handleClickOnSearchResult: function (e, rid) {
		//log("handleClickOnSearchResult\t" + rid);
		this.loadAndProcessData(rid,false);


	},
	resize : function() {
		this.setViewerSize();
		this.pathwayDiagramPane.reposition(0,0);
	},
	handleToggleLeftPanel: function(event) {
		this.toggleLeftPanel();
	},
	toggleLeftPanel: function() {
	    var l = Position.cumulativeOffset($('clipwindow'))[0];
	    var n = $($('leftpanel').parentNode);
	    n.toggle();
	    var el = $('leftpaneltoggler');
	    if (n.visible()) {
			el.src = "/icons/hide-arrow.png";
			el.setStyle({position: 'relative', left: '0px'});
	    } else {
			el.src = "/icons/show-arrow.png";
			el.setStyle({position: 'absolute', left: '0px'});
	    }
<<<<<<< PathwayBrowser.js
=======
	    var pos = Position.cumulativeOffset(document.getElementById("leftpaneltogglerplaceholder"));
        this.placeToggleArrow(pos[0], pos[1], "leftpaneltogglercontainer", "leftpaneltoggler");
>>>>>>> 1.29
	    var canvas = $('canvas');
	    canvas.setStyle({left: (parseInt(canvas.style.left) + (l - Position.cumulativeOffset($('clipwindow'))[0]))+'px'});
	    this.pathwayDiagramPane.reposition(0,0);
<<<<<<< PathwayBrowser.js
	    this.pathwayDiagramPane.placeExperimentBrowser();
=======
	    if(this.pathwayDiagramPane.paintExpressionData){
	    	this.pathwayDiagramPane.placeExperimentBrowser();
	    }/*else if(this.pathwayDiagramPane.speciesComparator!= null && this.pathwayDiagramPane.speciesComparator.displayComparison==1){
	    	this.pathwayDiagramPane.placeSpeciesComparisonPanel();
	    }*/
	    else if(this.pathwayDiagramPane.displayComparison==1){
	    	if(this.pathwayDiagramPane.speciesdata){
	            this.pathwayDiagramPane.placeSpeciesComparisonPanel(this.pathwayDiagramPane.speciesdata.name); 
	    	}else{
	    		this.pathwayDiagramPane.placeSpeciesComparisonPanel();
	        } 
	    }
>>>>>>> 1.29
	},
	toggleDetails: function() {
	    var n = $('details');
	    n.toggle();
	    var el = $('detailstoggler');
	    if (n.visible()) {
			el.src = "/icons/hide-arrow-v.png";
			//el.setStyle({position: 'relative', top: '0px'});
	    } else {
			el.src = "/icons/show-arrow-v.png";
			//el.setStyle({position: 'absolute', bottom: '0px'});
	    }
		this.setViewerSize();
		this.pathwayDiagramPane.reposition(0,0);
	},
	processTitle: function(title) {
	    if (title) {
			document.title = title;
	    }
	},
	changeFocusPathway : function (pathway_id) {
		if (this.focus_species_id != null) {
			this.focus_pathway_id = pathway_id;	
			this.eventHierarchyPane.focus_pathway_id = pathway_id;
			this.pathwayDiagramPane.changeFocusPathway(pathway_id);
		}
	},
	updateLocationHref: function() {
		var i = document.location.href.indexOf("#");
		var href = document.location.href;
		if (i != -1) {
			href = href.substring(0,i);
		}
		href += "#DB=" + this.db + "&FOCUS_SPECIES_ID=" + this.focus_species_id;
		if (this.focus_pathway_id) href += "&FOCUS_PATHWAY_ID=" + this.focus_pathway_id;
		if (this.current_instance_id) href += "&ID=" + this.current_instance_id;
		document.location.href = href;
	},
	setDBandFocusSpecies: function() {
	    var params = this.extractParamsFromURI();
	    var db = '';
	    if (params['DB'] && (typeof(params['DB']) == 'string')) {
			db = params['DB'];
	    } else {
			var cv = getCookie('DB');
			if (cv) {
			    db = cv;
			}
	    }
	    this.setDB(db);
	    var focus_species_id;
	    if (params['FOCUS_SPECIES_ID'] && (typeof(params['FOCUS_SPECIES_ID']) == 'string')) {
	    	focus_species_id = params['FOCUS_SPECIES_ID'];
			
	    } else {
			var cv = getCookie('FOCUS_SPECIES_ID');
			if (cv) {
			    focus_species_id = cv;
			} else {
				// NOTE
				// Hopefully a reasonable default for the time being.
				focus_species_id = this.default_focus_species_id;
			}
	    }
	    this.setFocusSpecies(focus_species_id);
	},
	createLeftPanelTabs: function() {
		this.tabView = new YAHOO.widget.TabView('leftpanel');
	},
	init: function() {
		this.pathwayDiagramPane = new PathwayDiagramPane();
		this.eventHierarchyPane = new EventHierarchyPane();
		this.detailsPane = new DetailsPane();		
		// This has to happen before init_query_autocomplete as otherwise autocompleter wouldn't know the db.
		this.setDBandFocusSpecies();		
		//This has to happen early as doing it somehow makes the search bar lower
<<<<<<< PathwayBrowser.js
//		this.init_query_autocomplete();
	//	var queryHandled = this.handleQueryInURI();
		
=======
		this.init_query_autocomplete();
>>>>>>> 1.20
		this.setViewerSize();
		
		this.createLeftPanelTabs();
		this.init_handlers();	
		this.pathwayDiagramPane.init();
		this.eventHierarchyPane.initSpeciesList();
		this.eventHierarchyPane.newSpeciesTreeLoadedEvent.subscribe(this.onNewSpeciesTreeLoaded.bind(this), this);
		this.eventHierarchyPane.buildEventHierarchy();
		this.eventHierarchyPane.treeNodeClickEvent.subscribe(this.onTreeNodeClick.bind(this), this);
		this.eventHierarchyPane.treeTrunkLoadedEvent.subscribe(this.onTreeTrunkLoaded.bind(this), this);
		this.pathwayDiagramPane.diagramNodeClickedEvent.subscribe(this.onDiagramNodeClick.bind(this), this);
		// Menuitem clicked event for right-click menus. Used for other pathways functionality
        this.pathwayDiagramPane.menuItemClickedEvent.subscribe(this.onMenuItemClick.bind(this), this);
		this.detailsPane.internalLinkClickEvent.subscribe(this.onInternalLinkClick.bind(this), this);
		this.eventHierarchyPane.treeNodeMouseOverEvent.subscribe(
				this.pathwayDiagramPane.onTransientHighliteRequest.bind(this.pathwayDiagramPane)
		);
		this.eventHierarchyPane.treeNodeMouseOutEvent.subscribe(
				this.pathwayDiagramPane.onTransientHighliteRemovalRequest.bind(this.pathwayDiagramPane)
		);
        this.disableContextMenu(document.getElementById("clipwindow"));
        if (! this.handleQueryInURI()) {
			this.toggleDetails();
		}
        this.tweakNavigationBarLinks();
<<<<<<< PathwayBrowser.js
=======
        // If we are coming to the ELV from the expression analysis page, set up a handler
        // to request and process expression data from the server.
        this.pathwayDiagramPane.diagramLoadedEvent.subscribe(
				this.diagramLoadedEventHandler
						.bind(this),
				this);
      
        var pos = Position.cumulativeOffset(document.getElementById("leftpaneltogglerplaceholder"));
        this.placeToggleArrow(pos[0], pos[1], "leftpaneltogglercontainer", "leftpaneltoggler");
	},
	/*
	 * Toggle arrows are used to hide/show event hierarchy and details pane.
	 */
	placeToggleArrow: function(x,y, placeHolderId, arrowId){
	   // Place hide arrow for left panel      
	   var hidearrowcontainer = document.getElementById(placeHolderId);
       if(hidearrowcontainer){
    	   
        // Set style directly. In IE, object returned does not have setStyle method (but does have style
    	   // property).
		hidearrowcontainer.style.top = y + "px";
		hidearrowcontainer.style.left = x + "px";
		}	
	},
	
	/*
	 * When the diagram has loaded, check is expression painting or species comparison mode
	 * is enabled. If so, retrieve relevant data from the server and paint the overlays.
	 * Used when user arrives at ELV from expression analysis/species comparison page.
	 * Diagram has to be loaded first so that necessary objects are initialized before trying to
	 * paint overlays.
	 */
	diagramLoadedEventHandler : function(){
        var callback = {
				scope : this,
				customevents : {
					onSuccess : function(eventType, args) {
						var data = eval('(' + args[0].responseText + ')');
						if(data.action == "compare"){
							
							this.pathwayDiagramPane.getComplexComponentsForSpeciesComparison(data);
						}else if(data.action == "exp"){
							this.pathwayDiagramPane.expressionPainter.expressionCallback(args[0].responseText);
							this.setViewerSize();
							this.initDisplayExpressionLevels();
						}
					},
					onFailure : function(eventType, args) {
						alert("Failed to receive data when processing exp painter or species comparison");
					}
				}
		};
        // Check if we need to repaint expression data when switching pathways.
        if(this.pathwayDiagramPane.paintExpressionData == 1){
        	var postUrl =
        		"/ReactomeGWT/entrypoint/elv/ExpressionVisualizerServlet";
                     
        	YAHOO.util.Connect.asyncRequest("POST", postUrl, 
                    		 callback, "FOCUS_PATHWAY_ID=" + this.focus_pathway_id);
        }/*else if (this.pathwayDiagramPane.speciesComparator.displayComparison == 1){*/
        else if (this.pathwayDiagramPane.displayComparison == 1){
        	var getUrl =
        		"/ReactomeGWT/entrypoint/elv/SpeciesComparisonServlet?pathwayid=" + this.focus_pathway_id
        		+ "&ospeciesid=" + this.pathwayDiagramPane.otherSpeciesDbId;
        	YAHOO.util.Connect.asyncRequest("GET", getUrl, 
                    		 callback);
        }
<<<<<<< PathwayBrowser.js
>>>>>>> 1.20
=======
		/* new_current_instance_id is used as a flag to indicate to the elv that the other pathways feature was selected
		  by the user and now that the diagram is loaded, call onPathwayLoaded to scroll/select the user selected node.

		*/
		else if(this.new_current_instance_id != null){
			this.onPathwayLoaded();
		}
>>>>>>> 1.29
	},
	
	
	init_query_autocomplete: function() {
		log("init_query_autocomplete()");
		var maxResultsDisplayed = 20;
		this.oACDS = new YAHOO.widget.DS_XHR("/cgi-bin/entitylevelview/searchtermautocomplete", ["\n", "\t"]);
		this.oACDS.scriptQueryParam = "QUERY";
		this.oACDS.scriptQueryAppend = "DB=" + this.db + "&MAXROWS=" + maxResultsDisplayed;
	    this.oACDS.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
	    this.oACDS.maxCacheEntries = 0;
	    this.oACDS.queryMatchSubset = false;
	
	    this.oAutoComp = new YAHOO.widget.AutoComplete('query','querycontainer', this.oACDS);
	    this.oAutoComp.prehighlightClassName = "yui-ac-prehighlight";
	    this.oAutoComp.typeAhead = false;
	    this.oAutoComp.useShadow = true;
	    this.oAutoComp.minQueryLength = 2;
	    this.oAutoComp.maxResultsDisplayed = maxResultsDisplayed;
	    this.oAutoComp.queryDelay = 1; 
	    this.oAutoComp.formatResult = function(oResultItem, sQuery) {
	    	sQuery = decodeURIComponent(sQuery);
	   		sQuery = sQuery.replace(/\*/g, "");
	   		sQuery = '(' + sQuery + ')';
	    	var re = new RegExp(sQuery, "gi");
	        var sMarkup = oResultItem[0];
	        sMarkup = sMarkup.replace(re, "<span class=\"hl-substr-1\">$1</span>");
	        return (sMarkup);
	    };
	    // Need to specify the focus species
	    var t = this;
	    this.oAutoComp.doBeforeSendQuery = function(sQuery) {
	    	
	    	if (t.focus_species_id != null) 
	    		sQuery += "&FOCUS_SPECIES_ID=" + t.focus_species_id;
	    	log("doBeforeSendQuery(): " + sQuery);
	    	return sQuery;
	    };
	},
	tweakNavigationBarLinks: function() {
		var e = $("productsandservices");
		if (e) {
			var links = e.getElementsBySelector('a');
			var re = new RegExp("DB=\\w+");
	    	for (var i = 0, l = links.length; i < l; ++i) {
				var href = links[i].readAttribute('href');
				if (href) {
					href = href.replace(re, "DB="+this.db);
					links[i].setAttribute("href",href);
				}
	    	}
		}
	},
	goToOldUI: function() {
		var loc;
		if ((this.current_instance_id != null) && (this.current_instance_id != this.focus_species_id)) {
			loc = '/cgi-bin/eventbrowser?DB=' + this.db + '&ID=' + this.current_instance_id + '&FOCUS_SPECIES_ID=' + this.focus_species_id;
		} else {
			loc = '/cgi-bin/frontpage?DB=' + this.db + '&FOCUS_SPECIES_ID=' + this.focus_species_id;
		}
		window.location = loc;
	},
	init_handlers: function() {
		var t = this;
	    if ($('mapsearchform')) {
			Event.observe('mapsearchform', 'submit', this.handleMapsearchform.bindAsEventListener(this));
			Event.observe('querysubmitbutton', 'click', this.handleMapsearchform.bindAsEventListener(this));
	    }
	    Event.observe(window, 'resize', this.resize.bindAsEventListener(this));
	    Event.observe('leftpaneltoggler','mousedown',this.handleToggleLeftPanel.bindAsEventListener(this));
	    Event.observe('detailstoggler','mousedown',this.toggleDetails.bindAsEventListener(this));
<<<<<<< PathwayBrowser.js
=======
	    Event.observe('detailstoggler','mouseover',this.highliteToggleDetails.bindAsEventListener(this));
	    Event.observe('detailstoggler','mouseout',this.hidehighliteToggleDetails.bindAsEventListener(this));
	    
	    YAHOO.util.Event.addListener('specieslistdropdown', 'change',
				this.speciesSelectorChange, this, true);
	},
	/*
	 * This list below adds/hides highlights for the toggle arrows.
	 */
	highliteToggleDetails : function(){		
		$("detailstoggler").style.border="3px solid rgb(59,253,50)";
	},
	hidehighliteToggleDetails : function(){
		$("detailstoggler").style.border="";
	},

	highliteToggleLeftPanel: function(){
		$("leftpaneltoggler").style.border="3px solid rgb(59,253,50)";
	},
	hidehighliteToggleLeftPanel: function(){
		$("leftpaneltoggler").style.border="";		
>>>>>>> 1.20
	},
	/*
	 * end toggle highlight routines
	 */
	extractParamsFromURI: function() {
		var uri = String(document.location);
		var fragment = uri.substring(uri.indexOf("#")+1,uri.length);
		var params = fragment.toQueryParams();
		return params;
	},
	handleQueryInURI: function() {
		var params = this.extractParamsFromURI();
		// Z = set the zoom level
	    if (params['Z'] && (typeof(params['Z']) == 'string')) {
			this.pathwayDiagramPane.z = params['Z'];
			this.pathwayDiagramPane.zoomChange.fire(this.pathwayDiagramPane.z);
		}
<<<<<<< PathwayBrowser.js
	    if(params['REACTOME_GWT']){
=======
	    if(params['DATA_TYPE'] == "Expression"){
>>>>>>> 1.20
	    	this.pathwayDiagramPane.paintExpressionData = 1;
	    }
<<<<<<< PathwayBrowser.js

=======
	    if(params['DATA_TYPE'] == "SpeciesComparison"){
<<<<<<< PathwayBrowser.js
	    	this.pathwayDiagramPane.speciesComparator.displayComparison = 1;
	    	this.pathwayDiagramPane.speciesComparator.otherSpeciesDbId = params['OTHER_SPECIES_DB_ID'];
	    }
>>>>>>> 1.20
=======
	    	/*this.pathwayDiagramPane.speciesComparator.displayComparison = 1;
	    	this.pathwayDiagramPane.speciesComparator.otherSpeciesDbId = params['OTHER_SPECIES_DB_ID'];*/

	    	this.pathwayDiagramPane.otherSpeciesDbId = params['OTHER_SPECIES_DB_ID'];
	    	if(this.pathwayDiagramPane.otherSpeciesDbId == undefined){
	    		alert("Could not identify species to compare against.");
			
	    	} else {
	    		this.pathwayDiagramPane.displayComparison = 1;
	    	}
	}
>>>>>>> 1.29
	    if (params['FOCUS_PATHWAY_ID'] && (typeof(params['FOCUS_PATHWAY_ID']) == 'string')) {	    	
	    	this.changeFocusPathway(params['FOCUS_PATHWAY_ID']);
	    }
	    /*if (params['ID'] && (typeof(params['ID']) == 'string')) {
	    	log("params[ID]=" + params['ID']);
			this.loadAndProcessData(params['ID'], true);
			return true;
	    } else*/ if (this.focus_pathway_id) {
	    	log("this.focus_pathway_id=" + this.focus_pathway_id);
	    	this.loadAndProcessData(this.focus_pathway_id, true);
	    	return true;
	    }
	   
	    return false;
	},
	setFocusSpecies : function (focus_species_id) {
		this.previousSpeciesId = this.focus_species_id;
		this.focus_species_id = focus_species_id;
		this.pathwayDiagramPane.focus_species_id = focus_species_id;
		this.eventHierarchyPane.focus_species_id = focus_species_id;
		this.detailsPane.focus_species_id = focus_species_id;
	},
	getCurrentFINodes : function(){
		return this.pathwayDiagramPane.getCurrentFINodes();
	},
	displayFIOverlay: function(node, json){
	    this.pathwayDiagramPane.displayFIOverlay(node, json);
	},
	clearFIOverlay:function(){
	    this.pathwayDiagramPane.clearFIOverlay();
	},
	displayControlPanel: function(){
	    this.pathwayDiagramPane.displayControlDialog();
	},
	applyConfidenceColours: function(confthreshold, exceedColour, belowColour){
	    this.pathwayDiagramPane.applyConfidenceColours(confthreshold, exceedColour, belowColour);
	},
	resetColours:function(){
	    this.pathwayDiagramPane.resetColours();
	},
	setDB: function (db) {
		this.db = db;
		this.pathwayDiagramPane.db = db;
		this.eventHierarchyPane.db = db;
		this.detailsPane.db = db;
	},
	onTreeNodeClick: function(type, args, me) {
		var topNode = args[0];
		var clickedNode = args[1];
        this.focusOnTreeNode(topNode.data.name, topNode.data.dbid, clickedNode.data.dbid);
	},
    focusOnTreeNode: function(name, pathwaydbid, nodedbid){
        this.processTitle(name);
		this.pathwayDiagramPane.clearHighlites();
		if (pathwaydbid != this.focus_pathway_id) {
			this.changeFocusPathway(pathwaydbid);
		}
		this.loadAndProcessData(nodedbid, false, true);
    },
	onDiagramNodeClick: function(type, args, me) {
		var node = args[0];
	    this.current_instance_id = node.userObject.id;
	    this.detailsPane.loadDetails(node.userObject.id);
	    this.eventHierarchyPane.highliteNodeInEventHierarchy(node,true);
	    this.updateLocationHref();
	},
	/*
	 * Currently handles other pathways functionality.
	 */
    onMenuItemClick: function(type, args, me) {
		var rootdbid = args[0];
        var nodedbid = args[1];
        this.new_current_instance_id = nodedbid;
        if(this.eventHierarchyPane.selectPathway(rootdbid) == "false"){
        	this.loadAndProcessData(rootdbid, true, false);
        }
	},
    onPathwayLoaded : function(){
        this.pathwayDiagramPane.scrollToNode(this.new_current_instance_id);

        this.pathwayDiagramPane.highliteNodeWithId(this.pathwayDiagramPane.dbnodes[this.new_current_instance_id], false);
        this.pathwayDiagramPane.diagramNodeClickedEvent.fire(this.pathwayDiagramPane.nodes[this.pathwayDiagramPane.dbnodes[this.new_current_instance_id]]);
		this.new_current_instance_id=null;
    },
    disableContextMenu: function(element) {
        element.oncontextmenu = function() {
        return false;
        }
    },
	onInternalLinkClick: function(type, args, me) {
		log("onInternalLinkClick " + args);
		var dbid = args[0];
		this.loadAndProcessData(dbid);
	},
	onTreeTrunkLoaded: function(type, args, me) {
<<<<<<< PathwayBrowser.js
		this.tabView.set('activeTab',this.tabView.getTab(0),true);
=======
		this.tabView.set('activeTab',this.tabView.getTab(1),true);
	},
        // FIX search results
	onSearchResultsLoaded: function(type, args, me) {
		this.pathwayDiagramPane.clearHighlites();
>>>>>>> 1.20
	},
	toString: function() {
		return "PathwayBrowser";
	},
	speciesSelectorChange : function(e){
		var target = null;
		if(e.target){
			target = e.target;
		}else{
			target = e.srcElement;
		}
		var target = e.target;
		var speciesId = target.value;
		this.setFocusSpecies(speciesId);
		this.eventHierarchyPane.buildEventHierarchy(this.focus_pathway_id);
	},
	
	/*
	 * PathwayId is id of selected pathway in previous species. Now that the event hierarchy for the new species
	 * has been loaded, check to see if an orhologous pathway exists and switch to it if so.
	 */
	onNewSpeciesTreeLoaded:function(eventType, pathwayId){
		var t = this;
		var callback = {
				scope: this,
				customevents: {
					onSuccess: function(eventType, args) {
						var rtxt = args[0].responseText;
						try{
							if (rtxt && (rtxt.length > 0)) {
								var data = eval('(' + rtxt + ')');
								var orthologousId = data.orthologousEventId;
								if(orthologousId == undefined || orthologousId == "none"){
									t.pathwayDiagramPane.noPathwaySelected();
									t.focus_pathway_id=null;
									t.eventHierarchyPane.focus_pathway_id = null;
									t.detailsPane.getDetailsDiv().innerHTML="";
									return;
								}
								// Change pathway to orthologous pathway.
								t.focusOnTreeNode(document.title, orthologousId, orthologousId);
								t.eventHierarchyPane.highliteTreeNodesByEventDbIds(new Array(t.focus_pathway_id), t.eventHierarchyPane.treehighlites1cls);
							}
						}catch(err){
						}
					}, 
					onFailure: function(eventType, args) {
						
					}
				}
			};
		YAHOO.util.Connect.asyncRequest("POST", "/ReactomeGWT/entrypoint/elv/ELVUtilsServlet", 
       		 callback, "pathwayid=" + pathwayId + "&otherspeciesid=" + this.focus_species_id + "&action=getortholog&prevspeciesid="+this.previousSpeciesId);
	},
	
	loadAndProcessData: function(dbid, forceCoordinates, treenodesAlreadyHandled) {
		var sUrl = this.loadAndProcessDataUrl + '?DB=' + this.db + 
			'&FOCUS_SPECIES_ID=' + this.focus_species_id + '&ID=' + dbid;
		if (this.focus_pathway_id) sUrl += '&FOCUS_PATHWAY_ID=' + this.focus_pathway_id;
		if (forceCoordinates) sUrl += '&COORDINATES=1';
		var ol = overlayElementWithTimeIndicator(this.detailsPane.getDetailsDiv());
		var callback = {
			scope: this,
			customevents: {
				onSuccess: function(eventType, args) {
					this.current_instance_id = dbid;
                    var h = eval('(' + args[0].responseText + ')');
                    var o = new Object();
                    o.details = h.details;
                    o.map_highlites = h.map_highlites;
                    o.hierarchy_highlites = h.hierarchy_highlites;
                    o.top_highlites = h.top_highlites;
                    if(h.coordinates){
                    	o.coordinates = h.coordinates;
                    }
					if (! treenodesAlreadyHandled) {
						this.eventHierarchyPane.removeTreeNodeHilites();

						if ($A(o.hierarchy_highlites).indexOf(dbid) >= 0) {
							this.eventHierarchyPane.treehighlites1 = [dbid];
							this.eventHierarchyPane.highliteTreeNodesByEventDbIds(this.eventHierarchyPane.treehighlites1,this.eventHierarchyPane.treehighlites1cls);
						}
						this.eventHierarchyPane.treehighlites2 = $A(o.hierarchy_highlites).without(this.eventHierarchyPane.treehighlites1);
						this.eventHierarchyPane.highliteTreeNodesByEventDbIds(this.eventHierarchyPane.treehighlites2,this.eventHierarchyPane.treehighlites2cls);
					}
					if (o.focus_species_id) {
				    	this.setFocusSpecies(o.focus_species_id);
				    	this.eventHierarchyPane.buildEventHierarchy();
				    }
					// if focus change
					if (! treenodesAlreadyHandled ) {
						this.changeFocusPathway(dbid);
						this.eventHierarchyPane.selectPathway(dbid);
					}
					if(dbid == this.focus_pathway_id){
						this.eventHierarchyPane.scrollToFocusPathway();
					}
				    this.detailsPane.processDetails(o.details);
				    if (o.map_highlites && (this.focus_pathway_id != dbid)) {
				    	this.pathwayDiagramPane.processHighlites(o.map_highlites);
				    }
				    this.updateLocationHref();
                    this.pathwayLoadedEvent.fire();
				}, 
				onFailure: function(eventType, args) {
				},
				onComplete: function(eventType, args) {
					if (ol) ol.remove();
				}
			}
		};
		YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
	}

	}

);

YAHOO.util.Event.onDOMReady(function() {
	if (YAHOO.env.ua.ie > 0) {
		$('clipwrapper').setStyle({left:'0px'});
		$('thumbnailframe').setStyle({bottom:'0px',left:'0px'});
		/*
		 * To get horizontal scrollbar for the hierarchy tab as overflow: auto 
		 * and overflow:scroll does not have the desired effect in IE.
		 */
		$('hierarchytab').setStyle({width:'600px'});
	}
});

