<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
	<ModulePrefs title="WI Humane - Available Small Animals"
		title_url="http://wihumane.org/animals/smallanimals.aspx"
		height="425"
		width="300"
		author="Ben L."
		author_link="http://llamaslayers.net/"
		author_email="ben+wihumane.gadgets@llamaslayers.net"
		description="See the current small animals up for adoption at the Wisconsin Humane Society right from your iGoogle homepage!"
		screenshot="http://llamaslayers.googlecode.com/svn/gadgets/whs/small-animals-screenshot.png"
		thumbnail="http://llamaslayers.googlecode.com/svn/gadgets/whs/small-animals-thumbnail.png"
		category="lifestyle">
		<Require feature="dynamic-height"/>
		<Icon>http://llamaslayers.googlecode.com/svn/gadgets/whs/paw.png</Icon>
	</ModulePrefs>
	<UserPref name="refreshSpeed" display_name="Refresh Speed (Seconds)" default_value="45"/>
	<Content type="html">
		<![CDATA[
<base href="http://www.wihumane.org/animals/smallanimals.aspx" target="_top"/>
			<div id="content_div" style="text-align: center; margin-top: 5px">
				<big>Loading...</big>
				<div id="c" style="display: none">
					<h1></h1><br/>
					<span></span><br/>
					<small></small>
				</div>
			</div>
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
		<script type="text/javascript">
function strtotime(G,B){var E,F,J,I="",D="";I=G;I=I.replace(/\s{2,}|^\s|\s$/g," ");I=I.replace(/[\t\r\n]/g,"");if(I=="now"){return(new Date()).getTime()/1000}else{if(!isNaN(D=Date.parse(I))){return(D/1000)}else{if(B){B=new Date(B*1000)}else{B=new Date()}}}I=I.toLowerCase();var A=function(K){var N=(K[2]&&K[2]=="ago");var M=(M=K[0]=="last"?-1:1)*(N?-1:1);switch(K[0]){case"last":case"next":switch(K[1].substring(0,3)){case"yea":B.setFullYear(B.getFullYear()+M);break;case"mon":B.setMonth(B.getMonth()+M);break;case"wee":B.setDate(B.getDate()+(M*7));break;case"day":B.setDate(B.getDate()+M);break;case"hou":B.setHours(B.getHours()+M);break;case"min":B.setMinutes(B.getMinutes()+M);break;case"sec":B.setSeconds(B.getSeconds()+M);break;default:var L;if(typeof (L=C.day[K[1].substring(0,3)])!="undefined"){var O=L-B.getDay();if(O==0){O=7*M}else{if(O>0){if(K[0]=="last"){O-=7}}else{if(K[0]=="next"){O+=7}}}B.setDate(B.getDate()+O)}}break;default:if(/\d+/.test(K[0])){M*=parseInt(K[0]);switch(K[1].substring(0,3)){case"yea":B.setFullYear(B.getFullYear()+M);break;case"mon":B.setMonth(B.getMonth()+M);break;case"wee":B.setDate(B.getDate()+(M*7));break;case"day":B.setDate(B.getDate()+M);break;case"hou":B.setHours(B.getHours()+M);break;case"min":B.setMinutes(B.getMinutes()+M);break;case"sec":B.setSeconds(B.getSeconds()+M);break}}else{return false}break}return true};var C={day:{sun:0,mon:1,tue:2,wed:3,thu:4,fri:5,sat:6},mon:{jan:0,feb:1,mar:2,apr:3,may:4,jun:5,jul:6,aug:7,sep:8,oct:9,nov:10,dec:11}};F=I.match(/^(\d{2,4}-\d{2}-\d{2})(?:\s(\d{1,2}:\d{2}(:\d{2})?)?(?:\.(\d+))?)?$/);if(F!=null){if(!F[2]){F[2]="00:00:00"}else{if(!F[3]){F[2]+=":00"}}J=F[1].split(/-/g);for(E in C.mon){if(C.mon[E]==J[1]-1){J[1]=E}}J[0]=parseInt(J[0],10);J[0]=(J[0]>=0&&J[0]<=69)?"20"+(J[0]<10?"0"+J[0]:J[0]+""):(J[0]>=70&&J[0]<=99)?"19"+J[0]:J[0]+"";return parseInt(this.strtotime(J[2]+" "+J[1]+" "+J[0]+" "+F[2])+(F[4]?F[4]/1000:""),10)}var H="([+-]?\\d+\\s(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?|sun.?|sunday|mon.?|monday|tue.?|tuesday|wed.?|wednesday|thu.?|thursday|fri.?|friday|sat.?|saturday)|(last|next)\\s(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?|sun.?|sunday|mon.?|monday|tue.?|tuesday|wed.?|wednesday|thu.?|thursday|fri.?|friday|sat.?|saturday))(\\sago)?";F=I.match(new RegExp(H,"g"));if(F==null){return false}for(E in F){if(!A(F[E].split(" "))){return false}}return(B.getTime()/1000)}
function time_since(z,A){function B(){var s=/%%|%(\d+\$)?([-+#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuidfegEG])/g;var a=arguments,i=0,t=a[i++];var u=function(a,b,c,d){var e=(a.length>=b)?'':Array(1+b-a.length>>>0).join(c);return d?a+e:e+a};var v=function(a,b,c,d,e){var f=d-a.length;if(f>0){if(c||!e){a=u(a,d,' ',c)}else{a=a.slice(0,b.length)+u('',f,'0',true)+a.slice(b.length)}}return a};var w=function(a,b,c,d,e,f,g){var h=a>>>0;c=c&&h&&{'2':'0b','8':'0','16':'0x'}[b]||'';a=c+u(h.toString(b),f||0,'0',false);return v(a,c,d,e,g)};var x=function(a,b,c,d,e){if(d!=null){a=a.slice(0,d)}return v(a,'',b,c,e)};var y=function(b,c,d,e,_,f,g){if(b=='%%')return'%';var h=false,k='',l=false,m=false;for(var j=0;d&&j<d.length;j++)switch(d.charAt(j)){case' ':k=' ';break;case'+':k='+';break;case'-':h=true;break;case'0':l=true;break;case'#':m=true;break}if(!e){e=0}else if(e=='*'){e=+a[i++]}else if(e.charAt(0)=='*'){e=+a[e.slice(1,-1)]}else{e=+e}if(e<0){e=-e;h=true}if(!isFinite(e)){throw new Error('sprintf: (minimum-)width must be finite');}if(!f){f='fFeE'.indexOf(g)>-1?6:(g=='d')?0:void(0)}else if(f=='*'){f=+a[i++]}else if(f.charAt(0)=='*'){f=+a[f.slice(1,-1)]}else{f=+f}var n=c?a[c.slice(0,-1)]:a[i++];switch(g){case's':return x(String(n),h,e,f,l);case'c':return x(String.fromCharCode(+n),h,e,f,l);case'b':return w(n,2,m,h,e,f,l);case'o':return w(n,8,m,h,e,f,l);case'x':return w(n,16,m,h,e,f,l);case'X':return w(n,16,m,h,e,f,l).toUpperCase();case'u':return w(n,10,m,h,e,f,l);case'i':case'd':{var o=parseInt(+n);var p=o<0?'-':k;n=p+u(String(Math.abs(o)),f,'0',false);return v(n,p,h,e,l)}case'e':case'E':case'f':case'F':case'g':case'G':{var o=+n;var p=o<0?'-':k;var q=['toExponential','toFixed','toPrecision']['efg'.indexOf(g.toLowerCase())];var r=['toString','toUpperCase']['eEfFgG'.indexOf(g)%2];n=p+Math.abs(o)[q](f);return v(n,p,h,e,l)[r]()}default:return b}};return t.replace(s,y)}var C=Math.round(new Date().getTime()/1000);var D=z;if(isNaN(D)){D=Math.round(new Date(D).getTime()/1000)}var E=[[60*60*24*365,'year','years'],[60*60*24*30,'month','months'],[60*60*24*7,'week','weeks'],[60*60*24,'day','days'],[60*60,'hour','hours'],[60,'minute','minutes'],[1,'second','seconds']];var F=C-D;for(var i=0,j=E.length;i<j;i++){var G=E[i][0];var H=E[i][1];var I=E[i][2];var J=Math.floor(F/G);if(0!=J)break}var K=B('%1$d %2$s',J,J==1||!A?H:I);if(i+1<j&&A){var L=E[i+1][0];var M=E[i+1][1];var N=E[i+1][2];var O=Math.floor((F-G*J)/L);if(0!=O)K+=B(', %1$d %2$s',O,O==1?M:N)}return K}

				var updateTimer;

				$('img').live('load', function(){gadgets.window.adjustHeight()});

				function getTheData(){
					var params = {};
					params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
					var url = "http://www.wihumane.org/animals/smallanimals.aspx?nocache=" + Math.floor((new Date - 900000) / 3600000);
					gadgets.io.makeRequest(url, parseTheData, params);
				}
				function parseTheData(obj){
					$('img, strong').remove();

					if ($('#c').is(':visible')) {
						$('#c').slideUp('normal', function(){
							parseTheData(obj);
						});
						return;
					}

					$('body').css({backgroundColor: 'transparent'});

					var wihumane = $(obj.text).find('img').each(function(){
						this.src = gadgets.io.getProxyUrl(this.src.indexOf('camerashy.jpg') > -1 ? 'http://llamaslayers.googlecode.com/svn/gadgets/whs/camerashy.gif' : $(this).attr('src').substr(0, 4) == 'http' ? $(this).attr('src') : ($(this).attr('src')[0] == '/' ? 'http://www.wihumane.org' + $(this).attr('src') : 'http://www.wihumane.org/animals/' + $(this).attr('src')));
					}).end(),
					animals = wihumane.find('#animalList_tableSingles a:has(img)');
					doubles = wihumane.find('#animalList_tablePairs tr:nth-child(odd)');
					if (!updateTimer)
						updateTimer = setTimeout(function updateTime(){
							$('small').text('Last updated ' + time_since(strtotime(wihumane.find('#Controlanimallastupdate1_labelLastUpdate').text()), true) + ' ago.').css({color: '#aaa'});
							setTimeout(updateTime, 750);
						}, 5);

						var animal = animals.eq(Math.floor(Math.random() * animals.length));

						var img = animal.children('img').removeAttr('height').css({maxWidth: 300, maxHeight: 300});
						var name = wihumane.find('.animal-name a[href="' + animal.attr('href') + '"]');

						var stats = name.parent().next().html().replace(/<br>/, ' ').replace(/\/(Spayed|Neutered)/, '').split(/<br>/).reverse();
						$('span').text((stats[2] == 'Adult' || stats[2] == 'Juvenile' ? stats[2] + ' ' : (time_since(strtotime(stats[2] + ' ago')) + ' old ')) + stats[3]);
						$('h1').css({margin: '0 0 5px'}).text('Meet ').append(name.attr({href: 'http://www.wihumane.org/animals/'+name.attr('href'), target: '_top'}).css({color: '#27568f', textDecoration: 'none'})).append(':').after(img.css({border: '1px solid #ccc'}));
						$('#c').css({position: 'relative', margin: '25px auto 0', textAlign: 'center', width: 300, background: '#eee', border: '1px solid #ccc', MozBorderRadius: '10px', WebkitBorderRadius: '10px', borderRadius: '10px', font: '16px/1 "Lucida Sans", Tahoma, Helvetica, Verdana, Arial, sans-serif'}).animate({height: 'show', opacity: 'show', marginTop: 0}, 2500, 'swing', gadgets.window.adjustHeight).prepend(stats.join(' ').indexOf('Female') == -1 ? $('<strong/>').attr({title: 'Male'}).css({background: '#77f', MozBorderRadiusBottomleft: '7px', MozBorderRadiusTopright: '9px', WebkitBorderBottomLeftRadius: '7px', WebkitBorderTopRightRadius: '9px', borderBottomLeftRadius: '7px', display: 'block', height: 15, paddingLeft: 15, border: '1px solid #ddd', borderWidth: '0 0 1px 1px', 'float': 'right', opacity: 0.5}) : $('<strong/>').attr({title: 'Female'}).css({background: '#f77', MozBorderRadiusBottomleft: '7px', MozBorderRadiusTopright: '9px', WebkitBorderBottomLeftRadius: '7px', WebkitBorderTopRightRadius: '9px', borderBottomLeftRadius: '7px', borderTopRightRadius: '9px',  display: 'block', height: 15, paddingLeft: 15, border: '1px solid #ddd', borderWidth: '0 0 1px 1px', 'float': 'right', opacity: 0.5}));
						$('strong').hover(function(){
							$(this).stop().fadeTo(500, 1);
						}, function(){
							$(this).stop().fadeTo(500, .5);
						});
					$('big').hide('slow', function(){
						$(this).remove();
					});
					setTimeout(getTheData, (new gadgets.Prefs()).getInt('refreshSpeed') * 1000);
				}
				gadgets.util.registerOnLoadHandler(getTheData);
			</script>
		]]>
	</Content>
</Module>

