var TRG_NUM = "HowToBrush";
var TRG_HEAD = "How to Brush";
var addthis_share = {
	url: ''
}

function defVid() {
	endCheckCount();
	var urlparams = location.search.substring(1);
	if(urlparams.length > 0) {
		var urlvalues = urlparams.split(",");
		PlayVideo(decodeURIComponent(urlvalues[0]), decodeURIComponent(urlvalues[1]));
	} else {
		PlayVideo(TRG_NUM,TRG_HEAD.replace("-", /\s/g));
	}
}

function targetVid(num,head) {
	TRG_NUM = num;
	TRG_HEAD = head;
	if (addthis_share.url !== '') {
		addthis_share.url = location.protocol + location.host + location.pathname + "?" + TRG_NUM + "," + TRG_HEAD;
		addthis_share.title = "Colgate Video Library: " + TRG_HEAD;
		addthis.button('.addthis_button');
	}
	PlayVideo(num,head);
}

function getHeadline() {
	return encodeURIComponent(TRG_NUM + "," + TRG_HEAD);
}

function PlayVideo(targetVid, VideoTitle) {
	var targetSO = document.getElementById('FlashInsert');
	var targetVid = 'targetSO.swf_PlayVideo' + targetVid + '();';
	if (document.getElementById("addthis")) {
		document.getElementById("addthis").name.value = location.href + "?" + encodeURIComponent(targetVid) + "," + encodeURIComponent(VideoTitle);
	}
	if (targetVid != '') {
		LoadVideo();
		var titleLoc = document.getElementById('Video_Title');
		var dashReplace = /\-/g;
		var VideoTitle = VideoTitle.replace(dashReplace, " ");
		var titleLength = VideoTitle.length;
		var sitePointPosition = VideoTitle.indexOf("=");
		if (sitePointPosition >= 1) {
			var sitePointStrip = VideoTitle.substring(0,sitePointPosition);
			titleLoc.innerHTML = sitePointStrip ;
		} else {
			titleLoc.innerHTML = VideoTitle;
		}
	}
	function LoadVideo() {
		eval(targetVid);
	}
}

var t;
function checkLoadCount() {
	t = setTimeout("defVid()", 3000);
}

function endCheckCount() {
	clearTimeout(t);
}

window.onload = checkLoadCount;
