<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
<ModulePrefs 
scrolling="true" 
title="Notable US eBird Sightings" 
title_url="http://ebird.org"
description="Shows notable eBird sightings for a state which the user selects.  User can view details of each sighting and see them plotted on Google Maps"
author="Jeff Gerbracht"
author_email="jeffgerbracht+gadg@gmail.com"
author_location="Ithaca, NY"
author_affiliation="Cornell Lab of Ornithology"
screenshot="http://ebird.org/tools/google/eBirdGadget.png"
thumbnail="http://ebird.org/tools/google/eBirdGadgetThumb.png"
directory_title="Notable eBird Sightings"
>
 <Require feature="setprefs" />
<Require feature="dynamic-height"/>
<Locale lang="en" />
</ModulePrefs>
<UserPref name="state" datatype="hidden" default_value="US-NY"/> 
<UserPref name="heightOption" display_name="Gadget Height" datatype="enum" default_value="0"> 
<EnumValue display_value="Auto Fit to data" value="0"/>
<EnumValue display_value="Small" value="200"/>
<EnumValue display_value="Medium" value="400"/>
<EnumValue display_value="Large" value="600"/>
</UserPref>
<Content type="html">
<![CDATA[ 
 <div id=content_div></div>
 <style>
 .fmaxbox {background-image:url('/ig/images/max_dark_blue.gif');}
 .fminbox {background-image:url('/ig/images/min_dark_blue.gif');}
 a.fmaxbox:hover {background-image:url('/ig/images/max_dark_blue_highlight.gif');}
 a.fminbox:hover {background-image:url('/ig/images/min_dark_blue_highlight.gif');}
 .uftl {border:1px solid white;}
</style>
<link rel="stylesheet" type="text/css" href="/ig/f/U2SQqm5neGg/ig.css"/>
 <script type="text/javascript">
 // Get userprefs
 var prefs = new _IG_Prefs(__MODULE_ID__);
 var url = "http://ebird.org/xml/ebird/notable/" + prefs.getString("state")+ ".xml";
  var gHeight = prefs.getInt("heightOption");
 function toggleMenu(val){
 	var divObj = document.getElementById("summary_"+val);
 	var divTog = document.getElementById("tog_"+val);
 	if (divObj.style.display == 'none'){
 		divObj.style.display = 'block';
 		divTog.className = 'fminbox';
 	}else{
 		divObj.style.display = 'none';
 		divTog.className = 'fmaxbox';
	}
 	if (gHeight > 0) {  _IG_AdjustIFrameHeight(gHeight); } else {  _IG_AdjustIFrameHeight(); } 
}

function toggleDesc(items, showAll)  {
    	var disp = 'none';
    	var cName = 'fmaxbox';
    	if (showAll == 'show') {
    		disp = 'block';
 		cName = 'fminbox'; 
 		document.getElementById("show_all").style.display = 'none';
 		document.getElementById("hide_all").style.display = 'inline';
    	}
    	else {
 		document.getElementById("show_all").style.display = 'inline';
 		document.getElementById("hide_all").style.display = 'none';
    	}
	for (var i = 0; i < items ; i++)  {
	 	document.getElementById("summary_"+i).style.display = disp;
	 	document.getElementById("tog_"+i).className = cName;
	}
	if (gHeight > 0) {  _IG_AdjustIFrameHeight(gHeight); } else {  _IG_AdjustIFrameHeight(); } 
}

function toggleState() {
	var divObj = document.getElementById("selectAState");
	var divTitle = document.getElementById("title");
 	if (divObj.style.display == 'none'){
 		divObj.style.display = 'block';
 		divTitle.style.display = 'none';
 	}else{
 		divObj.style.display = 'none';
 		divTitle.style.display = 'block';
	}
	if (gHeight > 0) {  _IG_AdjustIFrameHeight(gHeight); } else {  _IG_AdjustIFrameHeight(); } 

}

function changeState(stateCode) {
prefs.set("state", stateCode);
 url = "http://ebird.org/xml/ebird/notable/" + stateCode + ".xml";
displayBirdData();

}
function displayBirdData() { 
// XML Bird data
_IG_FetchContent("http://ebird.org/tools/google/states.txt", function (resp) {
 if (resp == null ) {
_gel("content_div").innerHTML = "<i>Invalid data.</i>";
return;
 }
_IG_FetchXmlContent(url, function (response) {
 if (response == null || typeof(response) != "object" || 
response.firstChild == null) {
_gel("content_div").innerHTML = "<a href=\"http://ebird.org/\" target=\"_parent\" ><img src=\"http://ebird.org/eBirdCommon/images/ebird_logo.gif\" /></a><br>No Data Available at this time for this state, please try again soon by refreshing the browser or select a different state.<br><br><div id='selectAState' style='text-align:left;display:block'><form><select name=\"state\" onChange='changeState(this.options[this.selectedIndex].value)'>"+resp+"</select></form></div>";
return;
 }
 // Start building HTML string that will be displayed in <div>. 
 // Set the style for the <div>.		
 var html = "<div font-family:Arial, Helvetica;" + 
		"text-align:left;font-size:90%'>"; 
					
 // Set style for title.
 html +="<div id='title' style='text-align:center; font-size: 150%; " +
		"font-weight: 700;line-height:40px;'>"; 

 // Display channel title. Use getElementsByTagName() to retrieve the <channel> element.
 // Since there is only one channel element in the file,
 // you can get to it by accessing the item at index "0". 
 if (response.getElementsByTagName("channel").item(0) == null)
 _gel("content_div").innerHTML = "<a href=\"http://ebird.org/\" target=\"_parent\" ><img src=\"http://ebird.org/eBirdCommon/images/ebird_logo.gif\" /></a><br>No Data Available at this time for this state, please try again soon by refreshing the browser or select a different state.<br><br><div id='selectAState' style='text-align:left;display:block'><form><select name=\"state\" onChange='changeState(this.options[this.selectedIndex].value)'>"+resp+"</select></form></div>";


 var channelNodes = response.getElementsByTagName("channel").item(0).childNodes;

		for (var i = 0; i < channelNodes.length ; i++) {
		 var node = channelNodes.item(i);
		 if (node.nodeName == "title") {
			var title = node.firstChild.nodeValue;
		 }
		 if (node.nodeName == "link") {
			var link = node.firstChild.nodeValue; 
		 }
		} 
 // Append the title and description to the HTML string.
 html += "<a href=\"http://ebird.org/\" style=\"float:left;\" target=\"_parent\" ><img src=\"http://ebird.org/eBirdCommon/images/ebird_logo.gif\" /></a>" + title + " <a style='text-align:center; font-size: 70%; font-weight: 100' href=\"javascript:void(0)\" onclick=\"javascript:toggleState();\">(change)</a></div><div id='selectAState' style='text-align:center;display:none;line-height:40px;'><a href=\"http://ebird.org/\" style=\"float:left;\" target=\"_parent\" ><img src=\"http://ebird.org/eBirdCommon/images/ebird_logo.gif\" /></a><form>&nbsp;<select name=\"state\" onChange='changeState(this.options[this.selectedIndex].value)'>"+resp+"</select></form></div>";
 // Get a list of the <item> element nodes in the file
 var itemList = response.getElementsByTagName("item");
 if (itemList.length == 0) {
  html = "<div id='title' style='text-align:center; font-size: 150%; font-weight: 700;line-height:40px;'>"; 
  html += "<a href=\"http://ebird.org/\" style=\"float:left;\" target=\"_parent\" ><img src=\"http://ebird.org/eBirdCommon/images/ebird_logo.gif\" /></a><form>" + title + " <select name=\"state\" onChange='changeState(this.options[this.selectedIndex].value)'>"+resp+"</select></form></div><br><div font-family:Arial, Helvetica; text-align:left;font-size:90%'>No Notable Sightings have been reported for "+title+ "</div>";
  _gel("content_div").innerHTML = html;
  return;
 }
html += "<div class=\"uftl\" style=\"text-align:right;\"><a style=\"float:left;display:none;\" href=\"javascript:void(0)\" id='hide_all'  onclick=\"javascript:toggleDesc("+itemList.length+",'hide');\">hide details</a><a style=\"float:left;\" href=\"javascript:void(0)\" id='show_all' onclick=\"javascript:toggleDesc("+itemList.length+",'show');\">show details</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='http://ebird.org/eBirdCommon/images/checkmark.gif'  width='14' height='14'/> = Sighting confirmed by an eBird reviewer.</div>";

 // Loop through all <item> nodes
 for (var i = 0; i < itemList.length ; i++) { 
 // For each <item> node, get child nodes.
 var nodeList = itemList.item(i).childNodes;
 var itemCounty = "";
 for (var j = 0; j < nodeList.length ; j++) {
var node = nodeList.item(j);
if (node.nodeName == "species_name") {
 var itemSpecies = node.firstChild.nodeValue;
}
if (node.nodeName == "observation_date") {
 var itemDate = node.firstChild.nodeValue;
}
if (node.nodeName == "county") {
 itemCounty = node.firstChild.nodeValue + " Co.";
}
if (node.nodeName == "obs_reviewed") {
 var itemReviewed = node.firstChild.nodeValue;
}
if (node.nodeName == "obs_valid") {
 var itemValid = node.firstChild.nodeValue;
}
if (node.nodeName == "link") {
 var itemLink = node.firstChild.nodeValue;
 itemLink = itemLink.replace("&amp;","%26");
}
if (node.nodeName == "description") {
 var itemDescription = node.firstChild.nodeValue;
}
 }  
 var reviewedIMG = "<img src='http://ebird.org/eBirdCommon/images/spacer_trans.gif' width='14' />";
 var bkgColor = "FFF4C2";
 if (itemReviewed == "1")
 {
     reviewedIMG = "<img src='http://ebird.org/eBirdCommon/images/checkmark.gif' width='14' height='14'/>";
 }
 if (itemValid == "1")
 {
     bkgColor = "ccf3b4";
 }
 // Append extracted data to the HTML string.
 html += "<div class=\"uftl\"><a href=\"javascript:void(0)\" id='tog_"+i+"' class='fmaxbox' onclick=\"toggleMenu('"+i+"');\" ></a>&nbsp;&nbsp;"+reviewedIMG+itemSpecies+" - "+itemCounty+" - "+itemDate+" <a href='"+itemLink+"' target='_blank'>map</a></div>"; 
 html += "<div id=\"summary_"+i+"\" style=\"display:none; background-color:#"+ bkgColor + "\">" + itemDescription
 if (itemValid == "0" && itemReviewed == "0")
    html += "This sighting has not yet been reviewed by an eBird reviewer. ";
    
 html += "</div>";
 } 

 // Close up div
 html += "</div>";
 
// Display HTML string in <div>
_gel('content_div').innerHTML = html; 
// Tells gadget to resize itself
if (gHeight > 0) {  _IG_AdjustIFrameHeight(gHeight); } else {  _IG_AdjustIFrameHeight(); } 

  }, { refreshInterval: (60 * 10) });}, { refreshInterval: 60 * 15 });
}
_IG_RegisterOnloadHandler(displayBirdData);

</script>
]]> 
</Content>
</Module>
