var gotclip_aff = 10350;
(function(win, fn) {
	var done = false, top = true, doc = win.document, root = doc.documentElement,
	add = doc.addEventListener ? 'addEventListener' : 'attachEvent',
	rem = doc.addEventListener ? 'removeEventListener' : 'detachEvent',
	pre = doc.addEventListener ? '' : 'on',
	init = function(e) {
		if (e.type == 'readystatechange' && doc.readyState != 'complete') return;
		(e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
		if (!done && (done = true)) fn.call(win, e.type || e);
	},
	poll = function() {
		try { root.doScroll('left'); } catch(e) { setTimeout(poll, 50); return; }
		init('poll');
	};
	if (doc.readyState == 'complete') fn.call(win, 'lazy');
	else {
		if (doc.createEventObject && root.doScroll) {
			try { top = !win.frameElement; } catch(e) { }
			if (top) poll();
		}
		doc[add](pre + 'DOMContentLoaded', init, false);
		doc[add](pre + 'readystatechange', init, false);
		win[add](pre + 'load', init, false);
	}
})(window, function(){
	var objs = document.getElementsByTagName('object');
	for(var i in objs)
	{
		var obj = objs[i];
		if(obj.getAttribute && obj.getAttribute('gotclip')=='true') break;
		for(var x in obj.childNodes)
		{
			if(obj.childNodes[x].tagName && obj.childNodes[x].tagName.toUpperCase()=='PARAM')
			{
				var val = obj.childNodes[x].getAttribute('value');
				if(val.substr(0,22)=='http://www.youtube.com')
				{
					var video_id = val.match(/v\/([^&\/]+)/)[1];
					var div = document.createElement('DIV');
					div.innerHTML = "<div class=\"gotclip\"><div><span>Download this video with</span> <a href=\"http://gotclip.com/download/"
						+gotclip_aff+"/GotClip_YT-"+video_id+"\" title=\"GotClip allows you to download YouTube videos with one click. Get it now!\">GotClip Downloader</a></div></div>";
					div.style.width = obj.getAttribute("width") + "px";
				}
				obj.parentNode.insertBefore(div, obj.nextSibling);
				obj.setAttribute('gotclip','true');
			}
		}
	}
})

