com.portsofindiana.Main = new Class
({
    initialize: function ()
    {
        this.global();
        $$('body').getProperty('class').each( function (item)
        {
            if (this[item]) this[item]();
        }.bind(this));
    },

    global: function ()
    {
        new com.portsofindiana.MapLinks($$('a.openmap'));
        swfobject.embedSWF('/maps/indianamap2.swf', 'indianamap', "397", "250" , "8.0.0", false, {}, {}, {});
        swfobject.embedSWF('/maps/POIflashmapad3.swf', 'flashmapad', "180", "350" , "8.0.0", false, {}, {}, {});
    },

    maps: function ()
    {
        new com.portsofindiana.Map();
    }
})

com.portsofindiana.MapLinks = new Class
({
    initialize: function (elms)
    {
        this.maps = new Hash(
        {
            '#burns_harbor': '0',
            '#mount_vernon': '1',
            '#jeffersonville': '2'
        });

        elms.addEvent('click', this.clickHandler.bindWithEvent(this));
    },

    clickHandler: function (event)
    {
        var target = $(event.target);

        if (target.get('tag') != 'a')
        {
            var target = target.getParent('a');
        }

        var href = target.get('href');
        var map = this.maps.get(href);
        new com.portsofindiana.OpenMap(map);

        event.stop();
    }
})

com.portsofindiana.OpenMap = new Class
({
    initialize: function (map)
    {
        var url = '/maps/flashmap.html?map=' + map;

        new Browser.Popup
        (
            url,
            {
                x: 'center',
                y: 'center',
                width: 760,
                height: 500,
                toolbar: 0,
                location: 0,
                status: 0,
                scrollbars: 'no',
                name: 'maps'
            }
        );
    }
})

com.portsofindiana.Map = new Class
({
    Implements: Options,
    options:
    {
        swf_path: '/flash/portmaps.swf',
        replace: 'flashcontent'
    },
    initialize: function (options)
    {
        this.setOptions(options);

        window.focus();

        this.embedMap();
    },

    embedMap: function ()
    {
        var uri = new URI();
        var map = uri.get('data').map;

        var flashvars =
        {
            selectedMap: map
        };

        var params =
        {
            menu: false,
            allowScriptAccess: 'sameDomain',
            allowfullscreen: true
        };

        var attributes =
        {
            bgcolor: '#0B1422'
        };

        swfobject.embedSWF(this.options.swf_path, this.options.replace, "100%", "100%" , "8.0.0", false, flashvars, params, attributes);
    }
})
