﻿// JScript File

// getURL() : Current Page Reference
// copyright Stephen Chapman, 1st Jan 2005
// you may copy this function but please keep the copyright notice with it
function getURL(uri)
{
	uri.dir = location.href.substring(0, location.href.lastIndexOf('\/'));
	uri.dom = uri.dir; if (uri.dom.substr(0,7) == 'http:\/\/') uri.dom = uri.dom.substr(7);
	uri.path = ''; var pos = uri.dom.indexOf('\/'); if (pos > -1) {uri.path = uri.dom.substr(pos+1); uri.dom = uri.dom.substr(0,pos);}
	uri.page = location.href.substring(uri.dir.length+1, location.href.length+1);
	pos = uri.page.indexOf('?');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
	pos = uri.page.indexOf('#');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
	uri.ext = ''; pos = uri.page.indexOf('.');if (pos > -1) {uri.ext =uri.page.substring(pos+1); uri.page = uri.page.substr(0,pos);}
	uri.file = uri.page;
	if (uri.ext != '') uri.file += '.' + uri.ext;
	if (uri.file == '') uri.page = 'index';
	uri.args = location.search.substr(1).split("?");
	return uri;
}
function changeImageFade(newImage)
{
    var bigImgElmt = document.getElementById('BigImage');
    var newImgObject = new Image();
    newImgObject.onload = function()
    {
        var imgHTML = bigImgElmt.outerHTML;
        imgHTML = imgHTML.replace(/src.*\.jpg/, 'src=Images/' + newImage + '.jpg');
        $('#' + bigImgElmt.id).fadeOut(600, function()
        {
            bigImgElmt.outerHTML = imgHTML;
            $('#' + bigImgElmt.id).fadeIn(600);
        });
    };
    newImgObject.src = 'Images/' + newImage + '.jpg';
};
//---------------------------------
function changeImageSrc(newImageSrc)
{
    var newImagePath = 'Images/' + newImageSrc + '.jpg';
    document.getElementById('BigImage').src = newImagePath;
}
//---------------------------------
function changeImage(newImage)
{
    var bigImgElmt = document.getElementById('BigImage');
    var imgHTML = bigImgElmt.outerHTML;
    imgHTML = imgHTML.replace(/src.*\.jpg/, 'src=Images/' + newImage + '.jpg');
    bigImgElmt.outerHTML = imgHTML;
};
//---------------------------------
function changeElementText(id, txt)
{
    var obj = document.getElementById(id);
    obj.firstChild?obj.firstChild.data = txt:obj.appendChild(document.createTextNode(txt));
};
//---------------------------------
function changeProjectItem(newImage, txt)
{
    changeElementText('ProjText', txt);
    changeImageSrc(newImage);
};
// Gradually increase TagLine letter-spacing to 25px
function expandTag()
{
    expandText('TagLine', 25);
}
// Reset letter-spacing to 2px, then increase to target
function expandText(id, pxTo)
{
    this.elem = document.getElementById(id);
    this.iLs = 2;
    this.pxTo = pxTo;
    this.elem.style.letterSpacing = this.iLs + 'px';
    setTimeout('onEtTimeout()', 3000);
}
function onEtTimeout()
{
    this.iLs += 1;
    if (this.iLs > this.pxTo)
        return;
    this.elem.style.letterSpacing = this.iLs + 'px';
    setTimeout('onEtTimeout()', 100);
}
function initTagLine()
{
    changeElementText('TagLine', 'Make the most of your space');
    changeHomeTagLine();
}
// Initialise tag line letter spacing on Home page only.
// Other pages use CSS default.
function changeHomeTagLine()
{
	// Detect Home page
	var uri = new Object();
	getURL(uri);
//    if (window.location.href.search('') >= 0)
    if (uri.page == '')
    {
        var elem = document.getElementById('TagLine');
        elem.style.letterSpacing = '2px';
    }
}

                  
