(function(window) {
	
	window.twitBadges = window['twitBadges'] ? window.twitBadges : { 'length': 0 };
	twitBadges['mouseplanet_HTML'] = "<div class=\"twtpic-widget-wrap\"><div class=\"twtpic-widget-header\"><div class=\"twtpic-widget-avatar\"><a href=\"http://twitpic.com/photos/MousePlanet\" target=\"_blank\"><img src=\"http://a0.twimg.com/profile_images/79404346/avatar13109_1_normal.png\" alt=\"MousePlanet\" /></a></div><div class=\"twtpic-widget-user-info\"><p>MousePlanet</p><p class=\"twtpic-widget-username\"><a class=\"twtpic-widget-link\" href=\"http://twitpic.com/photos/MousePlanet\" target=\"_blank\">MousePlanet</a></p></div><div style=\"clear:both;\"></div></div><div class=\"twtpic-widget-tweets\"><a href=\"http://twitpic.com/7msd25\" target=\"_blank\"><img src=\"http://twitpic.com/show/mini/7msd25\" alt=\"Nice to see that the Disney Archives has the full set of David Koenig books.\" /></a><a href=\"http://twitpic.com/7mruij\" target=\"_blank\"><img src=\"http://twitpic.com/show/mini/7mruij\" alt=\"Richard Sherman inspecting Walt&amp;#039;s piano, recently restored and returned to the archives.\" /></a><a href=\"http://twitpic.com/7mrthp\" target=\"_blank\"><img src=\"http://twitpic.com/show/mini/7mrthp\" alt=\"So many props and treasures at the Studios archive.\" /></a><a href=\"http://twitpic.com/7mrl44\" target=\"_blank\"><img src=\"http://twitpic.com/show/mini/7mrl44\" alt=\"Setting up for a group photo of more Disney talent than I can name in 140 characters.\" /></a><a href=\"http://twitpic.com/7mqrpm\" target=\"_blank\"><img src=\"http://twitpic.com/show/mini/7mqrpm\" alt=\"The &amp;quot;found&amp;quot; art that inspired the Dumbo article in the latest issue of the D23 magazine.\" /></a><a href=\"http://twitpic.com/7mqnd4\" target=\"_blank\"><img src=\"http://twitpic.com/show/mini/7mqnd4\" alt=\"Disney archivist Becky Cline shows the original script of Steamboat Willie during a blogger event at the Studios.\" /></a><a href=\"http://twitpic.com/7mqgbh\" target=\"_blank\"><img src=\"http://twitpic.com/show/mini/7mqgbh\" alt=\"The ultimate Disney Geek Christmas tree - Monorail around the base, Orange Bird as the tree topper.\" /></a><a href=\"http://twitpic.com/7ktrrc\" target=\"_blank\"><img src=\"http://twitpic.com/show/mini/7ktrrc\" alt=\"Trio of holiday desserts from DCA. Almond cookie ice cream sandwich, mango parfait, Boudin bread pudding.\" /></a><a href=\"http://twitpic.com/7ktgrn\" target=\"_blank\"><img src=\"http://twitpic.com/show/mini/7ktgrn\" alt=\"Receipts from some DLR restaurants have a 20% merchandise coupon at the bottom. This was a popular promotion last year\" /></a><a href=\"http://twitpic.com/7hzajl\" target=\"_blank\"><img src=\"http://twitpic.com/show/mini/7hzajl\" alt=\"The windmill for Filmore&amp;#039;s is being driven down Route 66 at DCA right now.\" /></a><a href=\"http://twitpic.com/7f2pon\" target=\"_blank\"><img src=\"http://twitpic.com/show/mini/7f2pon\" alt=\"For those asking, this is the DL AP-exclusive ornament set. $49.95.\" /></a><a href=\"http://twitpic.com/7e8ydx\" target=\"_blank\"><img src=\"http://twitpic.com/show/mini/7e8ydx\" alt=\"Taste testing the new waffle sandwiches at Sleepy Hollow in WDW. Verdict: yummy, but the waffles could be crispier.\" /></a></div><div style=\"clear:both;\"></div><div class=\"twtpic-widget-footer\"><div class=\"twtpic-widget-logo\"><a href=\"http://twitpic.com\" target=\"_blank\"><img src=\"http://twitpic.com/images/widget-logo.png\" alt=\"Twitpic\" /></a></div><div class=\"twtpic-widget-share\"><a class=\"twtpic-widget-link\" href=\"http://twitpic.com/upload\" target=\"_blank\">Share Your Photos</a></div><div style=\"clear:both;\"></div></div></div>";
	twitBadges['mouseplanet_CSS'] = "<style type=\"text/css\" name=\"twtpic-widget-css\"> .twtpic-uniq-4f23071a59a26 { width: 189px; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-link { color: #0000ff; text-decoration: none; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-link:hover { text-decoration: underline; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-wrap { width: 100%; border: 1px #5b86bd solid; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; background-color: #5b86bd; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-header { width: 100%; padding: 10px 8px 10px 8px; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-avatar { float: left; margin: 0 10px 0 0; padding: 0px; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-avatar img { width: 35px; border: none !important; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-user-info { float: left; margin-top: 2px; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-user-info p { margin: 0; font-family: arial, sans-serif; font-size: 12px; color: #0000ff; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-username { font-weight: bold; font-size: 18px !important; margin-top: -1px !important; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-tweets { background-color: #ffffff; padding: 5px 0 5px 0; text-align: center; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-tweets img { margin: 2px; display: inline; width: 75px; height: 75px; border: none; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-tweet:last-child { border: none !important; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-image { float: left; width: 75px; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-image img { border: none; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-text { width: 84px; float: right; padding: 0 5px 0 5px; font-family: arial, sans-serif; font-size: 12px; color: #333333; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-timestamp { margin-top: 5px; font-size: 11px; color: #333333; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-footer { padding: 10px 7px 10px 7px; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-logo { float: left; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-logo img { border: none; } .twtpic-uniq-4f23071a59a26 .twtpic-widget-share { float: right; font-family: arial, sans-serif; font-size: 14px; margin-top: 6px; } </style>";
	twitBadges['mouseplanet_ID'] = "twtpic-uniq-4f23071a59a26";
	
	var conflict = false;
	if(!("jQuery" in window)) {
		conflict = true;
		var head      = document.getElementsByTagName('head')[0],
		script        = document.createElement('script');
		script.type   = 'text/javascript';
		script.src    = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js';
		script.onload = init;
		script.onreadystatechange = function() {
			if(script.readyState == 'loaded' || script.readyState == 'complete') {
				init();
			}
		};
		head.appendChild(script);
	} else {
		init();
	}
	
	function init() {
		if(conflict) jQuery.noConflict();
		start(window, jQuery);
	}
	
	function start(window, $) {
		$(document).ready(function() {
			$('script[src]').each(function (i,src) {
				var $attr = $(src).attr('src'),
				    incs  = $attr.match(/\/j\/2\/widget.js\?.*username=([A-Za-z0-9_]*)(.*?)/);
				
				if ( incs && incs.length >= 2 && !twitBadges[incs[1].toLowerCase()] ) {
					var user = incs[1].toLowerCase();
					$(this).after('<div id="twtpic-wdgt-'+twitBadges['length']+'" class="' + twitBadges[user + '_ID'] + ' twtpic-widget"></div>');
					var wdgt = new TwitPic_Widget(user, twitBadges['length']);
					wdgt.inject_css();
					twitBadges[user] = wdgt;
					twitBadges['length']++;
					
					for(var name in twitBadges) {
						if(name == 'length') continue;
						if(name.match(/([A-Za-z0-9_]+)_(CSS|HTML|ID)/)) continue;
						
						twitBadges[name].build_widget();
					}
				}
			});
		});
	}
	
	function TwitPic_Widget(user, id) {
		this.id = id;
		this.user = user;
		this.built = false;
		this.div_id = '#twtpic-wdgt-' + id;
	}
		
	TwitPic_Widget.prototype.init = function() {
	    this.inject_css();
	}
	
	TwitPic_Widget.prototype.inject_css = function() {
	    jQuery('head').append(twitBadges[this.user + '_CSS']);
	}
	
	TwitPic_Widget.prototype.build_widget = function() {
	    if(this.built) return;
	    
	    this.built = true;
	    jQuery(this.div_id).html(twitBadges[this.user + '_HTML']);
	}

})(window);


