<?xml version="1.0" encoding="UTF-8" ?>
<Module>
	<ModulePrefs
		title="Music, Movies, Books Finder"
		title_url="http://tastekid.com"
		directory_title="Music Finder"
		description="Just type in your favorite bands, movies and/or books, and you will get recommendations based on what you like. A gadget that helps you explore your taste. Brought to you by Emmy the Taste Kid."
		screenshot="http://tastekid.com/gadget/files/screenshot.png"
		thumbnail="http://tastekid.com/gadget/files/thumbnail.png"
		height="200"
		scrolling="true"
		author="Felix Oghina"
		author_email="znupi69+gemmy@gmail.com"
		author_affiliation="none"
		author_location="Bucharest, Romania"
		author_photo="http://i80.photobucket.com/albums/j161/znupi/gclock/author_photo.png"
		author_aboutme="I'm a high-school student (this is being written on 8/7/2008), soon to be a college student. I'm 17 years old at the time of writing, and I love to code. Also like beer ;-)."
		author_quote="if you think every day that today is the last day of your life, one day you'll certainly be right!"
	>
		<Require feature="dynamic-height" />
		<Require feature="minimessage" /> 
		<Require feature="analytics" />
	</ModulePrefs>
	<Content type="html">
	<![CDATA[
		<style type="text/css">
			* { margin: 0; padding: 0; }
			div.inputDiv {
				text-align: center;
			}
			div.inputDiv input {
				background: url("http://tastekid.com/gadget/files/input.gif") 0 0 no-repeat;
				border: none;
				font: bold 16px "Trebuchet MS", Arial, sans-serif;
				padding: 4px 5px 4px 10px;
				vertical-align: middle;
				width: 80%;
				color: #fff;
			}
			div.inputDiv button {
				background: url("http://tastekid.com/gadget/files/button.gif") 0 0 repeat-y;
				border: none;
				width: 40px;
				height: 30px;
				vertical-align: middle;
				cursor: pointer;
			}
			div.inputDiv button:hover {
				background-position: 0 -30px;
			}
			div.inputDiv button span {
				display: none;
			}
			div#loader {
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 100%;
				background: url("http://tastekid.com/gadget/files/load.gif") 50% 50% no-repeat #A5A5A5;
				opacity: 0.5;
				filter: alpha(opacity=50);
				display: none;
			}
			div#expand {
				display: none;
			}
			div#collapse {
				background: url("http://tastekid.com/gadget/files/collapse.gif") 50% 50% no-repeat #F5F5F5;
				height: 30px;
				cursor: pointer;
			}
			div#collapse:hover {
				background-color: #EFEFEF;
			}
			div#content {
				margin: 5px 0;
				min-height: 130px;
			}
			h2 {
				font: bold 16px "Trebuchet MS", "Arial", sans-serif;
				color: #2592A9;
			}
			p {
				font: 12px "Trebuchet MS", "Arial", sans-serif;
			}
			form {
				display: inline;
			}
			a, a:visited {
				color: #00f;
			}
			a:hover {
				text-decoration: none;
			}
		</style>
		<script type="text/javascript">
			_IG_AdjustIFrameHeight(30);
			
			String.prototype.ucwords = function() {
				return (" " + this.toLowerCase()).replace(/\s+\w/g, function(s) {
    			return s.substr(0, s.length-1) + s.charAt(s.length-1).toUpperCase();
				}).substr(1)
			}
			
			var maxItems = 1000;
			
			var mini = new _IG_MiniMessage(__MODULE_ID__);
			var suggestions = { music: [ ], movies: [ ], books: [ ] };
			function inputFocused() {
				if (_gel('q').value == 'Favorite bands/movies/books') _gel('q').value = '';
			}
			function inputBlurred() {
				if (_gel('q').value == '') _gel('q').value = 'Favorite bands/movies/books';
			}
			function makeSmall() {
				_gel('expand').style.display = "none";
				_IG_AdjustIFrameHeight(30);
			}
			function fetchData() {
				_gel('loader').style.display = "block";
				var loc = "http://www.tastekid.com/ask/ws?g=1&q=" + encodeURIComponent(_gel('q').value);
				_IG_FetchXmlContent(loc, handleData);
				return false;
			}
			function handleData(xml) {
				if (xml == null || typeof(xml) != "object" || xml.firstChild == null) {
					mini.createTimerMessage("There was a problem communicating with the server. Please try again in a few moments.", 5, makeSmall);
					_IG_AdjustIFrameHeight(60);
					_gel('loader').style.display = "none";
					return;
				}
				suggestions.music = [ ]; suggestions.movies = [ ]; suggestions.books = [ ];
				var resources = xml.getElementsByTagName("results").item(0).getElementsByTagName("resource");
				if (!resources.length) {
					html = "<h2>No Recommendations Found</h2><p>Please write only bands, artists, movies or book titles, separated by commas. E.g.: Beethoven, Britney Spears, Trainspotting</p>";
					_gel('content').innerHTML = html;
					_gel('expand').style.display = "block";
					_IG_AdjustIFrameHeight(200);
					_gel('loader').style.display = "none";
					return;
				}
				var rName;
				var rType;
				for (var i=0; i < Math.min(resources.length, 20); i++) {
					rName = resources.item(i).getElementsByTagName("name").item(0).firstChild.nodeValue;
					rType = resources.item(i).getElementsByTagName("type").item(0).firstChild.nodeValue;
					switch(rType) {
						case "music": suggestions.music.push(rName); break;
						case "movie": suggestions.movies.push(rName); break;
						case "book": suggestions.books.push(rName); break;
					}
				}
				var loc = "http://www.tastekid.com/ask?q=" + encodeURIComponent(_gel('q').value) + "&g=1";
				
				if (suggestions.music.length) {
					var music = "<h2>Recommended Music</h2><p>";
					for (i = 0; i < Math.min(suggestions.music.length, maxItems); i++) {
						music += suggestions.music[i].ucwords() + ", ";
					}
					music = music.substr(0, music.length-2);
					music += " <a href=\"" + loc + "\" target=\"_blank\">More from Emmy &raquo;</a>";
					music += "</p>";
				}
				
				if (suggestions.movies.length) {
					var movies = "<h2>Recommended Movies</h2><p>";
					for (i = 0; i < Math.min(suggestions.movies.length, maxItems); i++) {
						movies += suggestions.movies[i].ucwords() + ", ";
					}
					movies = movies.substr(0, movies.length-2);
					movies += " <a href=\"" + loc + "\" target=\"_blank\">More from Emmy &raquo;</a>";
					movies += "</p>";
				}
				
				if (suggestions.books.length) {
					var books = "<h2>Recommended Books</h2><p>";
					for (i = 0; i < Math.min(suggestions.books.length, maxItems); i++) {
						books += suggestions.books[i].ucwords() + ", ";
					}
					books = books.substr(0, books.length-2);
					books += " <a href=\"" + loc + "\" target=\"_blank\">More from Emmy &raquo;</a>";
					books += "</p>";
				}
				var html = '';
				for (i=0; i < 3; i++) {
					if (suggestions.music.length >= suggestions.movies.length && suggestions.music.length >= suggestions.books.length && suggestions.music.length) {
						html += music;
						suggestions.music = [ ];
					}
					else if (suggestions.movies.length >= suggestions.music.length && suggestions.movies.length >= suggestions.books.length && suggestions.movies.length) {
						html += movies;
						suggestions.movies = [ ];
					}
					else if (suggestions.books.length >= suggestions.music.length && suggestions.books.length >= suggestions.movies.length && suggestions.books.length) {
						html += books;
						suggestions.books = [ ];
					}
				}
				_gel('content').innerHTML = html;
				_gel('expand').style.display = "block";
				_IG_AdjustIFrameHeight(200);
				_gel('loader').style.display = "none";
			}
			
			_IG_Analytics('UA-2716740-10', '/gadget')
		</script>
		<div id="loader"></div>
		<div class="inputDiv"><form onsubmit="return fetchData()"><input type="text" id="q" value="Favorite bands/movies/books" onfocus="inputFocused()" onblur="inputBlurred()"><button type="submit"><span>Suggest</span></button></form></div>
		<div id="expand">
			<div id="content"></div>
			<div id="collapse" title="Collapse" onclick="makeSmall()"></div>
		</div>
	]]>
	</Content>
</Module>
