// == FOLDER STRUCTURE ==
var folder = {
    JS: '/templates/',
    XML: '/templates/',
    FLASH: 'http://media.tribunemediaservices.com/designvideo/',
    IMAGES: 'http://media.tribunemediaservices.com/designimages/'
};

// ========== Toggle Tab Items ================================================================================================
var Tabs = new Class({
    Implements: [Events, Options],
    options: {        //
    },
    initialize: function(tabs, options){
        this.currentSlide = -1;
        this.tabBtns = $$(tabs + ' .tabs li');
        this.tabItems = $$(tabs + ' .tabitem');
        this.create();
    },
    create: function(){
        this.tabBtns.each(function(tab, index){
            tab.addEvent('click', function(event){
                event.stop();
                this.activate(index);
            }
.bind(this));
        }
.bind(this));
        if (this.currentSlide == -1) {
            this.activate(0);
        };
            },
    activate: function(tabIndex){
        if (tabIndex == this.currentSlide) 
            return;
        if (this.currentSlide > -1) {
            this.tabBtns[this.currentSlide].removeClass('selected');
            this.tabItems[this.currentSlide].addClass('hide');
        };
        this.tabBtns[tabIndex].addClass('selected');
        this.tabItems[tabIndex].removeClass('hide');
        this.currentSlide = tabIndex;
    }
});


window.addEvent('domready', function(){
    if (!$E('.tabgroup')) 
        return;
    var tabs = new Tabs('.tabgroup');
    $$('.mapList a').each(function(locale, index){
        locale.addEvent('click', function(e){
            new Event(e).stop();
            tabs.activate(1);
            if (!$defined(map)) 
                loadMap();
            (function(){
                var point = this.getProperty('rel').replace(/[geocode:](.*?)/gi, '$1').split(",");
                map.addLocation(point[1], point[0]);
                map.setActiveMarker(this);
                $E('select.dropdown').options[index].selected = true;
                $E('div.location').set('html', this.get('html'));
            }
.bind(this)).delay(100);
        });
    });
    $E('select.dropdown').addEvent('change', function(e){
        map.clearDirections();
        var point = $$('.mapList a')[this.selectedIndex].getProperty('rel').replace(/[geocode:](.*?)/gi, '$1').split(",");
        map.setActiveMarker($$('.mapList a')[this.selectedIndex]);
        map.addLocation(point[1], point[0]);
        $E('div.location').set('html', $$('.mapList a')[this.selectedIndex].get('html'));
    });
    $$('.tabs li')[1].addEvent('click', function(e){
        if (!$defined(map)) {
            (function(){
                loadMap();
                var point = $$('.mapList a')[0].getProperty('rel').replace(/[geocode:](.*?)/gi, '$1').split(",");
                map.setActiveMarker($$('.mapList a')[0]);
                map.addLocation(point[1], point[0]);
                $E('div.location').set('html', $$('.mapList a')[0].get('html'));
            }).delay(100)
        };
            });
});

// ============================================================================================================================
function $E(selector, filter){
    return ($(filter) || document).getElement(selector);
};

