App = {};

App.Start = {

    elSrc: [],
    swapDisabledFor: null,
    colorScheme: {
        def: '#333333',
        brands: '#ff6666',
        film: '#66cccc',
        other: '#cdcc32'
    },
    language: 'en',
    section: 'start',

    init: function()
    {
        this.imagePath = '/gfx/';
        App.Start.deployListener();
        App.Start.activateOverlay();
    },

    activateOverlay: function()
    {
        $("div.header div.box img").css('display', 'block');
    },

    deployListener: function()
    {
        var $el = $("div.header div.box img");
        var elId = $(this).get(0);

        $el.mouseover(function() {

                
            App.Start.elSrc[elId] = $(this).attr('src');
            $(this).attr('src', $(this).parent().attr('hover'));
        
        }).mouseout(function() {

            if ($(this).parent().attr('id') != App.Start.swapDisabledFor) {
                
                $(this).attr('src', App.Start.elSrc[elId]);
            }
        });

        $el.click(function() {

            App.Start.resetButtons($(this).parent().attr('id'));

            var color = $(this).parent().attr('rel');
            var id = $(this).parent().attr('id');
            
            App.Start.swapDisabledFor = id;
            
            $("BODY").animate({backgroundColor:color}, 150);
            App.Start.toggleColor(App.Start.colorScheme[id]);
            App.Start.toggleContent(id);
        });

    },

    resetButtons: function(id)
    {
        $("div.header div.box img").each(function() {

            if ($(this).parent().attr('id') != id) {
                
                $(this).attr('src', $(this).parent().attr('default'));
            }
        });

        App.Start.swapDisabledFor = null;
    },

    toggleColor: function(color)
    {
        $("div.content").animate({backgroundColor:color}, 150);
    },

    toggleContent: function(target)
    {
        if (target == "start") {
            $(".content, .language").fadeOut("slow");
        } else if ($(".content:hidden")) {
            $(".content, .language").fadeIn("slow");
        }
        
        if (target != 'brands' &&
            target != 'film' &&
            target != 'other') {
            
            $("BODY").animate({backgroundColor:'#333333'}, 150);
            App.Start.toggleColor(App.Start.colorScheme["def"]);
            App.Start.resetButtons();
        }

        this.section = target;

        this.getContent(App.Start.language, target);
    },

    getContent: function(lang, target)
    {
        $.ajax({
            url: 'texts/' + lang + '_' + target + '.html',
            success: function(data) {
                $("div.content").html(data);

                if (target != 'brands' && target != 'film' && target != 'other') {
                    target = 'def';
                }
                $("div.content .headline").css('color', App.Start.colorScheme[target]);
            }
        });
    },

    toggleLanguage: function(lang)
    {
        this.getContent(lang, this.section);
        this.language = lang;
    }
};


