
/* :::::::::: IndexController :::::::::::::: */
var IndexController = Class.create();
IndexController.prototype =
{
    initialize: function()
    {
        this.categories = new Array(); //new Array('news', 'video', 'organisation', 'photos', 'misc', 'activities');
        this.subs = new Array('active', 'nactive', 'img');

        /*
            news:  [main], active, nactive, img
            video: [main], active, nactive, img
            organisation: [main], active, nactive, img, img2
            photos: [main], active, nactive, img
            misc: [main], active, nactive, img, img2
            activities: [main], active, nactive, img, img2
        */
        this.imagesPath = "img/";

        this.preloadImages();
        var thisCopy = this;

        this.mains = $$('div[id$=-main]');
        this.mains.each(function (el)
        {
            var catname = el.id.slice(0,-5);
            thisCopy.categories[thisCopy.categories.length] = catname;

            el.observe('mouseover', function(event) {
                thisCopy.onCategoryOver( catname );
            });

            el.observe('mouseout', function(event) {
                thisCopy.returnCategories( catname );
            });
        });
    },

    onCategoryOver: function( category )
    {
        this.categories.each( function(c)
        {
            if(c!=category && c!='logo')
                this.toggleCategorySubs(c, false, 'organisation,misc,activities'.include(c) );

        }.bind(this));

        this.toggleCategorySubs(category, true, 'organisation,misc,activities'.include(category) );

    },

    returnCategories: function( category )
    {
        //return categories, excluding CATEGORY
        this.categories.without(category).each( function(c)
        {
            var els = $$('div[id^='+c+']');
            els.each( function(el)
            {
                if( el.id.include('-main') || el.id.include('-nactive') ) el.show();
                else el.hide();
            });

            if(c=='misc')
            {
               $(c+'-img').show();
            }
            
            if(c=='activities')
            {
               $(c+'-img3').show();
            }
        }.bind(this));

        //return CATEGORY
        var els = $$('div[id^='+category+']');
        els.each( function(el)
        {
            if( el.id.include('-main') || el.id.include('-nactive') ) el.show();
            else el.hide();
        });

        if(category=='misc')
        {
           $(category+'-img').show();
                   $(category+'-img2').hide();
        }

        if(category=='activities')
        {
           $(category+'-img3').show();
        }
    },

    toggleCategorySubs: function( category, show, hasIMG2 )
    {
        var els = $$('div[id^='+category+']');
        els.each( function(el)
        {                                   
            if(!show) el.hide();
            else      el.show();
        });

        $(category+'-nactive').hide();

        if(category=='misc')
        {
           $(category+'-img').hide();
           $(category+'-img2').show();
        }

        if(category=='activities')
        {
           $(category+'-img3').hide();
        }
    },

 preloadImages: function () {
     preloads = new Object();
     preloads[0] = new Image(); preloads[0].src = this.imagesPath + "i_news_a.gif";
     preloads[2] = new Image(); preloads[2].src = this.imagesPath + "i_organisation_a.gif";
     preloads[3] = new Image(); preloads[3].src = this.imagesPath + "i_photos_a.gif";
     preloads[4] = new Image(); preloads[4].src = this.imagesPath + "i_misc_a.gif";
     preloads[5] = new Image(); preloads[5].src = this.imagesPath + "i_activities_a.gif";

     preloads[6] = new Image(); preloads[6].src = this.imagesPath + "i_news_aimg.gif";
     preloads[7] = new Image(); preloads[7].src = this.imagesPath + "i_misc_abg.gif";
     preloads[8] = new Image(); preloads[8].src = this.imagesPath + "i_video_abg.gif";
     preloads[9] = new Image(); preloads[9].src = this.imagesPath + "i_photos_abg.gif";
     preloads[10] = new Image(); preloads[10].src = this.imagesPath + "i_activities_bg_right.gif";
     preloads[11] = new Image(); preloads[11].src = this.imagesPath + "i_activities_bg_left.gif";
     preloads[12] = new Image(); preloads[12].src = this.imagesPath + "i_activities_bg.gif";
    }
}

var ic = null;
function initIndexController ( column )
{
    ic = new IndexController();
}


