﻿
/* global variables */
var menu = '';

/* event listener */
if(document.layers) document.captureEvents(Event.MOUSEUP);
WindowOldEventListener = document.onmouseup;

if(WindowOldEventListener != null)
    document.onmouseup = new Function("WindowOldEventListener(); HideMenu();");
else
    document.onmouseup = HideMenu;

/* menu functionality */
function AnchorPosition_getPageOffsetLeft(el)
    {
	    var ol=el.offsetLeft;
	    while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	    return ol;
	}
	
function AnchorPosition_getWindowOffsetLeft(el)
    {
	    return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}
	
function AnchorPosition_getPageOffsetTop(el)
    {
	    var ot=el.offsetTop;
	    while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	    return ot;
	}
	
function AnchorPosition_getWindowOffsetTop(el)
    {
	    return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}

function getAnchorPosition(anchorname)
    {
	    var useWindow=false;
	    var coordinates=new Object();
	    var x=0,y=0;

	    var use_gebi=false, use_css=false, use_layers=false;
	
	    if(document.getElementById) { use_gebi=true; }
	    else if (document.all) { use_css=true; }
	    else if (document.layers) { use_layers=true; }

 	    if(use_gebi && document.all)
 	        {
		        x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		        y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		    }
	    else if(use_gebi)
	        {
		        var o=document.getElementById(anchorname);
		        x=AnchorPosition_getPageOffsetLeft(o);
		        y=AnchorPosition_getPageOffsetTop(o);
		    }
 	    else if(use_css)
 	        {
	            x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		        y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		    }
	    else if(use_layers)
	        {
		        var found=0;
		        for(var i=0; i<document.anchors.length; i++)
		            {
			            if(document.anchors[i].name==anchorname) { found=1; break; }
			        }
		        
		        if(found==0)
		            {
			            coordinates.x=0; coordinates.y=0; return coordinates;
			        }

		        x = document.anchors[i].x;
		        y = document.anchors[i].y;
		    }
	    else
	        {
		        coordinates.x=0; coordinates.y=0; return coordinates;
		    }
    		
        coordinates.x=x;
        coordinates.y=y;
    	
	    return coordinates;
    }

function ShowMenu(id, anchor)
    {
        /* store new menu */
        menu = id;
        
        /* show new menu */
        if(document.getElementById)
            {
                obj = document.getElementById(id);
                
                /* set position from anchor */
                pos = getAnchorPosition(anchor);
                obj.style.top = (pos.y + 12) + "px";
                obj.style.left = (pos.x - 1) + "px";
                obj.style.width = "106px";

                /* display menu */
                if(obj.style.display == "none") new Effect.BlindDown(id, { duration: 0.5 });
            }
    }

function HideMenu()
    {
        /* hide new menu */
        if(document.getElementById)
            {
                if(menu != '')
                    {
                        obj = document.getElementById(menu);
                        if(obj.style.display == "") new Effect.BlindUp(menu, { duration: 0.5 });
                    }
            }
        
        /* reset menu */
        menu = '';
	}

/* world map */
function ShowAddress(id)
    {
        Lightbox.showBoxByID(id, 250, 180);
    }

/* global functions */
function Pointer(id)
    {
        id.style.cursor = 'Pointer';
    }
    
function MouseOver(id, colour)
    {
		id.style.color = colour;
        id.style.cursor = 'Pointer';
    }

function MouseOut(id, colour)
    {
        id.style.color = colour;
    }
    
function ShowHide(id)
    {
        if(document.getElementById)
            {
                obj = document.getElementById(id);

                if(obj.style.display == "none")
                    obj.style.display = "";
                else
                    obj.style.display = "none";
            }
    }
    
function SwapMap(state)
    {
        if(document.getElementById)
            {
                obj = document.getElementById('worldmap');
                
                if(state == 1)
                    obj.src = 'images/logo_maphover.png';
                else
                    obj.src = 'images/logo_map.png';
            }
    }