(function() {
	var wrap = document.getElementById("html5_video_compare1_wrap"),
		ogg = document.getElementById("html5_video_compare1_ogg"),
		mp4 = document.getElementById("html5_video_compare1_mp4"),
		oggWrap = document.getElementById("html5_video_compare1_ogg_wrap"),
		mp4Wrap = document.getElementById("html5_video_compare1_mp4_wrap"),
		oggCaption = document.getElementById("html5_video_compare1_ogg_caption"),
		mp4Caption = document.getElementById("html5_video_compare1_mp4_caption"),
		offsetLeft = -35,
		speed = 1,
		currentOpac = 0,
		dir = 1,
		waiting = false,
		timer;
	
	wrap.style.cssText = "position:relative; left:"+offsetLeft+"px; display:block; width:853px; height:478px; margin:10px auto; border:5px solid #444;";
	ogg.style.cssText = "border:none; margin:0; padding:0;";
	mp4.style.cssText = "border:none; margin:0; padding:0;";
	
	oggWrap.style.cssText = "position:absolute; left:0; top:0; display:block; width:853px; height:478px;";
	mp4Wrap.style.cssText = "position:absolute; left:0; top:0; display:block; width:853px; height:478px; opacity:0; filter:alpha(opacity=0);";
	
	oggCaption.style.cssText = "position:absolute; left:25%; top:10px; display:inline; padding:5px 10px; background:#000; color:#FFF; font-size:130%; border-radius:10px; -moz-border-radius:10px; -webkit-border-radius:10px; opacity:0.5; filter:alpha(opacity=50);";
	mp4Caption.style.cssText = "position:absolute; right:25%; top:10px; display:inline; padding:5px 10px; background:#000; color:#FFF; font-size:130%; border-radius:10px; -moz-border-radius:10px; -webkit-border-radius:10px; opacity:0.5; filter:alpha(opacity=50);";
	
	if (document.all && document.body.filters && !window.opera) {
		function opac(el, op) {
			el.filters.alpha.opacity = op + "";
		}
	}
	else {
		function opac(el, op) {
			el.style.opacity = op/100;
		}
	}
	
	function fade() {
		currentOpac += dir * speed;
		opac(mp4Wrap, currentOpac);
		
		if (currentOpac>=100 || currentOpac<=0) {
			dir *= -1;
			waiting = true;
			timer = window.setTimeout(fade, 1500);
		}
		else {
			waiting = false;
			timer = window.setTimeout(fade, 10);
		}
	}
	
	fade();
	
	
	wrap.onclick = function() {
		if (waiting===true) {
			window.clearTimeout(timer);
			fade();
		}
	};
})();

