var mainId = 'academySWF';
var menuId = 'menuSWF';

function onInit()
{
    var items = getFlaggedItems();
    
    for(var pid in items)
    {
        flagSelectionFromMenu(pid);
        flagSelectionFromMain(pid);
    }
}

function enableMenu() {
	document.getElementById(menuId).enableMenu();
}

function resizeMenu(menuHeight) {
    document.getElementById('menu').style.height = (menuHeight + 30) + 'px';
}

function flagSelectionFromMenu(pid)
{
	flag(pid);
	
	try {
        document.getElementById(mainId).flagSelection(pid);

    } catch(e) {
        // meh
    }
}

function unflagSelectionFromMenu(pid)
{
	unflag(pid);
	
	try {
        document.getElementById(mainId).unflagSelection(pid);

    } catch(e) {
        // meh
    }
}

function clearSelectionsFromMenu()
{
	try {
        document.getElementById(mainId).unflagAllSelections();

    } catch(e) {
        // meh
    }
}

function flagSelectionFromMain(pid)
{
	flag(pid);
	
	try {
        document.getElementById(menuId).flagSelection(pid);

    } catch(e) {
        // meh
    }
}

function unflagSelectionFromMain(pid)
{
	unflag(pid);
	
	try {
        document.getElementById(menuId).unflagSelection(pid);

    } catch(e) {
        // meh
    }
}

function clearSelectionsFromMain()
{
	try {
        document.getElementById(menuId).unflagAllSelections();

    } catch(e) {
        // meh
    }
}


function deselectMarker() {
    document.getElementById(mainId).deselectMarker();
}

function deselectHighlighted() {
	document.getElementById(menuId).deselectHighlighted();
}

function clearSuperSectionSelection() {
    document.getElementById(mainId).clearSuperSectionSelection();
}

function setSuperSectionSelection(superSectionName) {
    document.getElementById(mainId).setSuperSectionSelection(superSectionName);
}

function superSectionSelectionChanged(superSectionName) {
	document.getElementById(menuId).superSectionSelectionChanged(superSectionName);
    if (console && console.log) console.log(superSectionName);
}

function clearSectionSelection() {
    document.getElementById(mainId).clearSectionSelection();
}

function setSectionSelection(sectionName) {
    document.getElementById(mainId).setSectionSelection(sectionName);
}

function sectionSelectionChanged(sectionName) {
	document.getElementById(menuId).sectionSelectionChanged(sectionName);
    if (console && console.log) console.log(sectionName);
}

function clearAttractionSelection() {
    document.getElementById(mainId).clearAttractionSelection();
}

function setAttractionSelection(attractionName) {
    document.getElementById(mainId).setAttractionSelection(attractionName);
}

function attractionSelectionChanged(attractionName) {
	document.getElementById(menuId).attractionSelectionChanged(attractionName);
    if (console && console.log) console.log(attractionName);
}

function clearExhibitSelection() {
    document.getElementById(mainId).clearExhibitSelection();
}

function setExhibitSelection(id) {
    document.getElementById(mainId).setExhibitSelection(id);
}

function exhibitSelectionChanged(id) {
	document.getElementById(menuId).exhibitSelectionChanged(id);
    if (console && console.log) console.log(id);
}

function getCenterZoom() {
    var location = document.getElementById(mainId).getCenterZoom();
    return location; // array [lat, lon, zoom] 
}

function setCenterZoom(lat, lon, zoom) {
    document.getElementById(mainId).setCenterZoom(lat, lon, zoom); 
}

function getFloor() {
    var floor = document.getElementById(mainId).getFloor();
    return floor; // name of a floor, e.g. "Ground Floor" 
}

function setFloor(floor) { 
    document.getElementById(mainId).setFloor(floor); 
}

// only for the CMS swf            
function getWidthAndHeight() {
    var widthAndHeight = document.getElementById(mainId).getWidthAndHeight();
    return widthAndHeight; // array [ latHeight, lonWidth ]
}

// only for the CMS swf            
function setWidthAndHeight(latHeight, lonWidth) { 
    document.getElementById(mainId).setWidthAndHeight(latHeight, lonWidth); 
}

function centerZoomChanged() {
    if (console && console.log) {
        console.log(getCenterZoom());
        console.log(getFloor());
        // only for the CMS swf
        console.log(getWidthAndHeight());
    }
}
