flyui.namespace("flyui.apps.flyatlasbygene");flyui.apps.flyatlasbygene.Application=function(){var A=null;var C=null;var D=null;var B=this;this.initGenefinder=function(){try{flyui.info("instantiate a service for the genefinder widget");var E=new flyui.flybase.Service("../../../data/flybase");flyui.info("instantiate a renderer for the genefinder widget");var H=document.getElementById("genefinderWidget");var G=new flyui.genefinder.DefaultRenderer();G.setCanvas(H);flyui.info("instantiate a genefinder widget");A=new flyui.genefinder.Widget(E,G)}catch(F){flyui.apps.flyatlasbygene.handleError(F)}};this.initFlyatlas=function(){try{flyui.info("instantiate a service for the flyatlas widget");var E=new flyui.flyatlas.Service();E.setEndpoint("../../../data/flyatlas");flyui.info("instantiate a renderer for the flyatlas widget");var G=new flyui.flyatlas.Widget.DefaultRenderer();G.setCanvas($("#flyatlasWidget"));flyui.info("instantiate a flyatlas widget");C=new flyui.flyatlas.Widget(E,G)}catch(F){flyui.apps.flyatlasbygene.handleError(F)}};this.initState=function(){try{var H=new String(window.location.href);var K=H.indexOf("#query=");var G=H.indexOf(";selection=");if(K>0){var E=(G>0)?G:H.length;var J=H.substring(K+7,E);flyui.info("found query: "+J);A.findGenesByAnyName(J,false)}if(G>0){var I=H.substring(G+11,H.length);flyui.info("found selection: "+I);D=I}}catch(F){flyui.apps.flyatlasbygene.handleError(F)}};this.init=function(){try{var F=new YAHOO.widget.LogReader("logger");this.initGenefinder();this.initFlyatlas();A.subscribe("GENESELECTED",this.onGeneSelected,null);A.subscribe("GENESFOUND",this.onGenesFound,null);flyui.info("hook form submission to widget call");YAHOO.util.Event.addListener("queryForm","submit",this.onFormSubmitted);flyui.info("application loaded, showing main pane");flyui.mvcutils.hide(document.getElementById("loadingPane"));flyui.mvcutils.show(document.getElementById("applicationPane"));this.initState()}catch(E){flyui.apps.flyatlasbygene.handleError(E)}};this.onGenesFound=function(J,G){try{flyui.info("application: genes found");var I=G[0];if(D!=null){flyui.info("attempting to apply deferred selection: "+D);var F=-1;for(var H=0;H<I.length;H++){if(D==I[H].flybaseID){F=H}}if(F>=0&&I.length>1){A.setSelectionIndex(F)}else{flyui.info("failed to apply deferred selection: "+D,"error")}D=null}}catch(E){flyui.apps.flyatlasbygene.handleError(E)}};this.onGeneSelected=function(G,F){try{var H=F[0];flyui.info("gene selected: "+H+" "+H.flybaseID);C.getAssaysByGene(H);flyui.mvcutils.show(document.getElementById("flyatlasWidget"));B.setSelectionState(H)}catch(E){flyui.debug("caught error on gene selected");flyui.apps.flyatlasbygene.handleError(E)}};this.onFormSubmitted=function(G){try{flyui.info("form submitted");$("#errorMessage").hide().html("this should never be visible");var H=document.getElementById("queryInput").value;document.getElementById("queryInput").value="";var E=false;flyui.info("case sensitive: "+E);A.findGenesByAnyName(H,E);flyui.mvcutils.hide(document.getElementById("flyatlasWidget"));B.setQueryState(H)}catch(F){flyui.apps.flyatlasbygene.handleError(F)}};this.setQueryState=function(H){try{var F=new String(window.location.href);var G=F.indexOf("#");if(G>0){F=F.substring(0,G)}window.location.href=F+"#query="+H}catch(E){flyui.apps.flyatlasbygene.handleError(E)}};this.setSelectionState=function(H){try{var F=new String(window.location.href);var G=F.indexOf(";selection=");if(G>0){F=F.substring(0,G)}window.location.href=F+";selection="+H.flybaseID}catch(E){flyui.apps.flyatlasbygene.handleError(E)}};this.init()};flyui.apps.flyatlasbygene.handleError=function(A){flyui.err(A.name+" :: "+A.message);$("#errorMessage").html("an error has occurred, please see the log for more details").show()};YAHOO.util.Event.onDOMReady(function(){new flyui.apps.flyatlasbygene.Application()})