// Global variable to hold zone parameter passed
var zone    = "";

// Sliding window related javascripts
function zoneSlideout() {
    // Determine zone parameter passed
    zone   = getURLparameter('zone').toLowerCase();

    // Change the zone map overlay in accordance with the zone parameter passed
    switch(zone) {
        case "heart-of-country":
            document.getElementById("onstate").src  = "/images/parkvis/homepagemap/zone-heart-of-country.gif";
            break;
        case "north-coast":
            document.getElementById("onstate").src  = "/images/parkvis/homepagemap/zone-north-coast.gif";
            break;
        case "outback-nsw":
            document.getElementById("onstate").src  = "/images/parkvis/homepagemap/zone-outback-nsw.gif";
            break;
        case "snowy-mountains":
            document.getElementById("onstate").src  = "/images/parkvis/homepagemap/zone-snowy-mountains.gif";
            break;
        case "south-coast":
            document.getElementById("onstate").src  = "/images/parkvis/homepagemap/zone-south-coast.gif";
            break;
        case "sydney-surrounds":
            document.getElementById("onstate").src  = "/images/parkvis/homepagemap/zone-sydney-surrounds.gif";
            break;
        default:
            // zone parameter will be empty if invalid
            zone    = "";
    }

    // If valid zone parameter passed
    if (zone != "") {
        // Invoke the slide-out custom module
        jQuery('.slide-out-div').tabSlideOut({
            tabHandle: '.handle',                     //class of the element that will become your tab
            tabLocation: 'right',                     //side of screen where tab lives, top, right, bottom, or left
            pathToTabImage: '/images/parkvis/homepagezones/tab-spacer.png', //relative path to the image for the tab
            imageHeight: '218px',                     //height of tab image
            imageWidth: '33px',                       //width of tab image   
            speed: 300,                               //speed of animation
            action: 'click',                          //options: 'click' or 'hover', action to trigger animation
            topPos: '650px',                          //position from the top/ use if tabLocation is left or right
            leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
            fixedPosition: false,                     //options: true makes it stick(fixed position) on scroll
            onLoadSlideOut: true
        });

        // Show the custom slide-out placeholder
        document.getElementById("slider-div").style.display = "block";

        // Change default tab-graphic from spacer to appropriate zone-based graphic
        jQuery('.slide-out-div .handle').attr('style', jQuery('.slide-out-div .handle').attr('style').replace('tab-spacer', 'tab-zone-' + zone));

        // Append custom slide-out placeholder with the zone-based content
        jQuery('.slide-out-div').html(jQuery('.slide-out-div').html() + jQuery('#zone-' + zone).html());

        // Re-invoke slide-out custom module (to effect the change)
        jQuery('.slide-out-div').tabSlideOut({
            tabHandle: '.handle',                     //class of the element that will become your tab
            tabLocation: 'right',                     //side of screen where tab lives, top, right, bottom, or left
            speed: 300,                               //speed of animation
            action: 'click',                          //options: 'click' or 'hover', action to trigger animation
            topPos: '650px',                          //position from the top/ use if tabLocation is left or right
            leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
            fixedPosition: false,                     //options: true makes it stick(fixed position) on scroll
            onLoadSlideOut: true
        });
    }
};

// If region is passed through URL, show this region as highlighted on NSW map
function showCurrentRegion() {
	// See if region is passed through URL
	var selectedRegion = getURLparameter('region');
	if (selectedRegion.length != 0){
		selectedRegionImage = '/images/parkvis/homepagemap/region-' + selectedRegion + '.gif';
		document.getElementById("onstate").src = selectedRegionImage ;
	}
}

// Show highlighted region on load of page
jQuery(document).ready(function() {
	showCurrentRegion();
});

function mouseOver3(strImageID)
{
    // If valid zone parameter passed
    if (zone != "") {
        // Close the slide-out placeholder
        jQuery('.slide-out-div').animate({right: '-435px'}, 300).removeClass('open');
    }

    if(!(typeof(strImageID) == "string")) // guard
    { 
        // The strImageID must be a string value of the id attribute of the menu group UL tag
        return; 
    }
    var imgCurrent = document.getElementById("onstate")
  
    switch(strImageID)
    {
    case "region-blue-mountains":
      imgCurrent.src = "/images/parkvis/homepagemap/region-blue-mountains.gif";
      loadHLight('region-blue-mountains');
      break;
    case "region-central-coast":
      imgCurrent.src = "/images/parkvis/homepagemap/region-central-coast.gif";
      loadHLight('region-central-coast');
      break;
    case "region-eurobodalla-and-sapphire-coast":
      imgCurrent.src = "/images/parkvis/homepagemap/region-eurobodalla-and-sapphire-coast.gif";
      loadHLight('region-eurobodalla-and-sapphire-coast');
      break;
    case "region-upper-north-coast":
      imgCurrent.src = "/images/parkvis/homepagemap/region-upper-north-coast.gif";
      loadHLight('region-upper-north-coast');
      break;
    case "region-illawarra-shoalhaven-and-southern-highlands":
      imgCurrent.src = "/images/parkvis/homepagemap/region-illawarra-shoalhaven-and-southern-highlands.gif";
      loadHLight('region-illawarra-shoalhaven-and-southern-highlands');
      break;
    case "region-mid-north-coast":
      imgCurrent.src = "/images/parkvis/homepagemap/region-mid-north-coast.gif";
      loadHLight('region-mid-north-coast');
      break;
    case "region-new-england-tablelands":
      imgCurrent.src = "/images/parkvis/homepagemap/region-new-england-tablelands.gif";
      loadHLight('region-new-england-tablelands');
      break;
    case "region-newcastle-and-hunter":
      imgCurrent.src = "/images/parkvis/homepagemap/region-newcastle-and-hunter.gif";
      loadHLight('region-newcastle-and-hunter');
      break;
    case "region-north-west":
      imgCurrent.src = "/images/parkvis/homepagemap/region-north-west.gif";
      loadHLight('region-north-west');
      break;
    case "region-outback":
      imgCurrent.src = "/images/parkvis/homepagemap/region-outback.gif";
      loadHLight('region-outback');
      break;
    case "region-richmond-tweed":
      imgCurrent.src = "/images/parkvis/homepagemap/region-richmond-tweed.gif";
      loadHLight('region-richmond-tweed');
      break;
    case "region-snowy-mountains":
      imgCurrent.src = "/images/parkvis/homepagemap/region-snowy-mountains.gif";
      loadHLight('region-snowy-mountains');
      break;
    case "region-south-west":
      imgCurrent.src = "/images/parkvis/homepagemap/region-south-west.gif";
      loadHLight('region-south-west');
      break;
    case "region-sydney-region":
      imgCurrent.src = "/images/parkvis/homepagemap/region-sydney-region.gif";
      loadHLight('region-sydney-region');
      break;
    }
}

function loadHLight(strTextID)
{
    if (strTextID != '')
    {
        //Get and show the regionHighlights
        var divHolder = document.getElementById("regionHighlights")
        divHolder.style.visibility = 'visible';

        //Get and show the regionHighlights
        var divDropDown = document.getElementById("region")
        for(var i = 0; i < divDropDown.options.length; ++i)
        {
            if(divDropDown.options[i].value == strTextID)
            {
                divDropDown.options[i].selected = true;
            }
        }

        //Switch the text around
        var divText = document.getElementById(strTextID)
        divHolder.innerHTML = divText.innerHTML
    }
}

function loadRegionPage(myForm)
{
    switch(myForm.region.value)
    {
        case "region-blue-mountains":
            location.href="/nationalparks/region.aspx?name=blue-mountains";
            break;
        case "region-central-coast":
            location.href="/nationalparks/region.aspx?name=central-coast";
            break;
        case "region-eurobodalla-and-sapphire-coast":
            location.href="/nationalparks/region.aspx?name=eurobodalla-and-sapphire-coast";
            break;
        case "region-upper-north-coast":
            location.href="/nationalparks/region.aspx?name=upper-north-coast";
            break;
        case "region-illawarra-shoalhaven-and-southern-highlands":
            location.href="/nationalparks/region.aspx?name=illawarra-shoalhaven-and-southern-highlands";
            break;
        case "region-mid-north-coast":
            location.href="/nationalparks/region.aspx?name=mid-north-coast";
            break;
        case "region-new-england-tablelands":
            location.href="/nationalparks/region.aspx?name=new-england-tablelands";
            break;
        case "region-newcastle-and-hunter":
            location.href="/nationalparks/region.aspx?name=newcastle-and-hunter";
            break;
        case "region-north-west":
            location.href="/nationalparks/region.aspx?name=north-west";
            break;
        case "region-outback":
            location.href="/nationalparks/region.aspx?name=outback";
            break;
        case "region-richmond-tweed":
            location.href="/nationalparks/region.aspx?name=richmond-tweed";
            break;
        case "region-snowy-mountains":
            location.href="/nationalparks/region.aspx?name=snowy-mountains";
            break;
        case "region-south-west":
            location.href="/nationalparks/region.aspx?name=south-west";
            break;
        case "region-sydney-region":
            location.href="/nationalparks/region.aspx?name=sydney-region";
            break;
        default:

    }
}

// Functions to show and hide the A-Z list of parks on the parks home page
var okayToGo=false;
function countdown(id) {
	okayToGo = true;
	setTimeout ( "disappear('parkList')", 500 );
	}
function disappear(id) {
	if (okayToGo==true) {
		document.getElementById(id).style.display = 'none';
	}
}
function appear(id) {
	okayToGo=false;
	document.getElementById(id).style.display = 'block';
}

// Function to submit form if user hits the 'enter' key in a text box
function checkEnter(e){ //e is event object passed from function invocation
	var characterCode
	
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	} else {
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		document.forms[0].submit() //submit the form
		return false
	} else {
		return true
	}               
}


var currentPic=0;
// Function that cycles through the park spotlights on the home page
function spotlightCycle()
{
	if (currentPic==0) {
		currentPic=1;
		document.getElementById('parkSpotlight').innerHTML = document.getElementById('sp1').innerHTML;
		} else if (currentPic==1) {
		currentPic=2;
		document.getElementById('parkSpotlight').innerHTML = document.getElementById('sp2').innerHTML;
		} else if (currentPic==2) {
		currentPic=3;
		document.getElementById('parkSpotlight').innerHTML = document.getElementById('sp3').innerHTML;
		} else if (currentPic==3) {
		currentPic=4;
		document.getElementById('parkSpotlight').innerHTML = document.getElementById('sp4').innerHTML;
		} else if (currentPic==4) {
		currentPic=5;
		document.getElementById('parkSpotlight').innerHTML = document.getElementById('sp5').innerHTML;
		} else if (currentPic==5) {
		currentPic=6;
		document.getElementById('parkSpotlight').innerHTML = document.getElementById('sp6').innerHTML;
		} else if (currentPic==6) {
		currentPic=7;
		document.getElementById('parkSpotlight').innerHTML = document.getElementById('sp7').innerHTML;
		} else if (currentPic==7) {
		currentPic=0;
		}
	setTimeout('spotlightCycle()',10000);
}

