/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */
//>>built
define("esri/dijit/geoenrichment/Tapestry",["../../declare","./BaseWidget","dojo/_base/lang","dojo/on","require","dojo/dom-construct","dojo/dom-attr","dojo/dom-class","dojo/query","dojo/i18n!../../nls/jsapi","./dom"],function(_1,_2,_3,on,_4,_5,_6,_7,_8,_9,_a){_9=_9.geoenrichment.dijit.Tapestry;var _b=_1("esri.dijit.geoenrichment.Tapestry",[_2],{_widthExpanded:455,_widthCollapsed:200,currentTop:0,updateUIExpanded:function(){this.inherited(arguments);if(this.currentTop==0){this.updateListUIExpanded();}else{this.updateViewUIExpanded();}},updateUICollapsed:function(){this.inherited(arguments);if(this.currentTop==0){this.updateListUICollapsed();}else{this.updateViewUICollapsed();}},createUI:function(_c){_c.contentClass.push("Tapestry");this.inherited(arguments);},createUIExpanded:function(_d){this.inherited(arguments);if(this.currentTop==0){this.createListUIExpanded(_d);}else{this.createViewUIExpanded(_d);}},createUICollapsed:function(_e){this.inherited(arguments);if(this.currentTop==0){this.createListUICollapsed(_e);}else{this.createViewUICollapsed(_e);}},updateListUIExpanded:function(){var _f=function(_10,top,_11){var _12=(top-1)*5;if(_13(_11,top)){_14(_10,top,_12,5);_7.remove("arr"+top,"Tapestry_RightArrowCell");return;}_7.add("arr"+top,"Tapestry_RightArrowCell");var tr=_10.rows[_12++];tr.cells[0].innerHTML=_11.formatValue(0,_15.get(_15.Percentage,top));var _16=tr.cells[1];_16.innerHTML=_11.getValue(0,_15.get(_15.Name,top));tr=_10.rows[_12++];var _17=tr.cells[0];_17.innerHTML="("+_11.formatValue(0,_15.get(_15.Value,top))+" "+_9.hhLabel+")";tr=_10.rows[_12++];_18(tr.cells[1],_9.hhTypeLabel,"10em");_18(tr.cells[2],_11.getValue(0,_15.get(_15.Type,top)),"15em");tr=_10.rows[_12++];tr.cells[0].innerHTML="&nbsp;";_18(tr.cells[1],_9.medianAgeLabel,"10em");_18(tr.cells[2],_11.getValue(0,_15.get(_15.Age,top)),"15em");tr=_10.rows[_12++];tr.cells[0].innerHTML="&nbsp;";_18(tr.cells[1],_9.incomeLabel,"10em");_18(tr.cells[2],_11.getValue(0,_15.get(_15.Income,top)),"15em");};for(i=1;i<4;i++){_f(this.table,i,this._data);}},updateListUICollapsed:function(){var _19=function(_1a,top,_1b){var _1c=(top-1)*2;if(_13(_1b,top)){_14(_1a,top,_1c,2,true);_7.remove("arr"+top,"Tapestry_RightArrowCell");return;}_7.add("arr"+top,"Tapestry_RightArrowCell");var tr=_1a.rows[_1c++];tr.cells[0].children[0].innerHTML=_1b.formatValue(0,_15.get(_15.Percentage,top));tr.cells[1].innerHTML=_1b.getValue(0,_15.get(_15.Name,top));tr=_1a.rows[_1c++];tr.cells[0].innerHTML="("+_1b.formatValue(0,_15.get(_15.Value,top))+" "+_9.hhLabel+")";};for(i=1;i<4;i++){_19(this.table,i,this._data);}},updateViewUIExpanded:function(){if(_13(this._data,this.currentTop)){_8("td:not([\".Tapestry_LeftArrowCell\"])",this.table).forEach(function(_1d){_5.empty(_1d);});return;}var tr=this.table.rows[0];tr.cells[1].innerHTML=this._data.getValue(0,_15.get(_15.Name,this.currentTop));tr=this.table.rows[1];tr.cells[0].innerHTML="&nbsp;";var id=this._data.formatValue(0,_15.get(_15.Code,this.currentTop));if(id.length==1){id="0"+id;}_1e.bindTopIcon(tr.cells[1],id);for(var i=0;i<6;i++){var tr=this.table.rows[i+2];tr.cells[0].innerHTML="&nbsp;";_18(tr.cells[1],_1e.labels[i],_1e.labelWidth);_18(tr.cells[2],this._data.getValue(0,_15.get(_1e.values[i],this.currentTop)),_1e.valueWidth);}},updateViewUICollapsed:function(){if(_13(this._data,this.currentTop)){_8("td",this.table).forEach(function(_1f){if(_1f.className!="LeftArrow"){_5.empty(_1f);}});return;}var tbl=this.table.rows[0].cells[0].children[0];var _20=tbl.rows[0];_20.cells[1].innerHTML=this._data.getValue(0,_15.get(_15.Name,this.currentTop));for(var i=0;i<6;i++){var tr=this.table.rows[i+1];_18(tr.cells[0],_1e.labels[i],_1e.labelWidthCollapsed);_18(tr.cells[1],this._data.getValue(0,_15.get(_1e.values[i],this.currentTop)),_1e.valueWidthCollapsed);}},createListUIExpanded:function(_21){if(this.table&&this.table.innerHTML){_5.destroy(this.table);}this.table=_21.addContent("table",{"class":"Tapestry_Table","cellpadding":"0","cellspacing":"0"});_a.createCols(this.table,[0.16,0.26,0.36,0.2]);for(var i=1;i<4;i++){var tr=this.table.insertRow(-1);var _22=tr.insertCell(-1);_6.set(_22,"class","Tapestry_PrcCell Tapestry_Top"+_23[i]);_6.set(_22,"rowspan","2");var _22=tr.insertCell(-1);_6.set(_22,"class","Tapestry_HeaderCell Tapestry_Top"+_23[i]+" Tapestry_LeftCell topName");_6.set(_22,"colspan","3");tr=this.table.insertRow(-1);_22=tr.insertCell(-1);_6.set(_22,"class","Tapestry_ValueCell Tapestry_Top"+_23[i]+" Tapestry_LeftCell");_6.set(_22,"colspan","3");this.addTextRows(i);}},addTextRows:function(top){for(i=0;i<3;i++){var tr=this.table.insertRow(-1);tr.insertCell(-1);_6.set(tr.insertCell(-1),"class","Tapestry_AttrCell");_6.set(tr.insertCell(-1),"class","Tapestry_TextCell");if(i==0){var _24=tr.insertCell(-1);_6.set(_24,"rowspan","3");_25(_24,top,this);}}},updateMode:function(top){this.currentTop=top;this.destroy(true);this.update();},createListUICollapsed:function(_26){if(this.table&&this.table.innerHTML){_5.destroy(this.table);}this.table=_26.addContent("table",{"class":"Tapestry_Table","cellpadding":"0","cellspacing":"0"});_a.createCols(this.table,[0.25,0.65,0.07]);for(var i=1;i<4;i++){var tr=this.table.insertRow(-1);var _27=tr.insertCell(-1);_6.set(_27,"class","Tapestry_ListCell Tapestry_Top"+_23[i]+" Tapestry_PrcCell");_6.set(_27,"rowspan","2");_5.create("div",null,_27);_6.set(tr.insertCell(-1),"class","Tapestry_HeaderCell Tapestry_ListCell Tapestry_Top"+_23[i]+" Tapestry_LeftCell");_27=tr.insertCell(-1);_6.set(_27,"rowspan","2");_6.set(_27,"class","Tapestry_ListCell");_25(_27,i,this);_6.set(this.table.insertRow(-1).insertCell(-1),"class","Tapestry_HeaderCell Tapestry_Top"+_23[i]+" Tapestry_LeftCell");}},createViewUIExpanded:function(_28){if(this.table&&this.table.innerHTML){_5.destroy(this.table);}this.table=_28.addContent("table",{"class":"Tapestry_Table","cellpadding":"1","cellspacing":"0"});_a.createCols(this.table,[0.1,0.3,0.6]);var tr=this.table.insertRow(0);var _29=tr.insertCell(-1);_6.set(_29,"class","Tapestry_LeftArrowCell");on(_29,"click",_3.hitch(this,this.updateMode,0));var td=tr.insertCell(-1);_6.set(td,"class","Tapestry_HeaderCell Tapestry_Top"+_23[this.currentTop]+"");_6.set(td,"colspan","2");tr=this.table.insertRow(-1);tr.insertCell(-1);var _29=tr.insertCell(-1);_6.set(_29,"colspan","2");for(i=0;i<6;i++){tr=this.table.insertRow(-1);_6.set(tr.insertCell(-1),"class",i==0?"Tapestry_AttrCell Tapestry_TopCell":"Tapestry_AttrCell");_6.set(tr.insertCell(-1),"class",i==0?"Tapestry_AttrCell Tapestry_TopCell":"Tapestry_AttrCell");_6.set(tr.insertCell(-1),"class",i==0?"Tapestry_TextCell Tapestry_TopCell":"Tapestry_TextCell");}},createViewUICollapsed:function(_2a){if(this.table&&this.table.innerHTML){_5.destroy(this.table);}this.table=_2a.addContent("table",{"class":"Tapestry_Table","cellpadding":"1","cellspacing":"0"});_a.createCols(this.table,[0.3,0.7]);var tr=this.table.insertRow(0);var _2b=tr.insertCell(-1);_6.set(_2b,"colspan","2");_6.set(_2b,"class","LeftArrow");var _2c=_5.create("table",null,_2b).insertRow(0);var _2d=_6.set(_2c.insertCell(-1),"class","Tapestry_LeftArrowCell");on(this.table.rows[0].cells[0].children[0].rows[0].cells[0],"click",_3.hitch(this,this.updateMode,0));_6.set(_2c.insertCell(-1),"class","Tapestry_HeaderCell Tapestry_Top"+_23[this.currentTop]);for(i=0;i<6;i++){var tr=this.table.insertRow(-1);_6.set(tr.insertCell(-1),"class",i==0?"Tapestry_AttrCell Tapestry_TopCell":"Tapestry_AttrCell Tapestry_ViewCell");_6.set(tr.insertCell(-1),"class",i==0?"Tapestry_TextCell Tapestry_TopCell":"Tapestry_TextCell Tapestry_ViewCell");}}});var _15={Code:"CODE",Name:"NAME",Value:"VALUE",Percentage:"PRC",Type:"TYPE",Age:"AGE",Income:"INCOME",Employment:"EMP",Education:"EDU",Residental:"RSD",Race:"RACE",get:function(_2e,top){return "TOP"+top+_2e;}};var _18=function(_2f,_30,_31){_5.empty(_2f);_5.create("div",{style:"width:"+_31,title:_30,innerHTML:_30},_2f);};var _25=function(_32,top,_33){_5.create("div",{"class":"Tapestry_RightArrowCell","id":"arr"+top},_32);on(_32,"click",_3.hitch(_33,_33.updateMode,top));};var _23={1:"One",2:"Two",3:"Three"};var _14=function(_34,top,_35,_36,_37){for(r=_35;r<_35+_36;r++){_8("td",_34.rows[r]).forEach(function(_38){if(_8("#arr"+top,_38).length==0){_5.empty(_38);}if(_37&&_38.className.indexOf("Tapestry_PrcCell")>-1){_5.create("div",null,_38);}});}};var _1e={labels:[_9.hhTypeLabel,_9.medianAgeLabel,_9.incomeLabel,_9.employmentLabel,_9.educationLabel,_9.residentialLabel],values:[_15.Type,_15.Age,_15.Income,_15.Employment,_15.Education,_15.Residental],labelWidth:"10em",valueWidth:"23em",labelWidthCollapsed:"9em",valueWidthCollapsed:"10em",bindTopIcon:function(_39,id){_5.empty(_39);var img=_4.toUrl("./images/tapestry"+id+".png");_5.create("div",{"class":"Tapestry_ViewImage","style":"background-image:url('"+img+"')"},_39);}};var _13=function(_3a,top){var v=new Number(_3a.getValue(0,_15.get(_15.Value,top)));return (!v||v<=0);};return _b;});