/* Funk Bubble javascript code - Copyright 2004 Rent-A-Monkey.com */
/* You may adapt elements of this code in your own projects, but the unique combination of code contained here is copyright 2004 Rent-A-Monkey.com and may not be reproduced. */

var dom = document.getElementById ? true:false;
var timer = setTimeout("",500);
var scrolling = false;

function updateThenShow(element,newText) {
	if(dom) {
		document.getElementById(element).childNodes[0].nodeValue = "\u2022 " + newText + " \u2022";
		document.getElementById(element).style.display = 'block';
		document.getElementById(element).style.visibility = 'visible';
	}
}

function hide(element) {
	if(dom) {
		document.getElementById(element).style.visibility = 'hidden';
		document.getElementById(element).style.display = 'none';
	}
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function setupPage() {
	if(dom) {
		var windowHeight = getWindowHeight();
		var wholePageElement = document.getElementById('www-funkbubble-co-uk');
		wholePageElement.style.overflow = 'hidden';
		wholePageElement.style.height = windowHeight + 'px';
		wholePageElement.style.backgroundPosition = 'top center';

		var bodyElement = document.getElementById('bodytextouterbox');
		bodyElement.style.position = 'absolute';
		bodyElement.style.left = '0px';
		bodyElement.style.top = '0px';
		bodyElement.style.overflow = 'hidden';

		if (windowHeight > 0) {
			var footerElement = document.getElementById('footer');
			footerElement.style.position = 'absolute';
			footerElement.style.zIndex = '12';

			var clippingBox = document.getElementById('bodyclip');
			clippingBox.style.position = 'absolute';  // Causes fun in Opera
			clippingBox.style.overflow = 'hidden';
			clippingBox.style.top = '130px';
			clippingBox.style.left = '0';
			clippingBox.style.visibility = 'visible';
			clippingBox.style.zIndex = '3';
			
			var clippingBoxHeight = windowHeight - 220;
			
			if (clippingBoxHeight > 0) {
				clippingBox.style.height = clippingBoxHeight + 'px';
			} else {
				clippingBox.style.height = '0px';
			}
			clippingBox.style.width = '100%';
			clippingBox.style.clip = 'rect(0px,10000px,' + (windowHeight - 220) + 'px' + ',0px)';
			
			var bubbleBox = document.getElementById('bubblecontainer');

			bubbleBoxHeight = windowHeight - 125;
			if (bubbleBoxHeight > 0) {
				bubbleBox.style.height = bubbleBoxHeight + 'px';
			} else {
				bubbleBox.style.height = '0px';
			}

			if (document.getElementById('productimagecontainer')) {
				var productBox = document.getElementById('productimagecontainer');

				productBoxHeight = windowHeight - 180;
				if (productBoxHeight > 0) {
					productBox.style.height = productBoxHeight + 'px';
				} else {
					productBox.style.height = '0px';
				}
			}
			var scroller = document.getElementById('scrollwidget');
			scroller.style.display = 'block';
			if (document.getElementById('productimagecontainer')) {
				var scrollerRightPos = -240 + parseInt(document.getElementById('productimagecontainer').offsetLeft);
			} else {
				var scrollerRightPos = -30 + parseInt(document.getElementById('bubblepositioner').offsetLeft);
			}
			if (scrollerRightPos > 10) {
				scroller.style.right = scrollerRightPos + 'px';
			} else {
				scroller.style.right = '10px';
			}
			if (clippingBoxHeight > 70) {
				scroller.style.height = clippingBoxHeight + 'px';
				var scrollBubbleHeight = (clippingBoxHeight - 33) / 2;
			} else {
				scroller.style.height = '70px';
				var scrollBubbleHeight = 24;
			}
			document.getElementById('scrolltop').style.height = scrollBubbleHeight + 'px';
			document.getElementById('scrollbottom').style.height = scrollBubbleHeight + 'px';
		}
	}
}

function scrollUp(amount) {
	if(dom) {
		var bodyElement = document.getElementById('bodytextouterbox');
		
		var bodyclipHeight = bodyElement.offsetHeight - document.getElementById('bodyclip').offsetHeight;
		
		if (bodyclipHeight > 0) {
			var scrollMaximum = eval("-" + bodyclipHeight);
		} else {
			var scrollMaximum = 0;
		}
		if (parseInt(bodyElement.style.top) >= scrollMaximum) {
			var moveAmount = parseInt(bodyElement.style.top) - amount;
			if (moveAmount >= scrollMaximum) {
				bodyElement.style.top = (parseInt(bodyElement.style.top) - amount) + 'px';
			} else {
				bodyElement.style.top = scrollMaximum + 'px';
				scrolling = false;
			}
		}
		if (scrolling) {
			var newAmount = amount;
			if (newAmount < 30) {
				newAmount = newAmount + 1; // Accelleration
			}
			timer = setTimeout('scrollUp('+newAmount+')',50);
		}
	}
}

function scrollDown(amount) {
	if(dom) {
		var bodyElement = document.getElementById('bodytextouterbox');
		if (parseInt(bodyElement.style.top) < 0) {
			var moveAmount = parseInt(bodyElement.style.top) + amount;
			if (moveAmount <= 0) {
				bodyElement.style.top = (parseInt(bodyElement.style.top) + amount) + 'px';
			} else {
				bodyElement.style.top = '0px';
				scrolling = false;
			}
		}
		if (scrolling) {
			var newAmount = amount;
			if (newAmount < 30) {
				newAmount = newAmount + 1; // Accelleration
			}
			timer = setTimeout('scrollDown('+newAmount+')',50);
		}
	}
}

function stopScroll() {
	scrolling = false;
	clearTimeout(timer);
}

function postLoadLayout() {
	// Fix layout after load for badly behaved browsers
	if(dom) {
		var v = document.body.offsetHeight;
	}
}

window.onload = function() {
	setupPage();
}
window.onresize = function() {
	setupPage();
}
window.onmouseup = function() {
	scrolling = false;
	stopScroll();
}
