
    window.onresize = resize;

    function resize() {

	var height = document.documentElement.clientHeight;
	var width = document.documentElement.clientWidth;
	var con = document.getElementById("container");
	var half = document.getElementById("halfscreen");
	if (height < 520) {
	    con.style.top = "0";
	    con.style.marginTop = "5px";
	    half.style.height = "255px";
	} else {
	    con.style.top = "50%";
	    con.style.marginTop = "-255px";
	    half.style.height = "50%";
	}

	if (width < 920) {
	    con.style.left = "0";
	    con.style.marginLeft = "5px";
	    half.style.width = "930px";
	} else {
	    con.style.left = "50%";
	    con.style.marginLeft = "-460px";
	    half.style.width = "100%";
	}

    }

    function addDescription() {

	var textareas = getTextAreas();
	var descriptbox = document.getElementById("descriptbox");
	var tadiv = document.createElement('div');
	tadiv.setAttribute('id', 'tadiv'+textareas);
	tadiv.setAttribute('class', 'tadiv');
	var ta = document.createElement('textarea');
	ta.setAttribute('name', 'desc'+textareas);
	ta.setAttribute('id', 'desc'+textareas);
	var rem = document.createElement('a');
	rem.setAttribute('id', 'rem'+textareas);
	rem.setAttribute('onclick', 'removeEl("tadiv'+textareas+'")');
//	rem.setAttribute('style', 'display:block;text-align:right');
	rem.appendChild(document.createTextNode('Remove this Text Area'));
//	tadiv.appendChild(document.createTextNode('Text Area id: desc'+textareas+' | '));
	tadiv.appendChild(rem);
	tadiv.appendChild(ta);
	descriptbox.appendChild(tadiv);
	/*
	tinyMCE.init({
	    mode : "textareas",
	    theme : "advanced",
	});
	*/

    }

    function getTextAreas() {

	// determine number of textareas in document
	var textareas = document.getElementsByTagName('textarea');
	return textareas.length;

    }

    function removeEl(el) {

	elm = document.getElementById(el);
	elm.parentNode.removeChild(elm);
	var textareas = document.getElementsByTagName('textarea');
	for (var i = 0; i < textareas.length; i++) {
	    textareas[i].setAttribute('id', 'desc'+i);
	    textareas[i].setAttribute('name', 'desc'+i);
	}
	for (var i = 0; i < textareas.length; i++) {
	    // alert(textareas[i].getAttribute('id'));
	}

    }

    function removeDescription(desc) {

	var desc = document.getElementById(desc);
	var i = 0;
	var str = '';
	while (desc.parentNode.childNodes[i]) {
	    str += desc.parentNode.childNodes[i].nodeName + ': ' + desc.parentNode.childNodes[i].nodeValue + "\n";
	    if (desc.parentNode.childNodes[i].hasChildNodes()) {
		    str += 'has children: ';
		    str += desc.parentNode.childNodes[i].firstChild.nodeName + "\n";
	    }
	    i++;
	}
	desc.parentNode.removeChild(desc);

    }

    function swapDesc() {

	switchDesc();
	/*
	var descA = document.getElementById('descA');
	var descB = document.getElementById('descB');
	if (descA.style.display == 'none') {
	    shiftleft('descB');
	} else {
	    shiftleft('descA');
	}
	*/
    }

    function switchDesc() {
	var descA = document.getElementById('descA');
	var descB = document.getElementById('descB');
	var swap = document.getElementById('swap');
	if (descA.style.display == 'none') {
	    descB.style.display = 'none';
	    descA.style.display = 'block';
        swap.innerHTML = '1 | <a onclick="swapDesc()">2</a>';
	} else {
	    descA.style.display = 'none';
	    descB.style.display = 'block';
        swap.innerHTML = '<a onclick="swapDesc()">1</a> | 2';
    }
    /*
	var a = document.createElement('a');
	a.setAttribute('onclick', 'swapDesc()');
	if (descA.style.display == 'none') {
	    descB.style.display = 'none';
	    descA.style.display = 'block';
	    swap.removeChild(swap.lastChild);
	    swap.removeChild(swap.lastChild);
	    swap.appendChild(document.createTextNode('1 | '));
	    a.appendChild(document.createTextNode('2'));
	    swap.appendChild(a);
	//    shiftright('descA');
	} else {
	    descA.style.display = 'none';
	    descB.style.display = 'block';
	    swap.removeChild(swap.lastChild);
	    swap.removeChild(swap.lastChild);
	    a.appendChild(document.createTextNode('1'));
	    swap.appendChild(a);
	    swap.appendChild(document.createTextNode(' | 2'));
	//   shiftright('descB');
	}
    */
    }

    var left = 0;
    var i = 0;
    var tween = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1); // all these numbers add up to 100
    var tween2 = new Array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1); // all these numbers add up to 55 

    function shiftleft(id) {
	left -= Math.round(tween2[i] * 300/55); 
	document.getElementById(id).style.left = left + 'px';
	i++;
	if(left > -300) {
            setTimeout("shiftleft('" + id + "')", 50);
	} else {
	    i=0;
	    left = -300;
	    switchDesc();
	}
    }

    function shiftright(id) {
	left += Math.round(tween2[i] * 300/55); 
	document.getElementById(id).style.left = left + 'px';
	i++;
	if(left < 0) {
            setTimeout("shiftright('" + id + "')", 50);
	} else {
	    document.getElementById(id).style.left = 0;
	    i=0;
	    left = 0;
	}
    }

    /*
    tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	//plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr/advimage,advlink,emotions,iespell",

	// Theme options
//	theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull"
	//theme_advanced_buttons3_add : "tablecontrols",
	//table_styles : "Header 1=header1;Header 2=header2;Header3=header3",
	//table_cell_styles : "Header 1=header1;Header 2=header2;Header3=header3;Table Cell=tableCell",

	// CSS
	//content_css : "./css/styles.css"
    });
    */

    function step(bf, arraylength) {
	bf == "b" ? num-- : num++;
	num >= arraylength ? num = 0 : "";
	var limit = arraylength - 1;
	num < 0 ? num = limit : "";
	fadeout("image", jpgnames[num]);
//	document.getElementById("image").src = jpgnames[num];
	var imgnum = document.getElementById("imgnum");
	imgnum.removeChild(imgnum.firstChild);
	imgnum.appendChild(document.createTextNode(num+1));
	var caption = document.getElementById("caption");
	caption.innerHTML = captions[num];
    }

    function switchimg(el, jpg) {
	document.getElementById(el).src = jpg;
	fadein(el);
    }

    var opa = 9;

    function fadeout(id, jpg) {
	var op;
	opa == 0 ? op = 0 : op = "0." + opa;
	document.getElementById(id).style.opacity = op;
	e = opa * 10;
	document.getElementById(id).style.filter = "alpha(opacity=" + e + ")";
	opa -= 3;
	if (opa >= 3) {
	    var repeat = function() {
		fadeout(id, jpg);
	    }
            setTimeout(repeat, 100);
	} else {
	    switchimg(id, jpg);
	}
    }

    function fadein(id) {
	document.getElementById(id).style.opacity = "0." + opa;
	e = opa * 10;
	document.getElementById(id).style.filter = "alpha(opacity=" + e + ")";
	opa += 3;
	if (opa <= 10) {
            setTimeout("fadein('" + id + "')", 100);
	} else {
	    document.getElementById(id).style.opacity = "1";
	    document.getElementById(id).style.filter = "alpha(opacity=100)";
	    opa = 9;
	}
    }


    // SELECT BOX FUNCTION
    //
    function selectopts() {

	var tlw1 = document.getElementById("tlw1");
	tlw1.style.background = "#7790aa";
	tlw1.style.color = "#fff";
	var tlw2 = document.getElementById("tlw2");
	tlw2.style.background = "#7790aa";
	tlw2.style.color = "#fff";

    }

    function selectoff() {

	var tlw1 = document.getElementById("tlw1");
	tlw1.style.background = "none";
	tlw1.style.color = "#fff";
	var tlw2 = document.getElementById("tlw2");
	tlw2.style.background = "none";
	tlw2.style.color = "#fff";

    }

    // navbar swap title
    
    var curtitle;

    function swaph2(title) {

	curtitle = document.getElementById("pich2").innerHTML;
	document.getElementById("pich2").innerHTML = title;

    }

    function restoreh2() {

	document.getElementById("pich2").innerHTML = curtitle;

    }

    function loadfns() {

	//startbgcolours();
//	chColour();
	startList();
	resize();
	jsRandomImage(slideshowimgs, 0);

    }

    // enables css suckerfish menu in IE using javascript
    startList = function() {
	if(document.all && document.getElementById) {
	    navRoot = document.getElementById("nav");
	    for(i = 0; i < navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
		if(node.nodeName == "LI") {
		    node.onmouseover = function() {
			this.className += " over";
		    }
		    node.onmouseout = function() {
			this.className = this.className.replace(" over", '');
		    }
		}
	    }
	}
    }

    function startbgcolours() {

	setTimeout("chColour()", Math.round(Math.random()*5000));

    }

    var bgcolours = new Array("#800", "#693", "#ca0", "#235", "#569", "#aa7", "#430", "#c66");

    function chColour() {
	
	var i = Math.floor(Math.random() * bgcolours.length);
	document.getElementsByTagName("body")[0].style.background = bgcolours[i];
	if (document.getElementById("pich2")) document.getElementById("pich2").style.background = bgcolours[i];
	if (document.getElementById("ul1")) document.getElementById("ul1").style.background = bgcolours[i];
	if (document.getElementById("ul2")) document.getElementById("ul2").style.background = bgcolours[i];
	if (document.getElementById("onlineprojects")) document.getElementById("onlineprojects").style.background = bgcolours[i];
	if (document.getElementById("video")) document.getElementById("video").style.background = bgcolours[i];
	setTimeout("chColour()", Math.round(Math.random()*5000));

    }

    /*
    // IN NEW WINDOW
    function launchvideo(url) {

	window.open("./video.php?url=" + url, "videoWindow", "resizable=no, scrollbars=no, status=no, toolbar=no, location=no, width=400, height=325");

    }
    */

    function closevideo() {

	var el = document.getElementById("vidobj");
	el.parentNode.removeChild(el);
	document.getElementById("video").style.display = "none";

    }

    function displayprojtitle(title, id, href) {

	var box = document.getElementById("projtitle");
	box.innerHTML = title;
	box.setAttribute("href", href)
	var imgs = document.getElementsByTagName("img");
	for (var i = 0; i < imgs.length; i++) {
	    imgs[i].style.borderColor = "transparent";
	}
	var pic = document.getElementById(id);
	pic.style.borderColor = "#ced";

    }

    function noborder(id) {

	/*
	var pic = document.getElementById(id);
	pic.style.borderColor = "transparent";
	var box = document.getElementById("projtitle");
	box.innerHTML = '';
	*/

    }

    var lastimg = '';

    function jsRandomImage(val, initialimg) {	// initialimg is 1 or 0; deprecated: using
						// php to display the first image
						// until the others are loaded
	var namesArray = new Array;
	for (var i = 0; i < val.length; i++) {
	    namesArray[i] = val[i];
	}
	// alert(val);
	var rand = Math.floor(Math.random() * namesArray.length);
	var src = "./images/slideshow/" + namesArray[rand];
	namesArray[rand] = 0;
	var tempnames = new Array();
	var count = 0;
	for (var i = 0; i < namesArray.length; i++) {
	    if (namesArray[i]) {
		tempnames[count] = namesArray[i];
		count++;
	    }
	}
	if (initialimg) {
	    document.getElementById("randomImage").src = src;
	    jsRandomImage(tempnames, 0);
	    return;
	}
	if (tempnames.length == 0) {
	    lastimg = src;
	    var repeat = function() {
		fadeout("randomImage", src);
		jsRandomImage(slideshowimgs, 0);
	    }
	    setTimeout(repeat, 5000);
	} else {
	    if (src == lastimg) {
		jsRandomImage(slideshowimgs, 0);
		return;
	    }
	    var repeat = function() {
		fadeout("randomImage", src);
		jsRandomImage(tempnames, 0);
	    }
	    setTimeout(repeat, 5000);
	}
    }

