targetQuicktimeplayer = Class.create();
Object.extend(targetQuicktimeplayer.prototype, Event.Publisher);
Object.extend(targetQuicktimeplayer.prototype, {
	options: {
		targetClass: 'target-quicktimeplayer' // Class on anchor tags that this script sets events on
	},
		
	initialize: function() {
		// Get all links with handle class
		this.as = $$('.'+this.options.targetClass);
		
		// Get QuickTime Version
		qtv = AC.Detector.getQTVersion();
		qtv = qtv.split('.')[0];
		qtv = parseInt(qtv);
		
		// If QuickTime is installed and new enough for launcher, add the events
		if(AC.Detector.isQTInstalled() && qtv >= 4) this.addEvents();
	},
	
	addEvents: function(){
		this.as.each(function(a){
			if(a.readAttribute('href') && a.readAttribute('href') != '#') a.observe('click',this.onClick.bind(this));
		}.bind(this));
	},
	
	onClick: function(evt){
		evt.stop();

		this.dispatchEvent('lanchedQTPlayer', this);

		if(this.embed) this.embed.remove();
		
		el = evt.target;
		href = el.readAttribute('href');

		this.embed = new Element('embed', {
			'src': href,
			'href': href,
			'target': 'quicktimeplayer',
			'width': 1,
			'height': 1,
			'autohref': true,
			'autoplay': false
		});
		
		this.embed.setAttribute('autoplay','false')
		
		document.body.appendChild(this.embed);
		//this.embed.remove();
	}
});

