/************************************** Splendid *************************************
 * Created By:		Steve Doggett
 * Creation Date:	11th September 2007
 * Edited ----------------------------------------------------------------------------
 *      By:               On:
 * Description -----------------------------------------------------------------------
 *      This file creates a Disruption Map functionality
 *
 *      Functions:
 *          initDisruptionMap()
 *          createDisruptionPin( place )
 *          positionPin( place, counter )
 *      
 **************************************************************************************/

var numOpen = 0;

/****
 * Initialises the pins on the map.
 * the map is a background image on a div
 ****/
function initDisruptionMap()
{
    if( arrDisrupt.length > 0 )
    {
        for( var i=0; i<arrDisrupt.length; i++ )
        {
            createDisruptionPin(arrDisrupt[i]);
            positionPin( arrDisrupt[i], i );
        }
    }
}


/****
 * Opens and closes the disrupt panels
 ****/
function toggleDisrupt( which, nodeID )
{
    if(which.className.toLowerCase() == 'arrowmore' )
    {
//        if( numOpen == 0 )
//            hideAllDisruptPins();

        which.className = 'arrowless';
        document.getElementById('disrupt'+nodeID).style.display = 'block';
        //showDisruptionPin( parseInt(nodeID-1) );
        numOpen = parseInt(numOpen+1);
    } else
    {
        which.className = 'arrowmore';
        document.getElementById('disrupt'+nodeID).style.display = 'none';
        
        numOpen = numOpen-1;
        //hideDisruptionPin( parseInt(nodeID-1) );
        
        if( numOpen == 0 )
            showAllDisruptPins();
    }
    return false;
}

/****
 * Hides all the current disruption pins
 ****/
function hideAllDisruptPins()
{
    if( arrDisrupt.length > 0 )
    {
        for( var i=0; i<arrDisrupt.length; i++ )
        {
            document.getElementById('Pin'+arrDisrupt[i]).style.display = 'none';
        }
    }
}

/****
 * Shows all the current disruption pins
 ****/
function showAllDisruptPins()
{
    if( arrDisrupt.length > 0 )
    {
        for( var i=0; i<arrDisrupt.length; i++ )
        {
            document.getElementById('Pin'+arrDisrupt[i]).style.display = 'block';
        }
    }
}

/****
 * Shows a single disruption pin
 ****/
function showDisruptionPin( idx )
{
    document.getElementById('Pin'+arrDisrupt[idx]).style.display = 'block';
}

/****
 * Hides a single disruption pin
 ****/
function hideDisruptionPin( idx )
{
    document.getElementById('Pin'+arrDisrupt[idx]).style.display = 'none';
}

/****
 * Creates a disruption pin and adds it to the page
 ****/
function createDisruptionPin( place )
{
    var divElem = document.createElement('div');
    divElem.setAttribute('id', 'divPin'+place);
    //divElem.setAttribute('style', 'position:absolute;');
    divElem.style.position = 'absolute';
    
    var elem = document.createElement('img');
    elem.setAttribute('src', pinURL);
    elem.setAttribute('id', 'Pin'+place);
    divElem.appendChild(elem);
    
    document.getElementById('disruptionMap').appendChild(divElem);
}

/****
 * positions the pins on the map depending on which are selected
 ****/
function positionPin( place, counter )
{
    var node = null;
    
    switch( place.toLowerCase() )
    {
        case 'hull':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '130px';
                node.style.left = '76px';
                node.style.zIndex = '100';
            }catch(e){}
            break;
        case 'london':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '204px';
                node.style.left = '83px';
            }catch(e){}
            break;
        case 'leeds':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '125px';
                node.style.left = '50px';
                node.style.zIndex = '100';
            }catch(e){}
            break;
        case 'york':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '101px';
                node.style.left = '57px';
                node.style.zIndex = '150';
            }catch(e){}
            break;
        case 'newcastle':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '81px';
                node.style.left = '56px';
                node.style.zIndex = '100';
            }catch(e){}
            break;
        case 'edinburgh':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '59px';
                node.style.left = '40px';
                node.style.zIndex = '100';
            }catch(e){}
            break;
        case 'glasgow':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '60px';
                node.style.left = '9px';
                node.style.zIndex = '100';
            }catch(e){}
            break;
        case 'aberdeen':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '16px';
                node.style.left = '53px';
            }catch(e){}
            break;
        case 'inverness':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '13px';
                node.style.left = '13px';
            }catch(e){}
            break;
        case 'peterborough':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '170px';
                node.style.left = '82px';
                node.style.zIndex = '100';
            }catch(e){}
            break;
        case 'aberline':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '34px';
                node.style.left = '35px';
            }catch(e){}
            break;
        case 'invline':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '40px';
                node.style.left = '14px';
            }catch(e){}
            break;
        case 'edglas':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '60px';
                node.style.left = '27px';
            }catch(e){}
            break;
        case 'newed':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '71px';
                node.style.left = '49px';
            }catch(e){}
            break;
        case 'newyork':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '91px';
                node.style.left = '57px';
            }catch(e){}
            break;
        case 'peteyork':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '120px';
                node.style.left = '57px';
            }catch(e){}
            break;
        case 'peteleeds':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '160px';
                node.style.left = '75px';
            }catch(e){}
            break;
        case 'leedshull':
            try{
                node = document.getElementById('divPin'+place);
                node.style.top = '131px';
                node.style.left = '65px';
            }catch(e){}
            break;
    }
}
