var crumbCount = 3;
var crumbPrefix = 'hp_crumb_';
var linkPrefix = 'hp_crumb_link_';

function dropCrumb( crumb ) {
	for (var i=2; i<=crumbCount; i++) {
		if ( getCookie( linkPrefix + i ) == document.URL ) {
			return;
		}
	}
	for (var j=1; j<=crumbCount; j++) {
		makeCookie( crumbPrefix+j, (j<crumbCount) ? getCookie( crumbPrefix+(j+1) ) : crumb, 7 );
		makeCookie( linkPrefix+j, (j<crumbCount) ? getCookie( linkPrefix+(j+1) ) : document.URL, 7 );
	}
}

function showCrumbs(message) {
	var noCrumbs = true;
	for (var j=1; j<=crumbCount; j++) {
		var check = getCookie( crumbPrefix + j );
		var link = getCookie( linkPrefix + j );
		if (check != null && check != 'null' && link != document.URL) {
			noCrumbs = false;
		}
	}
	if (noCrumbs) return;

	document.write( "<ul class='breadcrumbs'>\n<li>"+message+"</li>" );
	var maxCrumbLength = 15;
	for (var i=1; i<=crumbCount; i++) {
		var crumb = getCookie( crumbPrefix + i );
		var link = getCookie( linkPrefix + i );
		if (crumb == null || crumb == 'null' || link == null || link == 'null' || link == document.URL) continue;

		var unique = true;
		for (var j=1; j<=crumbCount; j++) {
			if (j==i) continue;
			if (crumb == getCookie( crumbPrefix + j )) {
				unique = false;
			}
		}

		if ( unique ) {
			if (crumb.length > maxCrumbLength) crumb = crumb.substr(0, maxCrumbLength) + '...';
			document.write( '<li class="crumb"><a href="' + link + '">' + crumb + '</a></li>' );
		}
	}
	document.write( "</ul>\n" );
}

function crumble(crumb, message) {
	showCrumbs(message);
	dropCrumb(crumb);
}

function makeCookie( name,value,days ) {
	if ( days ) {
		var date = new Date();
		date.setTime( date.getTime() + (days * 86400000) );
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function getCookie( cookieName ) {
	var name = cookieName + "=";
	var a = document.cookie.split(';');
	for ( var i=0; i < a.length; i++) {
		var c = a[i];
		while ( c.charAt(0) == ' ' ) c = c.substring(1, c.length);
		if ( c.indexOf(name) == 0) return c.substring( name.length, c.length);
	}
	return null;
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

function sendToGallery(value) {
	thisMovie("gallery").sendToGallery(value);
	return false;
}

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

/* Outdated fscommand
// Handle all the FSCommand messages in a Flash movie.
function video_DoFSCommand(command, args) {
	var videoObj = isInternetExplorer ? document.all.video : document.video;

	if (command == "updateHeight") {
		//document.controller.target.value = args;
		if ( isInternetExplorer ) {
			videoObj.parentNode.style.height = args + "px";
		} else {
			videoObj.parentNode.parentNode.style.height = args + "px";
		}
		resizeContentMenus();
		//document.controller.actual.value = videoObj.parentNode.parentNode.style.height;
	}
}

// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub video_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call video_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}

*/

function updateVidHeight(args) {
	var videoObj = isInternetExplorer ? document.all.video : document.video;
	if ( isInternetExplorer ) {
		videoObj.parentNode.style.height = args + "px";
	} else {
		videoObj.parentNode.parentNode.style.height = args + "px";
	}
	resizeContentMenus();
}

function getChildrenCount(e) {
	if (! e.childNodes) return null;
	var count = 0;
	for (var i=0; i<e.childNodes.length; i++) {
		var child = e.childNodes[i];
		if (child.nodeType == 1)
			count++;
	}
	return count;
}

function setNestedULWidths(e, w) {
	if (! e || ! w || ! e.style) return;
	if (e.nodeName.toLowerCase() == "ul") {
		e.style.width = w;
	}
	var lastUL = -1;
	for (var i=0; i<e.childNodes.length; i++) {
		setNestedULWidths(e.childNodes[i], w);
		if (e.childNodes[i].nodeName.toLowerCase() == 'ul') {
			lastUL = i;
		}
	}
	if (lastUL > 0) {
		e.childNodes[lastUL].style.marginRight = '0';
	}
}

function resizeContentMenus() {
	var menus = document.getElementById("contentmenu");
	if (! menus) return;
	menus.style.width = "100%";
	var w = menus.clientWidth;
	//var n = menus.childNodes.length;
	var n = getChildrenCount(menus);
	var spacing = 11;
	var targetWidth = parseInt((w - ((n-1)*spacing)) / n) + "px";
	//alert(menus + ": " + n + ": " + w + ": " + targetWidth);
	setNestedULWidths(menus, targetWidth);
	//menus.childNodes[n-1].style.marginRight = "0";
}

function resizeFullFlash() {
	var div = document.getElementById("fullflash");
	if (! div) return;
	var h = document.getElementById("main").clientHeight - 175;
	div.style.height = h+"px";
}

function resizePDF() {
	var pdf = document.getElementById("pdf");
	if (! pdf) return;
	var w = pdf.clientWidth;
	pdf.style.height = (w*0.75)+"px";
}

function scrollPosition() {
	return results (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function results(w, d, b) {
	var result = w ? w : 0;
	if (d && (!result || (result > d))) result = d;
	return b && (!result || (result > b)) ? b : result;
}

function hide(e) {
	e.style.visibility = 'hidden';
}

function show(e) {
	e.style.visibility = 'visible';
}

function checkMore() {
	var m = document.getElementById("more");
	if (!m) return;
	var scroll = scrollPosition();
	var view = window.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
	var page = document.body.scrollHeight || document.documentElement.scrollHeight;
	if (scroll+view == page) hide(m);
	else show(m);
}

function doResize() {
	resizeContentMenus();
	resizeFullFlash();
	resizePDF();
	checkMore();
}

window.onload = function() {
	doResize();
}

window.onresize = function() {
	doResize();
}

window.onscroll = function() {
	checkMore();
}

