var uid = new Date().getTime();
var flashProxy = new FlashProxy(uid, '/style2008/gateway/JavaScriptFlashGateway.swf');

/*
    areaShown is called from flash each time a area is changed and it's showing on flash.
    params: -areaName:String : name of the current area (usa,europe,asia, notfound) currently only europe is in the flash
*/
function areaShown(areaName) {

    /* We wish to toggle between what's being shown in the navigation */
    var aElem = document.getElementById('content-'+areaName+'-'+areaName);
    
//    if(areaName == "usa") {
//        clear_display(true);
    //    var aElem = document.getElementById('content-usa-usa');
//        document.getElementById('subnav-asia').style.display = "none";
//        document.getElementById('subnav-europe').style.display = "none";
//    } else if(areaName != "notfound") {
      if(areaName != "notfound") {
        clear_display(true);
        var snElem = document.getElementById('subnav-'+areaName);
        snElem.style.display = "block";
        if (areaName == "europe")
        {
            document.getElementById('subnav-asia').style.display = "none";
            document.getElementById('subnav-america').style.display = "none";
        }
        else if (areaName == "america")
        {   
            document.getElementById('subnav-asia').style.display = "none";
            document.getElementById('subnav-europe').style.display = "none";
        }
        else if(areaName == "asia")
        {
            document.getElementById('subnav-europe').style.display = "none";
            document.getElementById('subnav-america').style.display = "none";
        }
    }
    aElem.style.display = "block";
}

/*
    areaHidden is called from flash each time a area is changed and it's no longer showing on flash (means we are back at the world map).
    params: -areaName:String : name of the last area (usa,europe,asia, notfound) currently only europe is in the flash
*/
function areaHidden(areaName) {
    
    clear_display(false);
    
//    if(areaName == "usa") {
//        var aElem = document.getElementById('content-usa-usa');
//        aElem.style.display = "none";
//    } else if(areaName != "notfound") {
      if(areaName != "notfound") {
        var snElem = document.getElementById('subnav-'+areaName);
        snElem.style.display = "none";
    }
    show_main();
}

/*
    showArea: Use this function to change the area in flash.
    params: -areaName:String : possible values currently (europe) later (usa,europe,asia)
*/
function showArea(areaName) {
    /* Add your logic here... ie. remove old data from somewhere */
    clear_display(true);
    aElem = document.getElementById('content-'+areaName+'-'+areaName);
    aElem.style.display = 'block';
    flashProxy.call('showArea', areaName);
}

/*
    placeSelected is called from flash when user clicks on active area one of it's places.
    params: -areaName:String : name of the current area (usa,europe,asia, notfound) currently only europe is in the flash
            -placeName:String : name of the place clicked. (these vary depending on the selected area)
*/
function placeSelected(areaName,placeName) {
    /* Add your logic here... ie. get data via ajax and show it somewhere */
    
    /*
     Here we are still missing logic to hide other countries... This could be done many ways.
     ie. getting all div elements under the content-areaname div and hide them in a loop
    */
    clear_display(true);
    
//    if(areaName == "usa") {
//        var aElem = document.getElementById('content-usa-usa');
//        aElem.style.display = "block";
//    } else if(areaName != "notfound") {
      if(areaName != "notfound") {
        var aElem = document.getElementById('content-'+areaName+'-'+placeName);
        aElem.style.display = "block";
        var snElem = document.getElementById('subnav-'+areaName);
        snElem.style.display = "block";
    }    
    
}
/*
    mapShown is called from flash when flash returns to it's idle state (showing the world map).
*/
function mapShown() {
    /* Add your logic here... ie. remove old data from somewhere */
    // Has yet to do anything
}

/*
    selectPlace doesn't currectly do anything...
*/
function selectPlace(areaName,placeName) {
    flashProxy.call('selectPlace', areaName, placeName);
    placeSelected(areaName, placeName);
}

/*
    showMap sets any active area to go hidden and returns the flash to standby state (showing the world map)
*/
function showMap() {
    flashProxy.call('showMap');
}

function show_main()
{
    main_element = document.getElementById('flash-main');
    main_element.style.display = 'block';
}

function clear_display(hide_main)
{
    if (hide_main)
    {
        main_element = document.getElementById('flash-main');
        main_element.style.display = 'none';   
    }
//    element_count = document.getElementsByClassName('flash-content');    
    element_count = getElementsByClassName(document, 'div', 'flash-content');
    for (var i = element_count.length - 1; i >= 0; i--){
        element_count[i].style.display = 'none';
    }
}

