var ieX = false;
var theBrowserVersion = navigator.appVersion.toLowerCase();
if(theBrowserVersion.indexOf('msie') != -1) {
	ieX = true;
}

function A4WincludeFile(filePath) {
	if(!filePath) {return;}
	var checkPath = ''+filePath;
	if(checkPath.indexOf('?') != -1) {
		checkPath = checkPath.split('?')[0];
	}
	var ext = checkPath.substring(checkPath.lastIndexOf('.')+1);
	switch (ext) {
		case 'php':
			var inc = document.createElement('script');
			inc.setAttribute('type','text/javascript');
			inc.setAttribute('charset','utf-8');
			inc.setAttribute('src',filePath);
			break;
		case 'js':
			var inc = document.createElement('script');
			inc.setAttribute('type','text/javascript');
			inc.setAttribute('charset','utf-8');
			inc.setAttribute('src',filePath);
			break;
		case 'css':
			var inc = document.createElement('link');
			inc.setAttribute('type','text/css');
			inc.setAttribute('rel','stylesheet');
			inc.setAttribute('media','screen');
			inc.setAttribute('href',filePath);
			break;
		default:
			return;
	}
	if(ieX) {
		document.documentElement.appendChild(inc);		
	} else {
		document.getElementsByTagName('head').item(0).appendChild(inc);		
	}
};

function A4Wtimestamp() {
	var timeStamp = new Date();
	timeStamp = timeStamp.getTime();
	return timeStamp;
};

var timeoutLoad;

var _ctw = false;
var productID = _actor4web;
function A4WshowActor() {
	if(productID && (productID != undefined)) {
		var pagePath = window.location.href;
		pagePath = pagePath.split('://')[1];
		var domainName = pagePath.split('/')[0];
		if(pagePath.indexOf('?page=') != -1) {
			pagePath = pagePath.split('?page=');
			pagePath = pagePath[pagePath.length-1];
			_ctw = true;
		} else {
			if(pagePath.indexOf('?') != -1) {
				pagePath = pagePath.split('?')[0];
			}
			pagePath = pagePath.split(domainName+'/')[1];
		}
		if(!pagePath) {pagePath = 'index.html';}
		if(timeoutLoad) {clearTimeout(timeoutLoad);}
		var timeoutFunc = function() {actorInitDisplay(productID,pagePath,domainName);};
		timeoutLoad = setTimeout(timeoutFunc,1000);
	}
};
A4WshowActor();

function actorInitDisplay(prodID,webPage,domainName) {
	var filePath = 'http://actor4web.com/actor4web.php';
	filePath += '?id='+encodeURIComponent(prodID);
	filePath += '&page='+encodeURIComponent(webPage);
	filePath += '&domain='+encodeURIComponent(domainName);
	if(_ctw) {filePath += '&ctw='+encodeURIComponent('ctw');}
	A4WincludeFile(filePath);
};


function A4WactorPlayagainButton() {
	var tempItem = document.createElement('span');
	tempItem.innerHTML = playagainButtonHtmlCode;
	tempItem = document.body.appendChild(tempItem);
	tempItem.firstChild.onclick = A4WactorReplay;
};

function A4WactorClose() {
	var currentActor = document.getElementById("actorXweb");
	currentActor.style.display = 'none';
	A4Wstopmovie(true);
	A4WactorPlayagainButton();
};
function A4WactorEnd() {
	var currentActor = document.getElementById("actorXweb");
	currentActor.style.display = 'none';
	A4Wstopmovie(false);
	A4WactorPlayagainButton();
};
function A4WactorReplay() {
	this.parentNode.removeChild(this);
	A4WactorPlay();
};

function A4WmovieRedirect(aLink,aTarget) {
	if(productID && (productID != undefined)) {
		var pagePath = window.location.href;
		pagePath = pagePath.split('://')[1];
		var domainName = pagePath.split('/')[0];
		if(pagePath.indexOf('?page=') != -1) {
			pagePath = pagePath.split('?page=');
			pagePath = pagePath[pagePath.length-1];
			_ctw = true;
		} else {
			if(pagePath.indexOf('?') != -1) {
				pagePath = pagePath.split('?')[0];
			}
			pagePath = pagePath.split(domainName+'/')[1];
		}
		if(!pagePath) {pagePath = 'index.html';}
		
		var filePath = 'http://actor4web.com/actor4web.php';
		filePath += '?id='+encodeURIComponent(productID);
		filePath += '&page='+encodeURIComponent(pagePath);
		filePath += '&domain='+encodeURIComponent(domainName);
		filePath += '&click='+encodeURIComponent('click');
		filePath += '&actorlink='+encodeURIComponent(aLink);
		filePath += '&linktarget='+encodeURIComponent(aTarget);
		if(_ctw) {filePath += '&ctw='+encodeURIComponent('ctw');}
		filePath += '&time='+encodeURIComponent(A4Wtimestamp());
		A4WincludeFile(filePath);
	}
};

function A4WstatTextAction(isShow,aLang) {
	if(productID && (productID != undefined)) {
		var pagePath = window.location.href;
		pagePath = pagePath.split('://')[1];
		var domainName = pagePath.split('/')[0];
		if(pagePath.indexOf('?page=') != -1) {
			pagePath = pagePath.split('?page=');
			pagePath = pagePath[pagePath.length-1];
			_ctw = true;
		} else {
			if(pagePath.indexOf('?') != -1) {
				pagePath = pagePath.split('?')[0];
			}
			pagePath = pagePath.split(domainName+'/')[1];
		}
		if(!pagePath) {pagePath = 'index.html';}
		
		var filePath = 'http://actor4web.com/manager/data/statsdb.php';
		filePath += '?stat='+encodeURIComponent('texts');
		filePath += '&id='+encodeURIComponent(productID);
		filePath += '&page='+encodeURIComponent(pagePath);
		filePath += '&domain='+encodeURIComponent(domainName);
		filePath += '&isshown='+encodeURIComponent(isShow);
		filePath += '&userlang='+encodeURIComponent(aLang);
		filePath += '&time='+encodeURIComponent(A4Wtimestamp());
		A4WincludeFile(filePath);
	}
};

var A4WplayerLastStatus = '';
var A4WplayerLastTime = 0;
function A4WstatSequenceAction(aStatus,curTime) {
/*alert(A4WplayerLastStatus+' : '+aStatus)*/
	var ellapsedTime = A4WplayerLastTime-0;
	A4WplayerLastTime = curTime-0;
	curTime = A4WplayerLastTime-ellapsedTime;
	curTime = Math.abs(curTime);
	curTime = curTime.toFixed(2);
	if(A4WplayerLastStatus == aStatus) {return;}
	A4WplayerLastStatus = aStatus;
	if(aStatus == 'ended') {A4WplayerLastTime = 0;}
	if(productID && (productID != undefined)) {
		var pagePath = window.location.href;
		pagePath = pagePath.split('://')[1];
		var domainName = pagePath.split('/')[0];
		if(pagePath.indexOf('?page=') != -1) {
			pagePath = pagePath.split('?page=');
			pagePath = pagePath[pagePath.length-1];
			_ctw = true;
		} else {
			if(pagePath.indexOf('?') != -1) {
				pagePath = pagePath.split('?')[0];
			}
			pagePath = pagePath.split(domainName+'/')[1];
		}
		if(!pagePath) {pagePath = 'index.html';}
		
		var filePath = 'http://actor4web.com/manager/data/statsdb.php';
		filePath += '?stat='+encodeURIComponent('seqs');
		filePath += '&id='+encodeURIComponent(productID);
		filePath += '&page='+encodeURIComponent(pagePath);
		filePath += '&domain='+encodeURIComponent(domainName);
		filePath += '&seqstatus='+encodeURIComponent(aStatus);
		filePath += '&seqtime='+encodeURIComponent(curTime);
		filePath += '&time='+encodeURIComponent(A4Wtimestamp());
		A4WincludeFile(filePath);
	}
};

function A4WstatShareAction(anAction) {
	if(productID && (productID != undefined)) {
		var pagePath = window.location.href;
		pagePath = pagePath.split('://')[1];
		var domainName = pagePath.split('/')[0];
		if(pagePath.indexOf('?page=') != -1) {
			pagePath = pagePath.split('?page=');
			pagePath = pagePath[pagePath.length-1];
			_ctw = true;
		} else {
			if(pagePath.indexOf('?') != -1) {
				pagePath = pagePath.split('?')[0];
			}
			pagePath = pagePath.split(domainName+'/')[1];
		}
		if(!pagePath) {pagePath = 'index.html';}
		
		var filePath = 'http://actor4web.com/manager/data/statsdb.php';
		filePath += '?stat='+encodeURIComponent('shares');
		filePath += '&id='+encodeURIComponent(productID);
		filePath += '&page='+encodeURIComponent(pagePath);
		filePath += '&domain='+encodeURIComponent(domainName);
		filePath += '&shareaction='+encodeURIComponent(anAction);
		filePath += '&time='+encodeURIComponent(A4Wtimestamp());
		A4WincludeFile(filePath);
	}
};

