KATY.youtubeBadge = Class.create();
KATY.youtubeBadge.prototype = {
	initialize: function(element) {
        var d = new Date();
		this.element = $(element);
		this.url = 'youtube/api2_rest.aspx?time=' + d.getTime();
		this.params = '';
        
		/*
			Youtube will not except the extra parameter that prototype.js ads to Ajax Requests. (_=)
			I had to comment out that line in prototype. If you upgrade prototype and suddenly the
			youtube video's don't show up in safari, this is why.
		*/
		new Ajax.Request(
            
			this.url,
			{
				method:'get',
				parameters:'',
                generateUniqueUrl:true,
				onSuccess:this.displayThumbs.bind(this),
				onFailure:this.failure.bind(this),
                onException:this.failure.bind(this)
                
			}
		)
	},
	
	displayMovie: function(id,e) {
		//new Simpltry.Dialog.Ajax({url: "/lbv.php?id="+id, width: 427, height: 352});
		e = (e) ? e : window.event;
		Event.stop(e);
		return false;
	},
	
	displayThumbs: function(response) {
		var videos = response.responseXML.getElementsByTagName('video');
		$A(videos).each(function(video,c) {
			if(c<9) {
				var img = document.createElement('img');
				img.src = video.getElementsByTagName('thumbnail_url')[0].firstChild.nodeValue;
				//img.alt = video.getElementsByTagName('description')[0].firstChild.nodeValue;
				img.width = 45;
				img.height = 45;
			
				var a = document.createElement('a');
				a.className = 'youTubeThumb';
				a.href = video.getElementsByTagName('url')[0].firstChild.nodeValue;
				//a.href = '/lbv.php?id=' + video.getElementsByTagName('id')[0].firstChild.nodeValue;
				// a.rel  = '/lbv.php?id=' + video.getElementsByTagName('id')[0].firstChild.nodeValue;
				a.title = video.getElementsByTagName('title')[0].firstChild.nodeValue;
                a.target = "_blank";
				//a.className = 'lbOn';
				//a.onclick = this.displayMovie.bind(this,video.getElementsByTagName('id')[0].firstChild.nodeValue);
				a.appendChild(img);
			
				var surround = document.createElement('li');
				surround.appendChild(a);
			
				this.element.appendChild(surround);
			}
		}.bind(this));
		lbvInitialize();
	},
	
	failure: function(response) {
		if(window.console) {
			window.console.log(response.responseText);
		}
	}
}

Event.observe(window,'load', function() {
	new KATY.youtubeBadge('videos');
});
