(function(){
	//console.log(navigator.userAgent.toLowerCase());
	/*isIE = (navigator.userAgent.toLowerCase().indexOf("trident")!=-1)?true:false;
	isEdge = (navigator.userAgent.toLowerCase().indexOf("edge")!=-1)?true:false;
	isChrome = (navigator.userAgent.toLowerCase().indexOf("edge")!=-1)?true:false;*/
	
	volInterval = setInterval(checkVideoAudio, 100);
	eventIsAdded = false;
		
	function checkVideoAudio(){
		vid = document.querySelector("video");
		aud = document.querySelector("audio");
		csVolume = document.querySelector("input.cs-volume");
		
		if (volInterval>=0 && csVolume && !eventIsAdded){
			console.log("Mousedown event is added!");
			_setEvt_(csVolume, "mousedown");
			eventIsAdded = true;
		}
	}

	function _setEvt_(el, evtType) {
		if (evtType=="mousedown") { 
			el.addEventListener("mousemove", _wraf_);
			el.addEventListener("mouseup", _wraf_);
		}else if (evtType=="mouseup") {
			el.removeEventListener("mousemove", _wraf_);
			el.removeEventListener("mouseup", _wraf_);			
		}
		
		function _wraf_() {
			window.requestAnimationFrame(function () {
				if (vid!=null){
					vid.volume = el.value;
				}else if (aud!=null){
					aud.volume = el.volume;
				}
				//console.log(el.value);
				el.setAttribute("aria-valuenow", el.value); // include for accessibility
			});
		}	
	}
	
})();