//>>built
define("demos/doGeo/src/app/assistants/main-assistant",["dojo","dijit","dojox","dojo/require!dojox/mobile/app/SceneAssistant"],function(_1,_2,_3){_1.require("dojox.mobile.app.SceneAssistant");_1.declare("MainAssistant",_3.mobile.app.SceneAssistant,{setup:function(){this.handleAddressResults=_1.hitch(this,this.handleAddressResults);this.controller.parse();this.serviceBtn=_2.byId("serviceBtn");this.setService("FourSquare");var _4=this;this.searchYQL="select * from foursquare.venues where geolong = '${0}' and geolat = '${1}'";_1.connect(this.serviceBtn,"onClick",function(_5){this.controller.popupSubMenu({choices:[{label:"FourSquare",value:"FourSquare"},{label:"Twitter",value:"Twitter"},{label:"Flickr",value:"Flickr"}],fromNode:_5.target,onChoose:function(_6){if(!_6){return;}_1.publish("/service",[_6]);}});});_1.subscribe("/service",_1.hitch(this,this.setService));_1.subscribe("/images",function(_7){this.dataAvailable(_4.venues.map(function(_8,i){_8.image=_7[i];_8.title=_8.name;_8.backFaceId="backface1";return _8;}));});},dataAvailable:function(_9){var _a=new wink.ui.xyz.CoverFlow({covers:_9,size:300,viewportWidth:window.innerWidth,reflected:true,displayTitle:true,fadeEdges:true,handleOrientationChange:true,handleGesture:true,backgroundColor:{r:0,g:0,b:0},coverSpacing:25,displayTitleDuration:1000,borderSize:2});$("container").appendChild(_a.getDomNode());},activate:function(_b){var _c=this;this.getVenuesNearby(function(_d){_d=_d.query.results.venues.group.venue;if(!_1.isArray(_d)){_d=[_d];}_c.venues=_d;_c.findAddressImages(_1.map(_d,function(_e){var _f=_e.name;return _f;}),_c.handleAddressResults);},function(){});},findAddressImages:function(_10,_11){_10=_10.slice(0,2);var url="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20query.multi%20where%20queries%3D%22";var _12="%27%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys;";url+=_1.map(_10,function(_13){var _14="http://ajax.googleapis.com/ajax/services/search/images?v=1.0&count=1&q="+_13;_14=escape(_14);return "select%20*%20from%20json%20where%20url%3D%27"+_14;}).join("%3B")+"%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";var _15=_1.io.script.get({url:url,jsonp:"callback"});_15.addBoth(_11);},handleAddressResults:function(_16){if(!_16||!_16.query||!_16.query.results||!_16.query.results.results){return null;}var _17=_1.map(_16.query.results.results,this.parseImageResults);_1.publish("/images",[_17]);return _17;},parseImageResults:function(_18){if(!_18.json||!_18.json.responseData||!_18.json.responseData.results){return null;}return _18.json.responseData.results[0].tbUrl;},getVenuesNearby:function(_19,_1a){var _1b=_1.hitch(this,function(_1c){var url="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20foursquare.venues%20where%20%20geolong%20%3D%20'"+_1c[0]+"'%20and%20geolat%20%3D%20'"+_1c[1]+"'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";var _1d=_1.io.script.get({url:url,jsonp:"callback"});_1d.addBoth(_19);});this.getCurrentLatLong(_1b);},getCurrentLatLong:function(_1e){_1e([40.7204,-73.9933]);return;if(navigator.geolocation){navigator.geolocation.getCurrentPosition(function(_1f){_1e([_1f.coords.latitude,_1f.coords.longitude]);});}else{}},setService:function(_20){this.serviceName=_20;_1.query("span",this.serviceBtn.domNode)[0].innerHTML=_20;}});});