var srch = {
    e: null,
    on: false,
    html: ''
}
window.addEvent('domready',function() {
    if($('secnote')){
        $('secnote').setStyle('display','block');
        $('secnotefull').slide('hide');
    }


    if($('nrw')) $('nrw').setStyle('display','none');
    
    
    /*var ilCount = $$('.iconlink').length;
    
    if(ilCount > 1){
        var il = $$('.iconlink');
        il.each(function(e,i){

            var cn = e.className.replace('iconlink ','');                
            e.store('initialClass',cn);
            e.store('activeClass',cn+'-aktiv');
            e.store('state','inaktiv');
            
            toggleIconlink.delay(200+100*i,e,e);
            toggleIconlink.delay(200+100*(i+1),e,e);

            toggleIconlink.delay(200 + ilCount*100 + 100*(ilCount-i),e,e);
            toggleIconlink.delay(200 + ilCount*100 + 100*((ilCount-i)+1),e,e);
        })
    }*/
    
    $$('.iomo_sitemap tr').each(function(e,i){
        var td = e.getChildren('td');
        var co = e.className.replace('goto','');
        var col = new Color('#'+co).mix('#fff',95);
        
        
        td.addEvents({
            'mouseover': function(){
                var x = this.getParent('tr').getChildren('td');
                x.setStyle('background-color',col);
                x[0].getElement('img').setProperty('src','/fileadmin/iom/button'+co+'a.gif');
            },
            'mouseout': function(){
                var x = this.getParent('tr').getChildren('td');
                x.setStyle('background-color','white');
                x[0].getElement('img').setProperty('src','/fileadmin/iom/button'+co+'.gif');
            }
        });
    });
    if($('nach_tg')){
        ortsSeite('zg');
        $('orteJump').setStyle('display','block');
    }
    $$('a').addEvent('focus',function(){ this.blur(); })
    
    
    if(window.location.href == 'http://iom.testfactor.de/index.php?id=289'){
        srch.e = $$('#srch input.input');
        if(srch.e.length==1){
            srch.e = srch.e[0];
            srch.form = srch.e.getParent('form');
            srch.e.addEvent('mouseover',function(e){ srch.on = true; });
            srch.e.addEvent('mouseout', function(e){ srch.on = false; srch.kill() });
            srch.e.addEvent('blur',     function(e){ srch.on = false; srch.kill() });
    
            srch.e.addEvent('click',function(e){
                if(!srch.list){
                    srch.list = new Element('div',{
                        styles: {
                            left: srch.e.getPosition().x,
                            top: srch.e.getPosition().y+20
                        },
                        id: 'suchbox',
                        events: {
                            'mouseleave':  function(e){ srch.on = false; srch.kill() },
                            'mouseenter': function(e){srch.on = true; }
                        },
                        html: '<small>Lade...</small>'
                    });
                    srch.list.inject(srch.e,'after');
                }
                
                srch.ajax = new Request.JSON({
                    url: '/fileadmin/global/nfms.ajax.php',
                    onSuccess: function(json,txt){
                        srch.html = '<div class="titel">Interessante Suchen:</div>';
                        json.each(function(e){
                            srch.html += '<a href="#" onClick="srch.e.value=\''+e+'\'; srch.form.submit(); return false;">'+e+'</a>';
                        });
                        srch.list.set('html',srch.html);

                        srch.list.fade('hide');
                        srch.list.fade('in');
                    }
                }).get();
            });
            
            srch.kill = function(e){
                if(e==1 && srch.on==false){
                    this.fade('out');
                } else {
                    srch.kill.delay(1000,srch.list,1);
                }
                
            }
        }
    }
});
function toggleIconlink(e){
    if(e.retrieve('state')=='inaktiv'){
        e.addClass(e.retrieve('activeClass'));
        e.removeClass(e.retrieve('initialClass'));
        e.store('state','aktiv');
    } else if(e.retrieve('state')=='aktiv'){
        e.removeClass(e.retrieve('activeClass'));
        e.addClass(e.retrieve('initialClass'));
        e.store('state','inaktiv');
    }
}
function showSecNote(){
    $('secnotefull').slide('toggle');
   // $('secnote').slide('toggle');
    return false;
}
function ortsSeite(t){
    if(t=='zg' || t=='tg'){
        var neu = $('nach_'+t);
        var alt = $('nach_'+(t=='tg'?'zg':'tg'));

        var neuB = $('btn_'+t);
        var altB = $('btn_'+(t=='tg'?'zg':'tg'));
        
        alt.setStyle('display','none');
        neu.setStyle('display','block');
        
        neuB.addClass('aktiv');
        altB.removeClass('aktiv');
    }
}

var allowHide = false;
function enterNRW(){
    allowHide = false;
    document.getElementById('nrw').style.display = 'block';
    document.getElementById('layer').style.display = 'block';
    
}
function leaveNRW(){
    allowHide = true;
    window.setTimeout("hideNRW()", 150);
}

function hideNRW(){
    if(allowHide){
        document.getElementById('nrw').style.display = 'none';
        document.getElementById('layer').style.display = 'none';
    }
}


function iom_anmeldung(){
    var o = $$('#content div.pdb_typ1 p.orte span')
    if(o.length == 1){
        var e = o.pop();
        var did = e.getProperty('class').split('-').pop();
        var go = 'http://www.fom.de/anmeldung.php?id='+did;
        go.toURI().go();
    } else if(o.length > 0){
        if(!$('anmeldung-box')){
            var c = new Element('div',{
                'text': 'Anmeldung für:',
                'class': 'anmeldung-download',
                'id': 'anmeldung-box',
                'styles': {
                    'background-color': '#DCE2E1',
                    'padding': '0px 10px 5px 10px',
                    'font-weight': 'bold'
                }
            });
            
            o.each(function(e,i){
                var ort = e.get('text');
                var did = e.getProperty('class').split('-').pop();
                
                new Element('a',{
                    text: ort,
                    href: 'http://www.fom.de/anmeldung.php?id='+did,
                    events: {
                        'focus': function(){ this.blur(); }
                    }
                }).inject(c);
            })
            
            var parent = $$('#right .download')[0];
            c.inject(parent,'after');
        }
    }
    return false;
}