// Javascript  - thanks to Stuart Langridge for an excellent
// book "DHTML Utopia: Modern Web Design"
// Author - Neil Hulbert

function addEvent(element, eventtype, fn, userCapture)
{

    if (element.addEventListener)		// DOM-compliant browser
    {
        element.addEventListener(eventtype, fn, userCapture);
        return true;
    }
    else
    if (element.attachEvent)		// Internet Explorer
    {
        var result = element.attachEvent('on' + eventtype, fn);
        return result;
    }
    else
        element['on' + eventtype] = fn;	// old fashioned browser

}

function ascendDOM(element,target)
{
    while (element.nodeName.toLowerCase() != target &&
         element.nodeName.toLowerCase() != 'html')
    element = element.parentNode;

    return (element.nodeName.toLowerCase() == 'html' ? null : element);
}

 
function getTarget(event, targettype)
{
    var temp;

    if (window.event && window.event.srcElement)	// Internet Explorer
    temp = window.event.srcElement;

    if (event && event.target)				// DOM-compliant
    temp = event.target;

    if (temp) temp = ascendDOM(temp,targettype);

    return temp;
}

function updatePosition()
{
    timeCount++;   
    currLeftPos = parseInt((windowIndex - 1)*768 + (1 - Math.cos(timeCount/40*Math.PI))*(targetWindowIndex - windowIndex)*384);   

    backgroundFrame.style.left = -currLeftPos + 'px';


    if (timeCount == 40)
    {
        clearInterval(interval);
        windowIndex=targetWindowIndex;
        timeCount = 0;
    }
    else
    {}
}

function pcwidthPosition()
{  
   
    pcwidthCount+=5;    
    pcpic.style.width = pcwidthCount + 'px';

 

    if (pcwidthCount == 250)
    {

        clearInterval(pcwidthInterval);
        pcwidthCount = 0;
    }

}

function netwidthPosition()
{  
   
    netwidthCount+=5;    
    netpic.style.width = netwidthCount + 'px';

    if (netwidthCount == 250)
    {
        clearInterval(netwidthInterval);
        netwidthCount = 0;
    }

}


function setLink (button)
{

    currLink.style.color = '#666666';
    currLink.style.fontWeight = 'normal';

    button.style.color = '#174a81';
    button.style.fontWeight = 'normal';
    button.style.border = '0px';

    currLink = button; 

}

    

function handleWebClick (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target


    if (targetWindowIndex == 1) return;
    targetWindowIndex = 1;
    setLink(webbutton); 

    timeCount = 0;    
    interval = setInterval(function() {updatePosition()},30);
    
}
    
function handlePCClick (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target  

    if (targetWindowIndex == 2) return;
    targetWindowIndex = 2;
    setLink(pcbutton);

    timeCount = 0;    
    interval = setInterval(function() {updatePosition()},30);

    pcwidthCount = 0;
    pcwidthInterval = setInterval(function() {pcwidthPosition()},30);

}
  
function handleNetworkClick (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target


    if (targetWindowIndex == 3) return;
    targetWindowIndex = 3;
    setLink(networkbutton);

    timeCount = 0;    
    interval = setInterval(function() {updatePosition()},30);

    netwidthCount = 0;
    netwidthInterval = setInterval(function() {netwidthPosition()},30);

    
}
    
function handleAboutusClick (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target 
    
    if (targetWindowIndex == 4) return;
    targetWindowIndex = 4;
    setLink(aboutusbutton);

    timeCount = 0;    
    interval = setInterval(function() {updatePosition()},30);
}

function handleLegalClick (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target 
    
    if (targetWindowIndex == 5) return;
    targetWindowIndex = 5;
    setLink(legalbutton);

    timeCount = 0;    
    interval = setInterval(function() {updatePosition()},30);
}

function handleWebMouseOver (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target


    if (windowIndex != 1) webbutton.style.color = '#7e233f';
    
}

function handlePCMouseOver (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target



    if (windowIndex != 2) pcbutton.style.color = '#7e233f';
    
}

function handleNetworkMouseOver (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target


    if (windowIndex != 3) networkbutton.style.color = '#7e233f';
    
}

function handleAboutusMouseOver (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target


    if (windowIndex != 4) aboutusbutton.style.color = '#7e233f';
    
}

function handleLegalMouseOver (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target


    if (windowIndex != 5) legalbutton.style.color = '#7e233f';
    
}

function handleWebMouseOut (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target


    if (targetWindowIndex != 1) webbutton.style.color = '#666666';
    
}

function handlePCMouseOut (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target


    if (targetWindowIndex != 2) pcbutton.style.color = '#666666';
    
}

function handleNetworkMouseOut (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target


    if (targetWindowIndex != 3) networkbutton.style.color = '#666666';
    
}

function handleAboutusMouseOut (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target


    if (targetWindowIndex != 4) aboutusbutton.style.color = '#666666';
    
}

function handleLegalMouseOut (event)
{

    if (!getTarget(event,'a')) return;			// couldn't determine target


    if (targetWindowIndex != 5) legalbutton.style.color = '#666666';
    
}
      

function failSilently()
{
//  Don't do anything - just fall over
}
    
function init()
{
    window.onError = failSilently;

    if (!document.getElementById) return;	// we really are in trouble!!

    webbutton = document.getElementById('Web');
    pcbutton = document.getElementById('PC');
    networkbutton = document.getElementById('Network');
    aboutusbutton = document.getElementById('Aboutus');
    legalbutton = document.getElementById('Legal');
    advertisingbutton = document.getElementById('advert');
    discussbutton = document.getElementById('discuss');
    backgroundFrame = document.getElementById('services');
    pcpic = document.getElementById('pcconsulting');
    netpic = document.getElementById('homenet');
    currLink=webbutton;
    setLink(webbutton);

    
   
    addEvent(webbutton, 'click', handleWebClick, false);
    addEvent(pcbutton, 'click', handlePCClick, false);
    addEvent(networkbutton, 'click', handleNetworkClick, false);
    addEvent(aboutusbutton, 'click', handleAboutusClick, false);
    addEvent(legalbutton, 'click', handleLegalClick, false);
    addEvent(advertisingbutton, 'click', handleLegalClick, false);
    addEvent(discussbutton, 'click', handleAboutusClick,false);
    addEvent(webbutton, 'mouseover', handleWebMouseOver, false);
    addEvent(pcbutton, 'mouseover', handlePCMouseOver, false);
    addEvent(networkbutton, 'mouseover', handleNetworkMouseOver, false);
    addEvent(aboutusbutton, 'mouseover', handleAboutusMouseOver, false);
    addEvent(legalbutton, 'mouseover', handleLegalMouseOver, false);
    addEvent(webbutton, 'mouseout', handleWebMouseOut, false);
    addEvent(pcbutton, 'mouseout', handlePCMouseOut, false);
    addEvent(networkbutton, 'mouseout', handleNetworkMouseOut, false);
    addEvent(aboutusbutton, 'mouseout', handleAboutusMouseOut, false);
    addEvent(legalbutton, 'mouseout', handleLegalMouseOut, false);

    
    currLeftPos = 0;
    
    document.getElementsByTagName('body')[0].style.visibility = "visible";
    
}
    

var interval;			// Time interval variable
var currLeftPos;
var webbutton, pcbutton, networkbutton, aboutusbutton,legalbutton,advertisingbutton, discussbutton;
var backgroundFrame;
var timeCount;
var windowIndex = 1;
var targetWindowIndex = 1;
var currLink;
var pcwidthCount;
var pcwidthInterval;
var netwidthCount;
var netwidthInterval;
var pcpic;
var netpic;





addEvent(window, 'load', init, false);








