var map;

function updateFeaturedMap(request, object){
  var remoteDocument = request.responseXML.documentElement;
  var id = remoteDocument.getAttribute('href').split('/')[5];
  
  $('map_title').innerHTML = "<a href=\"/maps/"+id+"\">"+remoteDocument.getElementsByTagName('title')[0].firstChild.nodeValue+"</a>";
  $('map_subtitle').innerHTML = "by <a href='/people/" + remoteDocument.getElementsByTagName('owner')[0].firstChild.nodeValue + "'>" + remoteDocument.getElementsByTagName('owner')[0].firstChild.nodeValue + "</a>";
}

/*
 Behaviour Rules
 */

var map;function updateFeaturedMap(request,object){var remoteDocument=request.responseXML.documentElement;var id=remoteDocument.getAttribute('href').split('/')[5];$('map_title').innerHTML="<a href=\"/maps/"+id+"\">"+remoteDocument.getElementsByTagName('title')[0].firstChild.nodeValue+"</a>";$('map_subtitle').innerHTML="by <a href='/people/"+remoteDocument.getElementsByTagName('owner')[0].firstChild.nodeValue+"'>"+remoteDocument.getElementsByTagName('owner')[0].firstChild.nodeValue+"</a>";}
var frontpageRules={'#sign_up_btn':function(element){Event.observe(element,'click',function(){window.location="/account/sign_up";});},'#next_map_btn':function(element){Event.observe(element,'click',function(){if(!element.current_map)element.current_map=1;else if(element.current_map>1)element.current_map=0;else element.current_map+=1;var id=document.getElementsByClassName('map_title')[element.current_map].getElementsByTagName('a')[0].href.split('/')[4];map.setMap(id);$('map_icon').src='/icons/maps/'+id;new Ajax.Request("/api/maps/"+id,{method:'get',onSuccess:updateFeaturedMap})});},'li.map':function(element){Event.observe(element,'click',function(e){map_id=element.id.split("-")[1];window.location="/maps/"+map_id;});Event.observe(element,'mouseover',function(e){if(browserName=="Internet Explorer"){Element.addClassName(element,"highlighted_map");}});Event.observe(element,'mouseout',function(e){if(browserName=="Internet Explorer"){Element.removeClassName(element,"highlighted_map");}});}};Behaviour.register(frontpageRules);Behaviour.addLoadEvent(function(){if(GBrowserIsCompatible()){map=new Map();map.resizeToFill=false;globalUnload=window.onunload;window.onunload=function(){globalUnload();GUnload();}
page.state=$H([]);var id=$('map_title').getElementsByTagName('a')[0].href.split('/')[4];map.setMap(id);}else{Map.prototype.resized();Map.prototype.complete();Element.show("map");$("map_search_tip").innerHTML="You must have a browser capable of displaying Google Maps to use Flagr.";Element.show("map_search_tip");}});
