﻿/************
*	This class to control the action of VJocx
*	author: Koala
*/
function VJocx_Ctrl(objName, ocxName, posCtrl, volCtrl) {
	this.objectName = objName;
	this.ocxName = ocxName;
	this.posCtrl = posCtrl;
	this.volCtrl = volCtrl;
	this.bSlidePos = false;
	this.nSlideTime = 0;
	//this.nPlayState = 0;
	var _this = this;
	var Check = function() {
		_this.CheckState();
	};
	this.vrTimer = setInterval(Check, 1000);

	this.CheckState = function() {
			var pos = document.getElementById(this.posCtrl);
		if (this.posCtrl.getValue() != document.getElementById(this.ocxName).Position && !this.bSlidePos) {
			if (this.posCtrl._disabled == true && document.getElementById(this.ocxName).Position > 0)
				   this.posCtrl._disabled=false;
			this.posCtrl.setValue(document.getElementById(this.ocxName).Position);
			}
		if (this.bSlidePos) {
				this.nSlideTime++;
				if (this.nSlideTime > 3)
					this.bSlidePos = false;
			} else 
				this.nSlideTime = 0;
		if (this.volCtrl.getValue() != document.getElementById(this.ocxName).Volume){
				this.volCtrl.setValue(document.getElementById(this.ocxName).Volume);
			}
		if (this.fnCheckTimer != "undefined") {
			this.fnCheckTimer();
		}

	};
//	this.attachOnStateChange = function(fnName){
//		this.fnStateChange = fnName;
//	};
	this.attachOnCheckTimer = function(fnName) {
		this.fnCheckTimer = fnName;
	}
}

function VolumeChange(sliderObj, changetype, val, newPos){
			if (changetype != "setvalue"){
						document.getElementById(sliderObj.ocxCtrl.ocxName).Volume = sliderObj.getValue();
					}
		}
function CtrlChange(sliderObj, changetype, val, newPos){ 
				if (changetype != "setvalue") {
					document.getElementById(sliderObj.ocxCtrl.ocxName).Position=sliderObj.getValue();
		 sliderObj.ocxCtrl.bSlidePos = true;
				}
	}
function CtrlPlay(obj)
		{
			document.getElementById(obj.ocxName).Play();
		}
function CtrlStop(obj)
		{
			document.getElementById(obj.ocxName).Stop();
		}
function CtrlMute(obj)
		{
			document.getElementById(obj.ocxName).Mute = !document.getElementById(obj.ocxName).Mute;
		}
function CtrlPause(obj)
		{
			document.getElementById(obj.ocxName).Pause();
		}