var hlColor   = '#F2E40A';
var unhlColor = '#fff';
var imageFolder = 'images/';

var catsBinary = $H({
    'lighting'  : 1 << 0,
    'bollards'  : 1 << 1,
    'litterbins': 1 << 2,
    'seating'   : 1 << 3,
    'signage'   : 1 << 4,
    'cycle'     : 1 << 5,
    'shelters'  : 1 << 6,
    'other'     : 1 << 7
});

var highlighted = $H({
    'lighting'  : true,
    'bollards'  : true,
    'litterbins': true,
    'seating'   : true,
    'signage'   : true,
    'cycle'     : true,
    'shelters'  : true,
    'other'     : true
});

var rowsCats = $H();

function init() {
    $$('#projects_list div').each(function(element) {
        var catValue = 0;
        element.classNames().each(function(className) {
            if(catsBinary[className]) {
                catValue |= catsBinary[className];
            }
        });
        rowsCats[element.id] = catValue;
    });
}

function toggleCat(catName) {
    var image    = $('head_'  + catName);
    var checkbox = $('check_' + catName);
    
    var hl = highlighted[catName];
    if(hl) {
        image.src = imageFolder + catName + '_p.gif';
        checkbox.checked = false;
    } else {
        image.src = imageFolder + catName + '_a.gif';
        checkbox.checked = true;
    }
    highlighted[catName] = !hl;
    
    var catValue = 255;
    highlighted.keys().each(function(cat) {
        if(!highlighted[cat]) {
            catValue ^= catsBinary[cat];
        }
    });
    
    var effects = new Array();
    var effectsStr = '';
    $$('#projects_list div').each(function(element) {
        //if((catValue & rowsCats[element.id]) != rowsCats[element.id]) { // Alle Zeilen mit gewählter Kategorie
        if((catValue & rowsCats[element.id]) == 0) { // nur diejenigen Zeilen, die nicht noch andere Kategorien beinhalten
            if(element.visible()) {
                //effects.push(new Effect.BlindUp(element, {duration:0.5}));
                effectsStr += 'new Effect.BlindUp("' + element.id + '", {duration:0.5}),'
            }
            
        } else {
            if(!element.visible()) {
                //effects.push(new Effect.BlindDown(element, {duration:0.5}));
                effectsStr += 'new Effect.BlindDown("' + element.id + '", {duration:0.5}),'
            }
        }
    });
    
    effectsStr = '[' + effectsStr.substr(0, effectsStr.length - 1) + ']';
    //alert(effectsStr);return;

    new Effect.Parallel(eval(effectsStr), {
        afterFinish: function() {
            // In geklickter Kategorie Punkte ein-/ausblenden
            var toggledCatValue = catsBinary[catName];
            $$('span.cat_'+toggledCatValue).each(function(element) {
                if(highlighted[catName]) {
                    new Effect.Opacity(element, { duration: 0.5, from: 0, to: 1});
                } else {
                    new Effect.Opacity(element, { duration: 0.5, from:1, to: 0});
                }
            });
        }
    });
    
    /* */
}

function hlrow(id, do_highlight) {
    
	var color = (do_highlight) ? hlColor : unhlColor;

    $$('#prj_'+id+' span').each(function(element) {
        element.setStyle({color: color})
    });
}