/*
	Copyright (c) 2004-2009, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


dojo.require("dojox.gfx");dojo.require("dojox.gfx.fx");dojo.require("dojo.fx");var map;var state_label_cache=[];function flip_states(e){if(e.target.id.indexOf("map")!=-1){dojo.animateProperty({node:dojo.byId("state_list"),duration:600,properties:{opacity:0,width:0}}).play();}else{dojo.animateProperty({node:dojo.byId("state_list"),duration:600,properties:{opacity:1,width:690}}).play();}};function cached_label(id){if(state_label_cache[id]){return state_label_cache[id];}var _1=id.split("_");for(var i=0;i<_1.length;i++){_1[i]=_1[i].substr(0,1).toUpperCase()+_1[i].substr(1);}state_label_cache[id]=_1.join(" ");return state_label_cache[id];};function show_regions_click(e){e.preventDefault();var _2=e.target.id.split(/-/)[1];show_regions(_2);};function show_regions(_3){dojo.query(".region").forEach(function(li){dojo.animateProperty({node:li,duration:300,properties:{opacity:0,height:0}}).play();});dojo.xhrGet({url:"/location/children/"+_3,handleAs:"json",timeout:5000,load:function(_4,_5){dojo.byId("region_list").innerHTML="";for(var i=0;i<_4.length;i++){a=document.createElement("a");dojo.addClass(a,"region_link");a.href="/location/set_location/"+_4[i].slug;a.appendChild(document.createTextNode(_4[i].name));li=document.createElement("li");dojo.addClass(li,"region");li.style.height="0px";li.style.opacity=0;li.appendChild(a);dojo.byId("region_list").appendChild(li);dojo.animateProperty({node:li,duration:500,properties:{opacity:1,height:20}}).play();}},error:function(_6,_7){}});};dojo.declare("ff0000.StatesMap",null,{dom_node:null,data_url:null,width:null,height:null,svg:null,surface:null,shapes:[],data:[],events:[],constructor:function(_8,_9){this.dom_node=_8;this.data_url=_9;this.load_data();},build_map:function(_a){this.states=_a.getElementsByTagName("path");states=this.states;width=_a.documentElement.getAttribute("width");height=_a.documentElement.getAttribute("height");this.surface=dojox.gfx.createSurface(dojo.byId("svg_map"),width,height);surface=this.surface;for(var i=0;i<states.length;i++){var id;var d;try{d=dojo.attr(states[i],"d");id=dojo.attr(states[i],"id");}catch(e){d=states[i].getAttribute("d");id=states[i].getAttribute("id");}path=surface.createPath();path.setShape(d).setStroke("#93a067");this.shapes[id]=path;if(id.length!=1){path.setFill("#bdca90");node=path.getNode();dojo.attr(node,"id",id);this.rig_state_events(id);}}},load_data:function(){dojo.xhrGet({url:this.data_url,handleAs:"xml",timeout:5000,load:dojo.hitch(this,function(_b,_c){svg=_b;this.build_map(svg);}),error:function(_d,_e){}});},highlight:function(e){id=e.target.getAttribute("id");this.shapes[id].setFill("#FFF");dojo.byId("state_tip").style.display="block";dojo.byId("state_tip").innerHTML="&nbsp;"+cached_label(id)+"&nbsp;";dojo.byId("state_tip").style.left=e.clientX+15+"px";dojo.byId("state_tip").style.top=e.clientY-15+"px";document.body.style.cursor="pointer";},lowlight:function(e){this.shapes[e.target.getAttribute("id")].setFill("#bdca90");dojo.byId("state_tip").style.display="none";dojo.byId("state_tip").innerHTML="";document.body.style.cursor="default";},select_state:function(e){dojo.byId("state_tip").style.display="none";dojo.byId("state_tip").innerHTML="";var id=e.target.id;if(this.raised!=null){this.raised.removeShape();this.rig_state_events(this.active_state_id);dojox.gfx.fx.animateFill({shape:this.shapes[this.active_state_id],duration:300,color:{"start":"#5e6546","end":"#bdca90"}}).play();}show_regions(id);this.flip_state_label(id);this.unrig_state_events(id);p=surface.createPath();p.setShape(this.shapes[id].getShape().path).setStroke("#93a067");p.setFill("#FFFFFF");dojox.gfx.fx.animateTransform({shape:p,duration:500,transform:[{name:"translate",start:[0,0],end:[8,-8]}]}).play();dojox.gfx.fx.animateFill({shape:this.shapes[e.target.id],duration:500,color:{"start":"#bdca90","end":"#5e6546"}}).play();this.active_state_id=id;this.raised=p;},flip_state_label:function(id){var _f=dojo.animateProperty({node:dojo.byId("state_name_wrapper"),duration:300,onEnd:function(e){dojo.byId("state_name").innerHTML=cached_label(id);},properties:{opacity:0,top:228}});var _10=dojo.animateProperty({node:dojo.byId("state_name_wrapper"),duration:300,properties:{opacity:1,top:200}});dojo.fx.chain([_f,_10]).play();},rig_state_events:function(id){path=this.shapes[id];this.events[id+"-click"]=path.connect("click",this,"select_state");this.events[id+"-onmouseover"]=path.connect("onmouseover",this,"highlight");this.events[id+"-onmouseout"]=path.connect("onmouseout",this,"lowlight");},unrig_state_events:function(id){dojo.disconnect(this.events[id+"-click"]);dojo.disconnect(this.events[id+"-onmouseover"]);dojo.disconnect(this.events[id+"-onmouseout"]);}});function page_init(){try{map=new ff0000.StatesMap(dojo.byId("svg_map"),"map2.svg");dojo.byId("state_list").style.width="0px";dojo.byId("select_state").style.display="block";dojo.byId("state_name_wrapper").style.display="block";dojo.byId("map").style.height="275px";dojo.connect(dojo.byId("text_button"),"click",flip_states);dojo.connect(dojo.byId("map_button"),"click",flip_states);dojo.query("a.state_link").forEach(function(_11){dojo.connect(_11,"click",show_regions_click);});}catch(err){dojo.query("a.state_link").forEach(function(_12){dojo.connect(_12,"click",show_regions_click);});}};dojo.addOnLoad(page_init);
