var iVideoTimer;
var iVideoHeight = 346;
var iVideoInterval = 35;

loadStylesheet = function (sUrl, sId) {
	if (!(document.getElementById(sId))) {
		if (document.createStylesheet) {
			document.createStylesheet(sUrl);
			return;
		}
		if (document.createElement && document.getElementsByTagName) {
			var head = document.getElementsByTagName("head")[0];
			var oCSS = document.createElement("link");
			oCSS.id = sId;
			oCSS.rel = "stylesheet";
			oCSS.href = sUrl;
			oCSS.type = "text/css";
			head.appendChild(oCSS);
		}
	}
}

loadAdSkin = function() {
	loadStylesheet("/resources/css/video-skinmode.css","videoAdSkin");
}

function advanceAdSkin() {
	var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
	if (InternetExplorer) {
		mc = window.videosync;
	} else {
		mc = window.document.videosync;
	}
	if(mc != null) {
		mc.GotoFrame(2);
	} 
}

function reverseAdSkin() {
	var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
	if (InternetExplorer) {
		mc = window.videosync;
	} else {
		mc = window.document.videosync;
	}
	if(mc != null) {
		mc.GotoFrame(3);
	} 
}

function rollupAdSkin() {
	rollVideoUp = function() {
		iVideoInterval = 50;
		if (iVideoHeight < iVideoInterval) {
			iVideoInterval = iVideoHeight;
		}
		if (iVideoHeight > 0) {
			iVideoHeight -= iVideoInterval;
			document.getElementById("videoPlayer").style.cssText = "height: " + iVideoHeight + "px";
			document.getElementById("videoInfo").style.cssText = "height: " + iVideoHeight + "px";
		} else {
			clearInterval(iVideoTimer);
			document.getElementById("videoText").className = "hidden";
			advanceAdSkin();
		}
	}
	// advanceAdSkin();
	iVideoTimer = setInterval(rollVideoUp, 5);
}

function rolloutAdSkin() {	
	document.getElementById("videoText").className = "";
	rollVideoOut = function() {
		iVideoInterval = 50;
		if ((346 - iVideoHeight) < iVideoInterval) {
			iVideoInterval = 346 - iVideoHeight;
		}
		if (iVideoHeight < 346) {
			iVideoHeight += iVideoInterval;
			document.getElementById("videoPlayer").style.cssText = "height: " + iVideoHeight + "px";
			document.getElementById("videoInfo").style.cssText = "height: " + iVideoHeight + "px";
		} else {
			clearInterval(iVideoTimer);
			reverseAdSkin();
		}
	}
	iVideoTimer = setInterval(rollVideoOut, 5);
}

function launchAdSkin() {
	iVideoTimer = setTimeout(rollupAdSkin, 500);
}

function finishAdSkin() {
	iVideoTimer = setTimeout(rolloutAdSkin, 500);
}
