<?xml version="1.0" encoding="UTF-8" ?>
<Module>
	<ModulePrefs
		title="Free iTunes Downloads"
		description="Every week Apple puts a few free songs and some free videos on the iTunes Store. Usually these are free for just a week, sometime longer. This gadget helps you by listing all the free stuff in one place by category (music, videos, audiobooks, etc.) and giving you updates as new stuff is released. Put it on your homepage or website and you won't miss another freebie!"
		author="iT'S Free Downloads"
		author_email="widgets@itsfreedownloads.com"
		author_photo="http://www.itsfreedownloads.com/profile.png"
		author_aboutme="iT'S Free Downloads works hard to bring you the latest free and legal music and video downloads from iTunes."
		author_link="http://www.itsfreedownloads.com"
		author_quote="Music is good, free music is better!"
		author_affiliation="iT'S Free Downloads"
		screenshot="http://www.itsfreedownloads.com/ifd_gadget_screenshot.png"
		thumbnail="http://www.itsfreedownloads.com/ifd_gadget_thumbnail.png"
	   	title_url="http://www.itsfreedownloads.com/music-widgets/"
		singleton="true"
		scrolling="false">
		<Require feature="setprefs" />
		<Require feature="analytics" />
	</ModulePrefs>
	<UserPref 
    	name="lastTab" 
    	default_value="New" 
    	datatype="hidden"
	/>
	<UserPref 
    	name="minId" 
    	default_value="50" 
    	datatype="hidden"
	/>
	<UserPref 
    	name="maxId" 
    	default_value="100" 
    	datatype="hidden"
	/>
	<Content type="html">
	<![CDATA[
	<script>
  		_IG_Analytics("UA-345942-3", "/widgets/ifd-gadget");
	</script>
	

	<style type="text/css">

		* html .hollyhack { height: 0.01% }

		body
		{
			border: 0;
			margin: 0;
			padding: 40px 0 14px 0;
			_padding: 0 0 0 0;
			font-size: 12px;
			font-family: sans-serif;
			overflow: auto;
		}

		.light a:link    { text-decoration: none; color: black;    display: block; width: 100%; }
		.light a:visited { text-decoration: none; color: darkgrey; display: block; width: 100%; }
		.light a:active  { text-decoration: none; color: black;    display: block; width: 100%; }
		.light a:hover   { text-decoration: none; color: white;    display: block; width: 100%; background: #3D80DF; }
		.dark a:link     { text-decoration: none; color: black;    display: block; width: 100%; }
		.dark a:visited  { text-decoration: none; color: darkgrey; display: block; width: 100%; }
		.dark a:active   { text-decoration: none; color: black;    display: block; width: 100%; }
		.dark a:hover    { text-decoration: none; color: white;    display: block; width: 100%; background: #3D80DF; }

		div#header
		{
			background-repeat: repeat-x;
			_position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 40px;
			color: #4D4B46;
			min-width: 260px;
	   		position: fixed;
		}

		div#footer
		{
			background-repeat: repeat-x;
		  	_position: absolute;
		  	bottom: 0;
		  	left: 0;
		  	width: 100%;
		  	height: 14px;
			font-size: 9px;
			font-style: italic;
	   		position: fixed;
			color: #626262;
		}	
				
		.footer a:link    { text-decoration: none; color: linen; }
		.footer a:visited { text-decoration: none; color: linen; }
		.footer a:active  { text-decoration: none; color: linen; }
		.footer a:hover   { text-decoration: none; color: lightblue; }

		.tab
		{
			display: none;		
		}

		h3
		{
			padding: 0 4px 0 4px;
		}

		p
		{
			padding: 0 6px 0 6px;
		}

		div#tab
		{
			position: absolute;
		}

		.box
		{
			position: absolute;
			left: 10%;
			top: 0px;
			height: 40px;
			width: 55%;
		}

		img.boxl
		{
			float: left;
			position: absolute;
			left: 0px;
			top: 0px;
		}

		img.boxr
		{
			float: right;
			position: absolute;
			left: 100%;
			top: 0px;
		}

		select
		{
			font-family: sans-serif;
			font-size: 13px;
			position: absolute;
			left: 110%;
			top: 13px;
		}

		span.dark 
		{
			background-color: #F1F5FA; 
			color: black;
			font-size: small;
			display: block;
			width: 100%;
			white-space: nowrap;
			margin: 2px;
		}

		span.light 
		{
			background-color: white; 
			color: black;		
			font-size: small;
			display: block;
			width: 100%;
			white-space: nowrap;
			margin: 2px;		
		}

		span.hilite 
		{
			background-color: #FFFF66; 
			color: black;		
			font-size: small;
			display: block;
			width: 100%;
			white-space: nowrap;
			margin: 2px;		
		}

	</style>	
	<script>
	  _IG_RegisterOnloadHandler(function() {
	    _gel("boxleft").src = _IG_GetImageUrl("http://www.itsfreedownloads.com/boxleft.png");
	    _gel("boxright").src = _IG_GetImageUrl("http://www.itsfreedownloads.com/boxright.png");	
	    _gel("header").style.background = "url(" + _IG_GetImageUrl("http://www.itsfreedownloads.com/headercenter.png") + ") repeat-x";
	    _gel("footer").style.background = "url(" + _IG_GetImageUrl("http://www.itsfreedownloads.com/bottom.png")       + ") repeat-x";
	    _gel("box").style.background    = "url(" + _IG_GetImageUrl("http://www.itsfreedownloads.com/boxcenter.png")    + ") repeat-x";	
	  });
	</script>
	
	
	<div class="gadget" style="height: 100%; width: 100%; ">
		<div id="header" style="vertical-align: top;">
			<div id="box" class="box"><img id="boxleft" class="boxl" src="" /><img id="boxright" class="boxr" src="" />
				<form name="naviform">
				<select name="navisel" onchange="showTab(this.options[this.selectedIndex].value);">
					<option value="New">New</option>
					<option value="News">News</option>
					<option value="Music">Music</option>
					<option value="Videos">Videos</option>
					<option value="Clips">Clips</option>
					<option value="Books">Books</option>
					<option value="Games">Games</option>
					<option value="World">World</option>
					<option value="About">About</option>
				</select>
				</form>

				<center>
					<p style="padding: 0 0 0 0; margin-top:18px; font-weight: bold;">Free iTunes Downloads</p>
				</center>
			</div>
		</div>
		<div id="center" class="middle" style="overflow: auto; width: 100%">
			<div class="tab" id="About">
				<h3>How to use</h3><p class="about">Choose the type of iTunes download you are interested in with the selector at the top. The most recent downloads will be listed at the top, the oldest ones at the bottom. Click on the desired title and iTunes will open, showing the item. Double check that the item is listed as "Free" before downloading -- sometimes iTunes updates the pricing before <a href="http://www.itsfreedownloads.com" class="about" target="_blank"><i>iT&#39;S Free Downloads</i></a> can update this list. <i>iT&#39;S Free Downloads</i> isn&#39;t responsible if you end up paying for a previously free download. Also you must have an account in the appropriate country&#39;s iTunes Store. Unvisited links are black and visited links should be grey.</p>
				<p>The possible selections are:
					<ul>
						<li><i>New</i> - items that have been added since the last update. If you are just starting, everything will be new until the next update.</li>
						<li><i>News</i> - this is a list of the updates from <i>iT&#39;S Free Downloads</i> with more information about the latest downloads and other free iTunes offers.</li>
						<li><i>Music</i> - free song downloads from the US iTunes Store.</li>
						<li><i>Videos</i> - longer free videos (TV shows, movies, etc.) in the US iTunes Store</li>
						<li><i>Clips</i> - shorter free videos (previews, promos, etc.) in the US iTunes Store</li>
						<li><i>Books</i> - free audiobooks &amp; excerpts in the US iTunes Store</li>
						<li><i>Games</i> - free iPod games &amp; demos in the US iTunes Store</li>
						<li><i>World</i> - free downloads in the various international iTunes Stores</li>
						<li><i>About</i> - this page ;)</li>
					</ul>
				</p>
				<h3>About <i>iT&#39;S Free Downloads</i></h3><p><a href="http://www.itsfreedownloads.com" class="about" target="_blank"><i>iT&#39;S Free Downloads</i></a> is a website that provides a complete list of all the free stuff on Apple&#39;s iTunes Store. Every week Apple posts to the US iTunes Store a few free songs and at least one free video. There are also free songs available in some of the international iTunes Stores. Most times these free downloads are available for just a week, so you need to download them ASAP. Sometimes a download stays free for a long time -- these items can be hard to find, though. This gadget will help you find and enjoy all these free hidden treasures!</p>
				<p>If you like this gadget, please tell your friends! Also you might be interested in the <a href="http://www.google.com/ig/directory?url=http://www.itsfreedownloads.com/emusic_gadget.xml" class="about" target="_blank">Free emusic Daily MP3</a> gadget that shows you today&#39;s free music download from emusic. These free MP3s can be played in iTunes and on iPods, etc. and can be downloaded from anywhere in the world without signing up with emusic.</p>
			</div>
			<div class="tab" id="New">
				<i>currently there are no new free downloads available</i>
			</div>
			<div class="tab" id="News">
				<i>currently there are no posts on iT&#39;S Free Downloads</i>
			</div>
			<div class="tab" id="Books">
				<i>currently there are no free audiobooks available for download</i>
			</div>
			<div class="tab" id="Clips">
				<i>currently there are no free short videos available for download</i>
			</div>
			<div class="tab" id="Videos">
				<i>currently there are no free videos available for download</i>
			</div>
			<div class="tab" id="Music">
				<i>currently there are no free songs available for download</i>
			</div>
			<div class="tab" id="World">
				<i>currently there are no free international songs available for download</i>
			</div>
			<div class="tab" id="Games">
				<i>currently there are no free iPod games available for download</i>
			</div>
		</div>
		<div id="footer" style="float: bottom;">
			<center class="footer" style="margin:1px;">gadget by <a href="http://www.itsfreedownloads.com" target="_blank">iT&#39;S Free Downloads</a></center>
		</div>
	</div>
	<iframe id="loadframe" name="loadframe" style="width:0px; height:0px; border: 0px" src="">
	</iframe>
		
	<script type="text/javascript">
		function loadIframe(url) 
		{
			if (window.frames['loadframe']) 
			{
				window.frames['loadframe'].location = url;   
				return false;
		  	}

			return true;
		}

		var curtab;
		function showTab(tab)
		{
			var newtab = document.getElementById(tab);
			curtab.style.display = 'none';
			newtab.style.display = 'block';
			curtab = newtab;    
			
			prefs.set("lastTab", tab);     
		}
	
		function display() 
		{
			// Get user preferences
	     	var prefs = new _IG_Prefs(__MODULE_ID__);

			var lastTab = prefs.getString("lastTab");
	        for (var i = 0; i < document.naviform.navisel.length; i++)
	        {
	        	if(document.naviform.navisel.options[i].value == lastTab)
	        		document.naviform.navisel.selectedIndex = i;
	        }

			// preload images
			if (document.images)
			{
				img1 = new Image();
				img2 = new Image();
				img3 = new Image();
				img4 = new Image();
				img5 = new Image();
			
				img1.src = _IG_GetImageUrl("http://www.itsfreedownloads.com/headercenter.png");
				img2.src = _IG_GetImageUrl("http://www.itsfreedownloads.com/bottom.png");
				img3.src = _IG_GetImageUrl("http://www.itsfreedownloads.com/boxcenter.png");
				img4.src = _IG_GetImageUrl("http://www.itsfreedownloads.com/boxleft.png");
				img5.src = _IG_GetImageUrl("http://www.itsfreedownloads.com/boxright.png");
			}

			// adjust height of central scroll div
			var height = 400;
		  	if( typeof(window.innerHeight) == 'number' ) 
			{
		    	//Non-IE
		    	height = window.innerHeight;
		  	} 
			else if(document.documentElement && document.documentElement.clientHeight) 
			{
		    	//IE 6+ in 'standards compliant mode'
		    	height = document.documentElement.clientHeight;
		  	} 
			else if(document.body && document.body.clientHeight)
			{
		    	//IE 4 compatible
		    	height = document.body.clientHeight;
		  	}
				
			document.getElementById('center').style.height = height-54+'px';

			// fetch the list of downloads, generate html & put into <div>s
			_IG_FetchXmlContent("http://itsfreedownloads.com/a.xml", function (response) 
			{
				var prefs = new _IG_Prefs(__MODULE_ID__);
				var cats = response.getElementsByTagName("category");
				
				if (response == null || typeof(response) != "object" || response.firstChild == null)
					return;
				
				// find the new max idNum & update the new item display range
		       	var idNums = new Array();
				for (var i = 0; i < cats.length; i++)
				{
		              items = cats.item(i).getElementsByTagName("item");
		              var last = items.item(items.length-1);
		              idNums[i] = last.getAttribute('idnum');
				}
				var newMaxId = Math.max.apply( Math, idNums );
				
				var minId = prefs.getInt("minId");
				var maxId = prefs.getInt("maxId");

				if (newMaxId > maxId)
				{
					minId = maxId+1;
					maxId = newMaxId;
					
					prefs.set("minId", minId);
					prefs.set("maxId", maxId);
				}

				// get the various categories ("free songs", "free audiobooks", etc.)
				// Get updates on <a href=\"http://twitter.com/itsfreedwnlds\" target=\"_blank\">Twitter</a> or <a href=\"http://friendfeed.com/itsfreedwnlds\" target=\"_blank\">FriendFeed</a>!
				
				var randomnumber=Math.floor(Math.random()*11);
				if (randomnumber > 2)
				{
					var newHtml="<span class=\"hilite\"><a href=\"http://su.pr/AFInpk\"  target=\"_blank\">Over 1300 FREE MP3 songs</a>  ready for download on Amazon!</span>";
				}
				else
				{
					var newHtml="<span class=\"hilite\">Thank you to everyone who has <a href=\"http://bit.ly/6xaMp8\" target=\"_blank\">reviewed this gadget!</a></span>";
				}
				
				var newCount = 0;
				for (var j = 0; j < cats.length; j++)
				{
					var html = "";
										
					// figure out which <div> to put the html in
					text = cats.item(j).getAttribute('text');

					if (text == "Free Shows")
						divName = "Videos";
					else if (text == "Free Songs")
						divName = "Music";
					else if (text == "Free Audiobooks") 
						divName = "Books"; 
					else if (text == "Free Short")
						divName = "Clips";
					else if (text == "International")
						divName = "World";
					else if (text == "Free iPod Game")
						divName = "Games";
					else
						continue;
					
					// build html for <div>
					var items = cats.item(j).getElementsByTagName("item");
					for (var i = items.length-1; i >= 0; i--)
					{
						var hurl = items.item(i).getAttribute('url');
						var text = items.item(i).getAttribute('text');
						var id   = parseInt(items.item(i).getAttribute('idnum'));
						
						// alternate light/dark background for lines
						if (i % 2)
							html += "<span class=\"light\">";
						else
							html += "<span class=\"dark\">";

						html += "<a href=\"" + hurl + "\" target=\"_blank\" >" +  
							text + "</a></span>";
						
						// if its in the range of ids for new items, add to html for "New" <div>
						if ((id >= minId) && (id <= maxId))
						{
							newCount++;
							if (newCount % 2)
								newHtml += "<span class=\"light\">";
							else
								newHtml += "<span class=\"dark\">";
								
							newHtml += "<a href=\"" + hurl + "\" target=\"_blank\" >" +  
								text + "</a></span>";
						}
					}

			        // put html string in <div>
					_gel(divName).innerHTML = html;

				}					
		        // put html string in "New" <div>
				_gel("New").innerHTML = newHtml;

		    }, { refreshInterval: 5000 } );

			// fetch & put the feed info into the "News" <div>
	     	_IG_FetchFeedAsJSON("https://twitter.com/statuses/user_timeline/75181094.rss",
	        	function(feed) 
				{ 
	            	if (feed == null)
	                	return;

	         		// Start building HTML string that will be displayed in gadget.
					var html = "<span class=\"hilite\"><a href=\"http://www.facebook.com/apps/application.php?id=9776468399\" target=\"_blank\">Facebook</a>, <a href=\"http://www.bebo.com/Profile.jsp?MemberId=6177904074\" target=\"_blank\">Bebo</a> and <a href=\"http://www.widgetbox.com/widget/free-itunes\" target=\"_blank\">other</a> versions of this gadget now available!</span>";

	         		// Access the data for a given entry
	         		if (feed.Entry) 
					{
	             		for (var i = 0; i < feed.Entry.length; i++) 
						{
							// alternate light/dark background for lines
							if (i % 2)
								html += "<span class=\"light\">";
							else
								html += "<span class=\"dark\">";

							html += "<a href=\"" + feed.Entry[i].Link + "\" target=\"_blank\" >" +  
								feed.Entry[i].Title + "</a></span>"; 

	             		}
	         		}
	
		     		_gel("News").innerHTML = html;

		     		// The rest of the function parameters, which are optional: the number
		     		// of entries to return, and whether to return summaries.
		    	}, 25, false
			);

			curtab = document.getElementById(lastTab);
			
			showTab(lastTab);		

		}
		
		_IG_RegisterOnloadHandler(display);
	</script>
	]]>
	</Content>
</Module>