var AreaMap = Class.extend({ init: function(map, container, data){ this.container = $(container); this.data = data; this.current = ""; var obj = this; this.container.find('div.map a').live('click', function(e){ e.preventDefault(); var dest = this.href.match(/\#(.+)/)[1]; obj.goto(dest); }); this.container.find('div.list a, div.trail a').live('click', function(e){ e.preventDefault(); if($(this).hasClass('select-all')){ var area = this.href.match(/#(\w+)\/(\w+)/)[1]; var id = this.href.match(/#(\w+)\/(\w+)/)[2]; var title = this.title; obj.selectAll(area, id, title); } else { var dest = this.href.match(/\#(.+)/)[1]; obj.goto(dest); } }); this.container.find('div.list input.continue-button').live('click', function(e){ e.preventDefault(); var select = $('select[name="suburbs"]:visible'); if(select.length){ var suburbs = []; var names = []; $.each(select.attr('options'), function(){ if(this.selected){ suburbs.push(this.value); names.push($.trim($(this).text())); } }); if(!suburbs || !suburbs.length) return; $(document).trigger('suburbSelect', [ suburbs, names ]); $.fancybox.close(); } }); this.goto(map); }, goto: function(dest){ if(dest == this.current) return; if(!this.data[dest]){ alert('Invalid data requested!'); return; } var content = this.data[dest]; this.container.html(content.html); this.container.find('div.map').css('backgroundPosition', ''+content.position[0]+'px '+content.position[1]+'px'); this.current = dest; }, selectAll: function(area, id, title){ if(area == 'state' || area == 'island') $(document).trigger('stateSelect', [ id, title ]); else $(document).trigger('regionSelect', [ id, title ]); $.fancybox.close(); } });