var Youtube = Class.create({
	url: null,
	object: null,
	embed: null,
	width: 0,
	height: 0,
	initialize: function(url)
	{
		this.url = url;		
	},
	play: function()
	{
		//embed.setAttribute('src', yt_src + '&autoplay=1');
	},
	stop: function()
	{

	},
	hide: function()
	{
		this.thumbnail.show();
		if( Prototype.Browser.IE )
		{
			this.embed.remove();
		}
		else
		{
			this.object.remove();
		}
	},
	show: function()
	{
		// TODO: generate the complete dom for both object and embed
		var parms = new Hash();
		parms.set('allowfullscreen', 'true');
		parms.set('allowscriptaccess', 'always');
		parms.set('height', this.height);
		parms.set('width', this.width);

		var embed = new Element('embed');
		embed.setAttribute('src', this.url);
		embed.setAttribute('type', 'application/x-shockwave-flash');

		var object = new Element('object');
		object.insert( new Element('param', {name: 'movie', value: this.url}) );
		
		parms.each(function(hash)
		{
			object.insert( new Element('param', {name: hash.key, value: hash.value}) );
			embed.setAttribute(hash.key, hash.value);
		});

		this.object = object;
		this.embed = embed;

		if( Prototype.Browser.IE )
		{
			this.thumbnail.insert({after: embed});
		}
		else
		{
			object.insert(embed);
			this.thumbnail.insert({after: object});
		}
		
		this.thumbnail.hide();

	},
	get_thumb: function()
	{
		var yt_id = this.url.replace(/http:\/\/www.youtube.com\/v\//, '').replace(/&hl=.{2}&fs=[0-9].*/, '');
		var yt_img = 'http://i4.ytimg.com/vi/' + yt_id + '/default.jpg';

		// put an image in the note
		var imgdiv = new Element('div');
		imgdiv.setStyle({cursor: 'pointer', width: '128px', height: '82px', background: "url('"+yt_img+"')"});
		imgdiv.className = 'yt-img';
		var img = new Element('img', {src: '/images/play.png'});
		img.setStyle({marginTop: '30px', marginLeft: '55px'});
		imgdiv.observe('click', function(){
			this.thumb_clicked();					
		}.bind(this));
		imgdiv.insert(img);
		this.thumbnail = imgdiv;
		return imgdiv;
	},
	thumb_clicked: function()
	{

	}
});
