<?xml version="1.0" encoding="UTF-8"?>
<Module>
	<ModulePrefs description="__MSG_description__" 
				thumbnail="http://earth.google.com/gadget/images/thumbnail.jpg" 
				screenshot="http://earth.google.com/gadget/images/screenshot.jpg" 
				title="__MSG_gTitle__"
				title_url="__MSG_gTitle_url__" 
				author_email="kmlgallery@google.com" height="250" width="300">
    <Locale messages="http://earth.google.com/gadget/all_all.xml"/>
	<Require feature="analytics" />
    <Require feature="dynamic-height"/>
	<Require feature="setprefs"/>
  </ModulePrefs>
  <UserPref name="seen_items_list" default_value="" datatype="hidden" />
  <UserPref name="seen_date" default_value="0" datatype="hidden" />

  <Content type="html"> <![CDATA[
	
<style type="text/css">
  * {behavior: url(/ig/proxy?url=http%3A%2F%2Fcdn.labpixies.com%2Flib%2Ffixpng%2Fiepngfix.htc) }
  body {
    width:100%;
	font-family: Arial, Helvetica, sans-serif;
	margin:0px;
	padding:0px;
	
   }
      
   .titleText, .titleText:hover, .titleText:visited {
        font-weight:bold;
	    text-decoration:none;
		color: #000000;
		font-size:75%;
		padding-left:5px;
   }
   
   #kml_auth{
		font-weight:bold;
		color: #000000;
		font-size:75%;
		padding-left:5px;
   }
   
   #kml_description {
	font-size:75%;
	text-align:left;
	width:100%;
	margin:5px;
	overflow:hidden;
	line-height:14px;
	height:42px;
   }
   
   .pageText {
    font-weight:bold;
	font-size:75%;
   }
   
   .arrow {
		border: 0px;
		cursor:pointer;
   }
   
   .getGoogleEarth {
    font-size:10px;
    color: #666666;
    height:14px;
    overflow:hidden;
	
   }
   
   .getGoogleEarthLink, .getGoogleEarthLink:visited, .getGoogleEarthLink:hover {
   
      font-size:10px;
      color:#0000cc;
   }
   
	#new_div{
		height:24px;
		line-height:24px;
		margin-top:5px;
		overflow:hidden;
	}

	.newKMLs{
		color:#dc4a20;
		font-size:12px;
		font-weight:bold;
		padding-left:10px;
	}
	
	
	#newItem{
		font-size:12px;
		height:18px;
	}
		
	#btn_center_part {
	
		font-size: 11px;
		color: #ffffff;
		font-weight:bold;
		font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
	}
   
</style>
<script type="text/javascript">

function FeedItem(item) {

	this.auth = "";
	this.title = "";
	this.desc = "";
	this.link = "";
	this.storyLink = "";
	this.background = "";
	this.isvalid = true;
	
	var childNodes = item.childNodes;
	if (!childNodes) {
		this.isvalid = false;
		return;
	}
	for (var k = 0; k < childNodes.length; k++) {
		var node = childNodes[k];
		var name = node.nodeName;
		// unsupported locales will be redirected to the old gallery so we need to
                // support both formats.
		switch (name) {
			case "ghapi:screenshot":
                        case "gadgets:screenshot":
				this.background = (node.firstChild) ? node.firstChild.nodeValue : null;
				break;
			case "title":
				this.title = (node.firstChild) ? node.firstChild.nodeValue : null;
				break;
			case "link":
				this.storyLink = (node.firstChild) ? node.firstChild.nodeValue : null;
				break;
			case "ghapi:more_info":
                        case "alternate_url":
				this.link = (node.firstChild) ? node.firstChild.nodeValue : null;
				break;
			case "description":
				this.desc = (node.firstChild) ? node.firstChild.nodeValue : null;
				if (this.desc) {
					if (this.desc.length > 200)
						this.desc = this.desc.substring(0,200) + "...";
				}
				break;
			case "ghapi:author_name":
			case "author":
				this.auth = (node.firstChild) ? node.firstChild.nodeValue : null;
				break;
			default:
				break;
		}
	}
}	

var curIndex = 0;
var itemNum = 0;
var newlinkTarget = "";
var feedItems = [];
var seenItems = [];
var prefs = new _IG_Prefs();

function next() {
	reportNextPrev();
	if (itemNum == 0)
	return;

	curIndex = (curIndex+1)%itemNum;
	updateUI();
}
   
function prev() {
	reportNextPrev();
	if (itemNum == 0)
	  return;

	curIndex = (curIndex+itemNum-1)%itemNum;
	updateUI();
}

function reportNextPrev() {
	_IG_Analytics('UA-18031-13', '/kmlgadget/navclick');
}

function reportKMLClick() {

	try {
	  window.top.location = feedItems[curIndex].link;
	  var aa = feedItems[curIndex].link.split('/');
	  var kmlFileName = feedItems[curIndex].link;
	  if (aa.length > 2)
		kmlFileName = aa[aa.length-1];
	  _IG_Analytics('UA-18031-13', '/kmlgadget/'+kmlFileName+'click');

	} catch (ee) {}

}
  
function reportDownload() {
	_IG_Analytics('UA-18031-13', '/kmlgadget/dlgeclick');
}
  
function reportTitle() {
    _IG_Analytics('UA-18031-13', '/kmlgadget/titleclick');
}
  
function gotoNew() {
	if (!newlinkTarget)
           return;
	window.top.location = "__MSG_gallery_base__?pid=earth&synd=earth&url="+encodeURIComponent(newlinkTarget);
	_IG_Analytics('UA-18031-13', '/kmlgadget/newlinkclicked');
     
}
  
function reportImageClick() {
    
	window.top.location = "http://earth.google.com/gallery/#utm_source=en-igg-kmlg&utm_medium=igg-ss&utm_campaign=en";
    _IG_Analytics('UA-18031-13', '/kmlgadget/shotclick');
      
}
  
function updateUI() {
   
    _gel("kml_img").src = feedItems[curIndex].background;
    _gel("kml_title").innerHTML = feedItems[curIndex].title;
    _gel("kml_title").href = "__MSG_gallery_base__?pid=earth&synd=earth&num=24&url=" + escape(feedItems[curIndex].storyLink)+"&output=html";
    _gel("kml_auth").innerHTML = feedItems[curIndex].auth;
    _gel("kml_description").innerHTML = feedItems[curIndex].desc;
    _gel("num_pages").innerHTML = (curIndex+1) + " __MSG_out_of__ " + itemNum;
    _IG_AdjustIFrameHeight();
    
}
	
function setErrorMsg() {
	_gel("kml_title").innerHTML = "__MSG_error_msg__";
	_gel("kml_title").href = "javascript:void(0);";
}

//return true if the item.title is not in the seenItems array
function isUnSeen(item) {
	
	for (var i=0;i<seenItems.length; i++) {
		if (seenItems[i] == item.title)
			return false;
	}
		
	return true;
}

//get all unseen items into the feedItems array
function parseFeatured(xml){
      
	try {
		var nodes = xml.documentElement.getElementsByTagName("item");
		itemNum = 0;
		for(i = 0; i<nodes.length && itemNum<6; i++) {
			var item = new FeedItem(nodes[i]);
			if (item.isvalid && isUnSeen(item))
				feedItems[itemNum++] = item;
		}
		
		if (itemNum==0)
			return;

		if (itemNum < 6)
		  curIndex = 0;
		else  {
		  var todayDay = (new Date()).getDay();
		  curIndex = todayDay-1;
		  if (todayDay==0)
			curIndex = 5;
		}  
		
		setSeenItems();
		updateUI();
    } catch (ee) {
        setErrorMsg();
    }
}
	
//parse the new feed
function parseNew(xml){
  
	try {
		var items = new Array();
		var nodes = xml.documentElement.getElementsByTagName("item");
		for (var i = 0; i < nodes.length && i < 1; i++) {
			// Iterate through child nodes
			var childNodes = nodes[i].childNodes;
			for (var k = 0; k < childNodes.length; k++) {
				var node = childNodes[k];
				var name = node.nodeName;					
				if (name == "title") {
					_gel("newItem").innerHTML = node.firstChild.nodeValue;
				}
				if (name == "link") {
					newlinkTarget = node.firstChild.nodeValue;
				}
			}
		}
	} catch (ee) {}
}
   
function setWidth() {
  
  //if (navigator.userAgent.toLowerCase().indexOf("msie") > 0) {
	_gel("main_container").style.width = document.body.clientWidth > 300? "300px": "100%";
  //}
}
   
function positionElements() {
	var img = _gel("kml_img");
	var ps = getObjectPos(img);
	_gel("_trans_back").style.left = ps.left+1+"px";
	_gel("_trans_back").style.top = ps.top+104+"px";
	_gel("_trans_back").style.width = img.clientWidth;
	_gel("_title_back").style.left = ps.left+1+"px";
	_gel("_title_back").style.top = ps.top+106+"px";
	_gel("_title_back").style.width = img.clientWidth-5;
	_gel("kml_auth").style.left = ps.left+1+"px";
	_gel("kml_auth").style.top = ps.top+123+"px";
	_gel("kml_auth").style.width = img.clientWidth-5;
	
}

function getObjectPos(a){
	
	var b={};
	var c=a;
	b.left=c.offsetLeft;
	b.top=c.offsetTop;
	while(c.offsetParent!=null){
		var d=c.offsetParent;
		b.left+=d.offsetLeft;
		b.top+=d.offsetTop;
		c=d;
	}
	return b;
}

function restructureElements() {
	setWidth();
	positionElements();
}
	
function setSeenItems() {
	
	try {
		seenItems[seenItems.length] = feedItems[curIndex].title;
		prefs.set("seen_items_list", seenItems.join("##op1##"));
	} catch (e){}
}
	
function prepareSeenItems() {
	try {
		var seen = prefs.getString("seen_items_list");
		var a = seen.split("##op1##",10);
		var nowSeen = new Date();
		var lastSeen = new Date(prefs.getInt("seen_date"));
		
		//if this is the same day remove today item from the list so the user can still see it.
		if (nowSeen.getTime()-lastSeen.getTime() < (1000*3600*24) ) {
			a.pop();
			seenItems = a;
		} else {
			seenItems = a;
			prefs.set("seen_date", nowSeen.getTime());
		}
	} catch (e) {}
}
		
_IG_RegisterOnloadHandler(function () {

	loadImages();
	prepareSeenItems();
	var aa = _args();
	var hl = "";
	var gl = "";
	if (aa["lang"]) hl = aa["lang"];
	if (aa["country"]) gl = aa["country"];
	_IG_FetchXmlContent("__MSG_gallery_base__?pid=earth&synd=earth&cat=new&num=1&output=rss&hl="+hl+"&gl="+gl, parseNew,{refreshInterval:3600});
	_IG_FetchXmlContent("__MSG_gallery_base__?pid=earth&synd=earth&cat=featured&output=rss&hl="+hl+"&gl="+gl, parseFeatured,{refreshInterval:3600});
	restructureElements();
	window.onresize = restructureElements;
	
});

function loadImages() {

	_gel("left_arrow").src = _IG_GetCachedUrl("__MSG_image_base__left_off.gif");
	_gel("left_arrow").onmouseover=function () {this.src = _IG_GetCachedUrl("__MSG_image_base__left_roll.gif");}
	_gel("left_arrow").onmouseout=function () {this.src = _IG_GetCachedUrl("__MSG_image_base__left_off.gif");}

	_gel("right_arrow").src = _IG_GetCachedUrl("__MSG_image_base__right_off.gif");
	_gel("right_arrow").onmouseover=function () {this.src = _IG_GetCachedUrl("__MSG_image_base__right_roll.gif");}
	_gel("right_arrow").onmouseout=function () {this.src = _IG_GetCachedUrl("__MSG_image_base__right_off.gif");}

	_gel("btn_left_part").src= _IG_GetCachedUrl("__MSG_image_base__left.png");
	_gel("btn_center_part").style.background = "transparent url("+_IG_GetCachedUrl("__MSG_image_base__middle.png")+") 0px 0px repeat-x";
	_gel("btn_right_part").src= _IG_GetCachedUrl("__MSG_image_base__right.png");

	_gel("new_div").style.background = "transparent url("+_IG_GetCachedUrl("__MSG_image_base__just_in_background.gif")+") 0px 0px repeat-x";
		
}
	
  
</script>
		
<center>

<div id="main_container">
	
	<div id="get_earth_links_gadget" class="getGoogleEarth" align="right">__MSG_dont_have__ <a id="download_for_free" href="http://earth.google.com/download-earth.html#utm_source=en-igg-kmlg&utm_medium=igg-dl&utm_campaign=en" onclick="reportDownload();"  class="getGoogleEarthLink" target="_top">__MSG_download__</a></div>    
	<img onclick="reportImageClick();" id="kml_img" src="" style="width:99.3%; height:143px; border:1px solid #0000cc; cursor:pointer;" />
	<div id="_trans_back" style="position: absolute; left:0px; top:104px; height:40px;width:298px;filter: alpha(opacity=70);-khtml-opacity: 0.7;-moz-opacity: 0.7;opacity: 0.7;background-color:#ffffff;"></div>
	<div id="_title_back" style="position: absolute; left:0px; top:106px; height:17px; overflow:hidden;"><a id="kml_title" onClick="reportTitle();" class="titleText" href="" target="_top">&nbsp;</a></div>
	<div id="kml_auth" style="position: absolute; left:0px; top:123px; height:19px; overflow:hidden;">&nbsp;</div>

	<div id="kml_description" class="descriptionText"></div>
	<div id="kml_buttons" style="height:24px;">
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
			<tr valign="middle">
				<td width="30%" align="left">
					<table atyle="float:right;" border="0" cellpadding="0" cellspacing="2">
						<tr>
							<td width="11" align="right"><img id="left_arrow" width="11" height="11" class="arrow" onclick="prev();" /></td>
							<td id="num_pages" class="pageText" width="70%"  align="center">&nbsp;</td>
							<td width="11"  align="left"><img id="right_arrow" width="11" height="11" class="arrow" onclick="next();" /></td>
						</tr>
					</table>
				</td>
				<td width="70%" align="right">
						<table border="0" cellpadding="0" cellspacing="0" onclick="reportKMLClick();" style="cursor:pointer;">
						<tr>
							<td style="width:11px;"><img id="btn_left_part" border="0" width="11" height="22"></td>
							<td id="btn_center_part" class="open_button">__MSG_open_in__</td>
							<td style="width:11px;"><img id="btn_right_part" border="0" width="11" height="22"></td>
						</tr>
						</table>
					</a>
				</td>
			</tr>
		</table>
	</div>
</div>
<div id="new_div">
		<span class="newKMLs">__MSG_new_kml__</span>
		<a id="newItem" href="javascript:void(0);" onclick="gotoNew();"></a>
</div>
	

		
</center>

<script>
  _IG_Analytics("UA-18031-13", "/kmlgadget");
</script>

]]> 
</Content>
</Module>
