var imgWidth = 160;
var imgHeight = 60;

function init() {
	var vSpan = document.createElement("span");
	vSpan.setAttribute("id", "topButton");
	vSpan.style.position = "absolute";
	vSpan.style.visibility="hidden";
	vSpan.style.left = "0px";
	vSpan.style.top = "0px";
	
	var aLink = document.createElement("a");
	aLink.setAttribute("id", "chatlink");
	a.href ="http://server.iad.liveperson.net/hc/79160457/?cmd=file&file=visitorWantsToChat&site=79160457&byhref=1";
	aLink.setAttribute("target", "chat79160457");
	aLink.onmouseover = displayLiveChat;
	aLink.onmouseout = removeDisplayLiveChat;
	aLink.onclick = popupChat;

	var mImg = document.createElement("img");
	mImg.src = 'http://server.iad.liveperson.net/hc/79160457/?cmd=repstate&site=79160457&&ver=1&category=en;woman;6' 
	mImg.name='hcIcon' 
	mImg.width=imgWidth 
	mImg.height=imgHeight 
	mImg.border=0;

	document.body.appendChild(vSpan);
	vSpan.appendChild(aLink);
	aLink.appendChild(mImg);

	initButton();
} 

function initButton() {
	if (document.all) { //IE
		document.all['topButton'].style.pixelLeft = document.body.clientWidth - document.all['topButton'].offsetWidth;
		document.all['topButton'].style.visibility = 'visible';
	}
	else if (document.layers) {
		document.topButton.left = window.innerWidth - document.topButton.clip.width - 170;
		document.topButton.visibility = 'show';
	}
	else if (document.getElementById) { //Firefox
		document.getElementById('topButton').style.left = window.innerWidth - imgWidth - 16;
		document.getElementById('topButton').style.visibility = 'visible';
	}
	
	if (document.all) {
		window.onscroll = floatButton;
	} else {
		setInterval ('floatButton()', 100);
	}
}

//General functions
function floatButton() {
	if (document.all) {
		document.all['topButton'].style.pixelTop = document.body.scrollTop;
	}
	else if (document.layers) {
		document.topButton.top = window.pageYOffset;
	}
	else if (document.getElementById) {
		document.getElementById('topButton').style.top = window.pageYOffset + 'px';
	}
}

function displayLiveChat() {
	window.status = 'Live chat now!';
	return true;
}

function removeDisplayLiveChat() {
	window.status = '';
	return true;
}

function popupChat () {
	testwin = window.open('http://server.iad.liveperson.net/hc/79160457/?cmd=file&file=visitorWantsToChat&site=79160457&referrer='+escape(document.location),'chat79160457','width=472,height=320,menubar=no,scrollbars=0');
	return false;
}

window.onload = init;