// requires sniff.js

/**
 * Performs all initialisation procedures for the map
 * application such as registering event listeners.
 * In IE it's necessary to perform the map tools highlight
 * with Javascript - other browsers use CSS
 */
 
 
 
 function initMap () {
    /*
     *  Register event handlers for the rollover effects in the map tools. (this
     * is only for IE as it doesn't provide a hover pseudo class for any elements
     * other than 'a' tags.
     * Painful brute force method used for now as any looping attempts have failed!
     */

	if (document.mapForm.mapClickMode.value =='9')
	{
    	if (document.mapForm.pageOrg.value == 'RAC')
            document.getElementById("zoom-in").style.backgroundImage = "url(images/travel/map/RAC/tools_zoom_inOn.gif)";
    	else if (document.mapForm.pageOrg.value == 'RAA')
            document.getElementById("zoom-in").style.backgroundImage = "url(images/travel/map/RAA/tools_zoom_inOn.gif)";
    	else if (document.mapForm.pageOrg.value == 'RACT')
            document.getElementById("zoom-in").style.backgroundImage = "url(images/travel/map/RACT/tools_zoom_inOn.gif)";
    	else if (document.mapForm.pageOrg.value == 'AANT')
            document.getElementById("zoom-in").style.backgroundImage = "url(images/travel/map/AANT/tools_zoom_inOn.gif)";
    	else if (document.mapForm.pageOrg.value == 'NRMA')
            document.getElementById("zoom-in").style.backgroundImage = "url(images/travel/map/NRMA/tools_zoom_inOn.gif)";
        else    
            document.getElementById("zoom-in").style.backgroundImage = "url(images/travel/map/tools_zoom_inOn.gif)";
    }        
    else if (document.mapForm.mapClickMode.value =='10')    
    {
    	if (document.mapForm.pageOrg.value == 'RAC')
            document.getElementById("zoom-out").style.backgroundImage = "url(images/travel/map/RAC/tools_zoom_outOn.gif)";            
    	else if (document.mapForm.pageOrg.value == 'RAA')
            document.getElementById("zoom-out").style.backgroundImage = "url(images/travel/map/RAA/tools_zoom_outOn.gif)";            
    	else if (document.mapForm.pageOrg.value == 'RACT')
            document.getElementById("zoom-out").style.backgroundImage = "url(images/travel/map/RACT/tools_zoom_outOn.gif)";            
    	else if (document.mapForm.pageOrg.value == 'AANT')
            document.getElementById("zoom-out").style.backgroundImage = "url(images/travel/map/AANT/tools_zoom_outOn.gif)";            
    	else if (document.mapForm.pageOrg.value == 'NRMA')
            document.getElementById("zoom-out").style.backgroundImage = "url(images/travel/map/NRMA/tools_zoom_outOn.gif)";            
        else    
            document.getElementById("zoom-out").style.backgroundImage = "url(images/travel/map/tools_zoom_outOn.gif)";            
    }
    if (IE)
        {
        document.getElementById('zoom_minus').attachEvent('onmouseover', function(){slideImage('zoom_minus', '0 -16px')});
        document.getElementById('zoom_minus').attachEvent('onmouseout', function(){slideImage('zoom_minus', '0 0')});
        document.getElementById('zoom_plus').attachEvent('onmouseover', function(){slideImage('zoom_plus', '0 -16px')});
        document.getElementById('zoom_plus').attachEvent('onmouseout', function(){slideImage('zoom_plus', '0 0')});
        document.getElementById('zoom1').attachEvent('onmouseover', function(){slideImage('zoom1', '0 -16px')});
        document.getElementById('zoom1').attachEvent('onmouseout', function(){slideImage('zoom1', '0 0')});
        document.getElementById('zoom2').attachEvent('onmouseover', function(){slideImage('zoom2', '0 -16px')});
        document.getElementById('zoom2').attachEvent('onmouseout', function(){slideImage('zoom2', '0 0')});
        document.getElementById('zoom3').attachEvent('onmouseover', function(){slideImage('zoom3', '0 -16px')});
        document.getElementById('zoom3').attachEvent('onmouseout', function(){slideImage('zoom3', '0 0')});
        document.getElementById('zoom4').attachEvent('onmouseover', function(){slideImage('zoom4', '0 -16px')});
        document.getElementById('zoom4').attachEvent('onmouseout', function(){slideImage('zoom4', '0 0')});
        document.getElementById('zoom5').attachEvent('onmouseover', function(){slideImage('zoom5', '0 -16px')});
        document.getElementById('zoom5').attachEvent('onmouseout', function(){slideImage('zoom5', '0 0')});
        document.getElementById('zoom6').attachEvent('onmouseover', function(){slideImage('zoom6', '0 -16px')});
        document.getElementById('zoom6').attachEvent('onmouseout', function(){slideImage('zoom6', '0 0')});
        document.getElementById('zoom7').attachEvent('onmouseover', function(){slideImage('zoom7', '0 -16px')});
        document.getElementById('zoom7').attachEvent('onmouseout', function(){slideImage('zoom7', '0 0')});
        document.getElementById('zoom-out').attachEvent('onmouseover', function(){slideImage('zoom-out', '0 -58px')});
        document.getElementById('zoom-out').attachEvent('onmouseout', function(){slideImage('zoom-out', '0 0')});
        document.getElementById('zoom-in').attachEvent('onmouseover', function(){slideImage('zoom-in', '0 -58px')});
        document.getElementById('zoom-in').attachEvent('onmouseout', function(){slideImage('zoom-in', '0 0')});
        document.getElementById('previous').attachEvent('onmouseover', function(){slideImage('previous', '0 -58px')});
        document.getElementById('previous').attachEvent('onmouseout', function(){slideImage('previous', '0 0')});
        document.getElementById('startover').attachEvent('onmouseover', function(){slideImage('startover', '0 -58px')});
        document.getElementById('startover').attachEvent('onmouseout', function(){slideImage('startover', '0 0')});
        }
    
    }



/**
 * Slides a background image within an element by changing the coordinates
 */
function slideImage (elm, position) {
    // move the background image to the new position
    document.getElementById(elm).style.backgroundPosition = position;
}


/**
 * Swaps the feature text on the product page
 */
function toggleHelp (elm, index, state)
{
    var help_text   
    if (IE) 
    {
    help_text = [
        'Zoom IN: Drag a BOX over the AREA of the map you want to see',
        'Zoom OUT: Drag a BOX the size that you want to shrink this map to in your new map',
        'View your Route/Map at its original size',
        'Go back and use your last map',
        'Type in a width and click \'Resize\' to change map',
        '',
        'Zoom level - Click here once to change to STATE level',
        'Zoom level - Click here once to change to REGION level',
        'Zoom level - Click here once to change to TOWN/CITY level',
        'Zoom level - Click here once to change to COMMUNITY level',
        'Zoom level - Click here once to change to NEIGHBOURHOOD level',
        'Zoom level - Click here once to change to STREET level',
        'Zoom level - Click here once to change to HOUSE level',
        ''
    ];
    }
    else
    {
    help_text = [
        'Zoom IN: Select and click the map to move in closer to the area you want to see',
        'Zoom OUT: Select and click the map to move further out from your current area',
        'View your Route/Map at its original size',
        'Go back and use your last map',
        'Type in a width and click \'Resize\' to change map',
        '',
        'Zoom level - Click here once to change to STATE level',
        'Zoom level - Click here once to change to REGION level',
        'Zoom level - Click here once to change to TOWN/CITY level',
        'Zoom level - Click here once to change to COMMUNITY level',
        'Zoom level - Click here once to change to NEIGHBOURHOOD level',
        'Zoom level - Click here once to change to STREET level',
        'Zoom level - Click here once to change to HOUSE level',
        ''
    ];        
    }
    
    text = document.getElementById('help');
    if (state == "on") {
        text.innerHTML = help_text[index];
        //clearTimeout(timeout_id);
    } else {
        //timeout_id = window.setTimeout("text.innerHTML = 'Select an option and click on the map'", 300);
    }
}

