var imgFolder = 'fileadmin/templates/fom/img';
var BROWSER, theTabs;
var nf = $H();



function tesfn(){
    alert('test');
    var e = $('c2757');
    alert(JSON.encode(e.getPosition()));
}

var hhcall=0;
var hhLast = 0;
function hh(t){
    return;
    var z = new Date().format('%s %L').split(' ');
    var tt = z[0].toInt()*1000+z[1].toInt();
    var took = tt-hhLast;
    hhLast = tt;

    var c = $('c7104');
    if(!c) return;
    if(hhcall++==0) c.empty();
    if(!t) t = 'Call '+hhcall;

    c.innerHTML += '+'+took+'ms / '+t+'<br />';
}

function calOpt(ortid) {
    if(ortid) {
        $$('.vcal .termin').setStyle('display','none');
        $$('.vcal .ort' + ortid).setStyle('display', 'block');
    } else {
        $$('.vcal .termin').setStyle('display','block');
    }
    return false;
}

var lmask;
function betterPosition(el, offset) {
    el.position();
    var pos = el.getPosition();
    if(pos.y < offset) el.setStyle('top', parseInt(el.getStyle('top')) - pos.y + offset);
}

window.addEvent('domready',function(){

    var video_frames = new Elements();
    $$('div.video-frame').each(function(vf) {
        video_frames.push(vf);
        if(vf.hasClass('last-video-frame')) {
            var maxH = 0;
            video_frames.each(function(vf1) {
                maxH = Math.max(maxH, vf1.getElement('div.video-title').getSize().y);
            });
            video_frames.each(function(vf1) {
                vf1.getElement('div.video-title').setStyle('height', maxH + 'px');
            });
            video_frames.empty();
        }
    });

    if($('semesterlayer')) {
        lmask = new Mask();
        var h4s = new Elements();
        var sc = new Fx.SmoothScroll();

        var seml = $('semesterlayer');

        itemscount = seml.getChildren('h5').length;
        seml.getChildren('h5').each(function(h4el) {

            if(h4el.getNext('.sem_accord')) {
                h4el.getNext('.sem_accord').slide('hide');

                h4el.addEvent('click', function() {
                    h4el.getNext('div .sem_accord').slide('toggle');
                });

                h4el.getNext('div .sem_accord').set('slide', {
                    onComplete: function() {
                         sc.toElement(h4el);
                    }
                });

                h4s.push(h4el);
            }

        });

        seml.setStyle('display','block');
        seml.hide();

        $$('a.open_semesterlayer').addEvent('click', function() {
            $('semesterlayer').show();
            betterPosition(seml, 20);
            if(h4s.length == 1) {
                h4s[0].getNext('div .sem_accord').slide('show');
                sc.toElement(h4s[0]);
            }
            lmask.show();
            return false;
        });

        $('semlayercloser').addEvent('click', function() {
            seml.hide();
            lmask.hide();
        });

        betterPosition(seml, 20);
    }
    //j5

    //Up und Down zum gleichen Zeit zeigt im untersten ToTop die SeitenID an
    window.addEvent('keydown:keys(alt+i)', function(){
        $$('#content_area .totop a').getLast().set('html', $(document.body).getProperty('id').substr(5) +' | Top');
        mySmoothScroll.toBottom();
    });
    //j6

    terminboxcount = 0;
    $$('.tx-nfmvteaser-pi1').each(function(termincont) {
        terminboxcount++;
        termincont.addClass('terminbox-'+terminboxcount);
        termine = termincont.getElements('div.termin');
        var counttermine = 0;
        termine.each(function(termin) {
            counttermine++;
            termin.addClass('termin-' + counttermine);

            termin.addEvent('mouseenter', function() {
                termin.addClass("no-scroll");
            });
            termin.addEvent('mouseleave', function() {
                termin.removeClass("no-scroll");
            });
        });
        termincont.store('terminecount', counttermine);
        termincont.store('acttermin', 0);
    });
    //j7

    window.setInterval(function() {
        $$('.tx-nfmvteaser-pi1').each(function(termincont) {
            actt = termincont.retrieve('acttermin');
            maxt = termincont.retrieve('terminecount');
            nextt = actt + 1;
            if((nextt + 1) > maxt) nextt = 0;

            actel  = termincont.getElements('div.inline-scroller div.termin-' + (actt +1))[0];
            nextel = termincont.getElements('div.inline-scroller div.termin-' + (nextt +1))[0];

            if(actel) scroller = actel.getParent('div.inline-scroller');
            else return;

            if(actel && !actel.hasClass('no-scroll') && maxt > 1) {

                if(nextel) nextel.inject(actel, 'after');
                scroller.setStyle('margin-left', '0px');
                new Fx.Tween(scroller, {
                    duration: 'long',
                    onComplete: function() {
                        firstel  = termincont.getElements('div.inline-scroller div.termin')[0];
                        myscroll = firstel.getParent('div.inline-scroller');
                        firstel.inject(myscroll, 'bottom');
                        myscroll.setStyle('margin-left', '0px');
                    }
                }).start('margin-left', 0, -198);
                termincont.store('acttermin', nextt);
            }
        });
    }, 7500);
    //j8


    $$('.jsOnly').removeClass('jsOnly');
    //Initiate Browser-Specific configuration
    BROWSER = new nf.browser();
    //j9

    //Sitemap einklappen
    var pureTabSubpages = $$('ul.dt-102');
    pureTabSubpages.each(function(tabul) {
        tabul.slide('hide');
        var parentLi = tabul.getParent('li');
        parentLi.toggleClass('tabsclosed');
        parentLi.addEvent('click', function() {
            tabul.slide('toggle');
            parentLi.toggleClass('tabsclosed');
        });
    });
    //j10

    var pureTabLis = $$('li.lidt-102');
    pureTabLis.each(function(tabli) {
        uls = tabli.getChildren('ul');
        if(uls.length > 0) {
            uls.each(function(ul) {
                ul.slide('hide');
                tabli.toggleClass('tabsclosed');
                tabli.addEvent('click', function() {
                    ul.slide('toggle');
                    tabli.toggleClass('tabsclosed');
                });
            });
        }
    });
    //j11


    //Löscht Tabs, die ausgeblendet sein sollen
    document.id('content').getElements('*.empty_tab ! div.tabbed').dispose();
    //j12

    //Initiate Paging
    new nf.paging();
    //j13

    //Initiate Tabbing
    var tabbed = document.id('content').getElements('div.tabbed');
    if(tabbed.length > 0){
        BROWSER.addHash('tab',{clearOnChange: 'page'});
        theTabs = new nf.tab(tabbed);
    }
    //j14
    hh('Tabbing Before');
    var tabbed = document.id('content').getElements('div.dTabbed');
    if(tabbed.length > 0){
        BROWSER.addHash('dtab',{clearOnChange: 'page'});
        var zm = new nf.tab(tabbed, {
            'hideTitleElement': 'h2',
            'tabberClass': 'tabber directTabber',
            'ignoreHash': true
        });
        if(window.location.hash.substr(0,4)=='#zm-'){
            zm.activate(window.location.hash.substr(4))
        }

    }
    hh('Tabbing After');

    //Recreate Multiple Radio Boxes to DropDown
    var selects = document.id('content').getElements('.nf-asSelect');
    selects.each(function(s){
        var form = s.getParent('form')

        var op = s.getElements('input[type=radio]');
        var name = op[0].get('name');
        var rest;

        var p = new Element('select',{
            name: name,
            id: 'transformed-'+name,
            size: 1,
            'events': {
                'change': function(){
                    if(rest.length > 0){
                        rest.each(function(e){
                            if(e.checked){
                                e.setProperty('checked', false);
                                e.fireEvent('unckeck');
                            }
                        })
                    }
                    form.submit();
                }
            }
        });

        var titel = s.getElement('.firstOption');
        var addToSelectedIndex = 0;
        var selectedIndex = 0;
        if(titel){
            new Element('option',{
                'value': 'none',
                'html': titel.get('text')
            }).inject(p);
            addToSelectedIndex = 1;
        }

        op.each(function(o,i){
            new Element('option',{
                'value': o.get('value'),
                'html': o.getNext('label').get('text'),
                'id': o.get('id')
            }).inject(p);
            if(o.checked) selectedIndex = i+addToSelectedIndex;
        }).setStyle('display', 'none');
        p.replaces(s);
        p.selectedIndex = selectedIndex;

        rest = document.id('content').getElements('input[name='+name+']');
        rest.each(function(e){
            e.addEvent('click', function(){
                p.selectedIndex = 0;
            })
        })
    })
    //j16

    checkbox2image(document.id('content'));
    radio2image(document.id('content'));
    //j17



    //Placeholder
    /*
    document.getElements('input[placeholder], textarea[placeholder]').each(function(e){
        if(Form.Placeholder){
            var x = new Form.Placeholder(e.get('id'));
        }
    });
    document.id('content').getElements('select[placeholder]').each(function(e){
        e.addEvent('change', checkForPH.bind(null,e));
        e.addEvent('blur', checkForPH.bind(null,e));
        e.addEvent('focus', function(){
            e.setStyle('color','#000');
        });
        checkForPH(e);
    });
    */


    //Hover for Labels
    hh('Label Hover Before');
    document.id('content').getElements('label.hl').each(function(l){
        var f = l.get('for');
        var fld = document.id(f);
        l.addEvents({
            mouseover: fld.addClass.bind(fld,'labelHovered'),
            mouseout: fld.removeClass.bind(fld,'labelHovered')
        })

    })
    hh('Label Hover After');

    //Fixing (CSS3)
    var h2 = document.id('content').getElement('h2');
    if(h2) h2.addClass('first-child');

    var aktuell = document.id('content').getElements('.aktuell-663');
    if(aktuell.length > 0){
        aktuell.getLast().addClass('aktuell-663-last');
    }
    //j19


    //Closed Slides erstellen:

    document.id('right_content').getElements('.slide-closed')
        .removeClass('slide-closed')
        .slide('hide');
    //j20

    var akk = document.id('right_content').getElements('.csc-default.nf-akkordeon');
    //var akk = [];
    akk.each(function(a,i){
        var h;
        if(h = a.getElement('h5')){

            h.store('nf-akkordeon','open');

            var height = h.getSize().y;
            if(akk.length-1 == i){
                height += 7;
            }

            a.store('height-open',a.getSize().y);
            a.store('height-close',height);

            h.addEvents({
                'click': function(){
                    if(h.retrieve('nf-akkordeon')=='open'){
                        h.set('html', h.get('html')+' »');
                        if(h.get('html').substr(-1))
                        a.tween('height',a.retrieve('height-close'));
                        h.store('nf-akkordeon','close');
                        a.addClass('nf-akkordeon-zu').removeClass('nf-akkordeon-offen');
                    } else {
                        a.addClass('nf-akkordeon-offen').removeClass('nf-akkordeon-zu');
                        if(h.get('html').substr(-2) == ' »'){
                            h.set('html',h.get('html').sub_str(0,-2));
                        }
                        a.tween('height',a.retrieve('height-open'));
                        h.store('nf-akkordeon','open');
                    }
                },
                'mouseover': h.addClass.bind(h,'nf-akkordeon-hover'),
                'mouseout': h.removeClass.bind(h,'nf-akkordeon-hover')
            });
            /*
            Anpassung Gierke/Schaumann für Braun Präsi
            if(!a.hasClass('nf-akkordeon-offen')){
                a.setStyle('height',height);
                h.set('html', h.get('html')+' »');
                h.store('nf-akkordeon','close');
                a.addClass('nf-akkordeon-zu');
            }
            */
        }

    })
    //j21

    if(Browser.ie && !Browser.ie9 && !Browser.ie10){
        //Kein TopTop in Smooth für den IE <= 8
    } else {
        var mySmoothScroll = new Fx.SmoothScroll(document.id('content').getElement('div.totop'));
        document.id('content').getElements('div.totop a').each(function(e){
            e.addEvent('click', function(){
                mySmoothScroll.toTop();
                return false;
            });
        });
    }

    (function($){
        var text_closeWindow = 'Fenster schließen';
        var text_studyProgrammes = 'Studiengänge';
        var text_startpage = 'Startseite';
        var text_tm_evening_weekend = 'Abend- und Wochenendstudium';
        var text_tm_block = 'Blockmodell';
        var text_tm_daystudy = 'Tages-Studium';

        var par = $('c11357');
        if(!par) par = $('c11366');
        if(!par) {
            par = $('c13803');
            if(par) {
                text_closeWindow = 'Close window';
                text_studyProgrammes = 'Study Programmes';
                text_startpage = 'Startpage';
                text_tm_evening_weekend = 'Evening- and weekend study';
                text_tm_block = 'Block model';
                text_tm_daystudy = 'Daytime-study';
            }
        }
        if(!par) return;


        //IE8 auf schwacher Hardware macht hier Probleme. Ergo: ausblenden.
        if(Browser.ie && !Browser.ie9 && !Browser.ie10){
            par.getElement('.csc-textpic-single-image').destroy();
            return;
        }

        var e = $('table-zm-prod');
        if(!e) return;
        var parent = new Element('div.table-parent').inject(e,'after').setStyle('display', 'none'); //.setStyle('border-bottom','5px solid red');
        var M = new Mask($(document.body), {
            hideOnClick: true,
            onHide: function(){
                parent.setStyle('display', 'none');
            }
        });



        (function(){
            var p = new Element('h2.first-child').inject(parent);
            new Element('a[html=&raquo; ' + text_closeWindow + '][href=#]',{events: {'click': function(evt){ evt.stop(); M.hide(); }}}).inject(p);
            new Element('span[text=' + text_studyProgrammes + ']').inject(p);
        })();


        e.inject(parent);

        var p2 = new Element('div.footage').inject(parent);
        new Element('a.gohome[href=/][text=» FOM ' + text_startpage + ']').inject(p2);
        new Element('span.desc.desc-orange[text=» ' + text_tm_daystudy + '«]').inject(p2);
        new Element('span.desc.desc-blau[text=» ' + text_tm_evening_weekend + '«]').inject(p2);
        new Element('span.desc.desc-rot[text=» ' + text_tm_block + '«]').inject(p2);

        var img = par.getElements('img').pop();
        img.setStyles({
            'cursor': 'pointer'
        });
        img.addEvents({
            'click': function(){

                var yy = 0100;
                M.show();
                parent.setStyles({
                    'display': 'block',
                    'z-index': 9000
                }).position({
                    allowNegative: true
                });

            }
        });
    })(document.id);
    //j23


    //Initiate nfGalery
    nfGal();
    nfGal2();
    //j24

    //OrteMap
    hh('Map Before');
    nfMap();
    hh('Map After');

    //Akkordeons
    hh('ACC Before');
    nfAcc();
    hh('ACC After');

    nfCRM();
    //j27

    nfVideoLayer();
    nfChatButton();
    //j28
    //nfTabLink();

    var nohs = $$('div.no-h');
    nohs.each(function(noh) {
        noh.getElements('h1, h2, h3, h4, h5, h6, h7').setStyle('display','none');
    });

});
function nfChatButton(){
    var $ = document.id;

    var show = $(document.body).hasClass('allowChat');

    if($(document.body).get('id')=='page-1531' && show){
        new Element('img[src=/fileadmin/templates/fom/chat.gif]').inject(new Element('a[href=http://bcwchat.by.nf/chat.php?code=U0VSVkVSUEFHRQ__][target=_blank]').inject($('c18338'), 'top').setStyles({'float': 'right','padding-left': 10}));
    }

    var rcb=$('rightContactBox');
    if(rcb && show){
        var t = rcb.getElement('.studienberatungdirekt');
        new Element('a.morelink.chatbutton[href=http://bcwchat.by.nf/chat.php?code=U0VSVkVSUEFHRQ__][target=_blank][html=<strong>Chat mit der Studienberatung</strong>]').inject(t, 'before');
        //new Element('a.morelink.chatbutton[href=http://bcwchat.by.nf/chat.php?code=U0VSVkVSUEFHRQ__][target=_blank][html=<strong>Chat mit der Studienberatung</strong>]').inject(rcb);
    }
}
/*
function user_match($var='x'){
    $t = intval(date('G'))*60 + intval(date('i'));
    $dow = date('w');
    return (($t >= 630 && $t <= 960) && ($dow > 0 && $dow < 6));
}
*/
function nfTabLink(){
    var target = {};
    theTabs.tabE.length.times(function(i){
        var x = theTabs.tabHeadE[i];
        target[e.get('name2')] = e.get('name');
    })

    //if(console) console.log(theTabs.tabE.length);
    //if(console) console.log(target);

    /*
    $$('a.internal-link[href*=/tab-]').each(function(e){
        var l = e.get('href');
        var t = l.split('/tab-')[1];

    });
    */
}



function nfVideoLayer(){
    $$('img[longdesc]').each(function(img){
        var vidlink = img.get('longdesc');
        if(vidlink.contains('getVideo=')){
            vidlink = new URI(vidlink);
            var vidNum = vidlink.getData('getVideo')-1;



            img.getParent('a').addEvent('click', function(evt){
                evt.stop();

                var win = new Element('div.nfPicView.nfVidView').inject($(document.body),'top');
                var mask = new Mask($(document.body), {
                    hideOnClick: true,
                    onHide: function(){
                        win.hide();
                    }
                }).show();

                var topBar = new Element('div.topBar').inject(win);
                new Element('a.close[text=schließen x][href=#]').inject(topBar).addEvent('click', function(){
                    mask.hide();
                    win.destroy();
                    //win.hide();
                    return false;
                });

                new Element('div#uvld[html=Video lädt...<br />Einen Moment bitte.]').inject(win);
                win.position();


                mlink = new URI(vidlink);
                mquery = mlink.get('query');
                mdir   = mlink.get('directory');
                mfile  = mlink.get('file');
                vidlink = mdir + mfile;

                new Request({
                    url: vidlink,
                    keepScripts: true,
                    onFailure: function(r){ window.location.href = vidlink; },
                    onError: function(r){ window.location.href = vidlink; },
                    onSuccess: function(response){
                		try {
                    		var o = new Element('div').set('html', response);
                    		var html = o.getElements('div.tx-nfmediaplayer-pi1')[vidNum].getElement('script').get('html').trim();
                    		o.destroy();

                    		var file = html.match(/so\.addVariable\(\'file\',\'([\s\S]*?)\'\);/i)[1];
                    		var img = html.match(/so\.addVariable\(\'image\',\'([\s\S]*?)\'\);/i);
                    		var noImg = false;
                    		if(img){
                    		    img = img[1];
                    		    noImg = true;
                    		}

                    		var part = html.substr(10,120).split("'");
                    		var factor = 2;
                    		var s1=part[5]*factor, s2=part[7]*factor;

                       		win.setStyles({
                       		    'width': s1.toInt(),
                       		    'height': s2.toInt()+20
                       		}).position();

                    		if(noImg) {
                        		var toExec =
                        		    "var so = new SWFObject('/typo3conf/ext/nf_media_player/assets/player.swf','ply','"+s1+"','"+s2+"','9','#000000');"+
                        		    "so.addParam('allowfullscreen','true');"+
                        		    "so.addParam('allowscriptaccess','always');"+
                        		    "so.addParam('wmode','opaque');"+
                        		    "so.addParam('flashvars','skin=/typo3conf/ext/nf_media_player/assets/fomskin.zip&autostart=true&file="+ file +"&viral.allowmenu=false&viral.onpause=false&viral.oncomplete=false');"+
                        		    "so.addVariable('controlbar','bottom');"+
                        		    "so.addVariable('backcolor','FFFFFF');"+
                        		    "so.addVariable('frontcolor','000000');"+
                        		    "so.addVariable('lightcolor','000000');"+
                        		    "so.addVariable('screencolor','000000');"+
                        		    "so.addVariable('showdownload','true');"+
                        		    "so.addVariable('link','"+ file +"');"+
                        		    "so.addVariable('viral.allowmenu','false');"+
                        		    "so.addVariable('viral.onpause','false');"+
                        		    "so.addVariable('viral.oncomplete','false');"+
                        		    "so.addVariable('autostart','true');"+
                        		    "so.addVariable('file','"+ file +"');"+
                        		    "so.addVariable('provider','video');"+
                        		    "so.write('uvld');";
                    		} else {
                        		var toExec =
                        		    "var so = new SWFObject('/typo3conf/ext/nf_media_player/assets/player.swf','ply','"+s1+"','"+s2+"','9','#000000');"+
                        		    "so.addParam('allowfullscreen','true');"+
                        		    "so.addParam('allowscriptaccess','always');"+
                        		    "so.addParam('wmode','opaque');"+
                        		    "so.addParam('flashvars','skin=/typo3conf/ext/nf_media_player/assets/fomskin.zip&autostart=true&file="+ file +"&viral.allowmenu=false&viral.onpause=false&viral.oncomplete=false&image="+img+"');"+
                        		    "so.addVariable('controlbar','bottom');"+
                        		    "so.addVariable('backcolor','FFFFFF');"+
                        		    "so.addVariable('frontcolor','000000');"+
                        		    "so.addVariable('lightcolor','000000');"+
                        		    "so.addVariable('screencolor','000000');"+
                        		    "so.addVariable('showdownload','true');"+
                        		    "so.addVariable('link','"+ file +"');"+
                        		    "so.addVariable('viral.allowmenu','false');"+
                        		    "so.addVariable('viral.onpause','false');"+
                        		    "so.addVariable('viral.oncomplete','false');"+
                        		    "so.addVariable('autostart','true');"+
                        		    "so.addVariable('file','"+ file +"');"+
                        		    "so.addVariable('image','"+ img +"');"+
                        		    "so.addVariable('provider','video');"+
                        		    "so.write('uvld');";
                            }

                       		Browser.exec(toExec);
                       	} catch(e){
                       	    window.location.href = vidlink;
                       	}
                   		return false;
                    }
                }).get(mquery);
            });
            return false;
        }
    });
}

function checkbox2image(parent){
    var checkb = parent.getElements('input[type=checkbox]');

    checkb.each(function(r){
        r.addClass('hideInput');

        var name = r.get('name');

        var img = new Element('img', {
            'src': imgFolder + '/cb_'+ (r.get('checked') ? 'true' : 'false') +'.gif',
            'class': 'input imgCb input-'+name+' value_'+r.get('value')+'_',
            'events': {
                'click': function(){
                    var chkd = !r.get('checked');
                    var src = imgFolder + '/cb_'+ (chkd ? 'true' : 'false') +'.gif';

                    r.setProperty('checked',chkd);
                    this.setProperty('src',src).store('gfx',src);
                    return false;
                },
                'mouseover': function(){
                    this.store('gfx',this.getProperty('src'))
                    this.setProperty('src',imgFolder + '/cb_trans.gif');
                },
                'mouseout': function(){
                    this.setProperty('src',this.retrieve('gfx'));
                }
            }
        }).inject(r,'before');

        var id = r.getProperty('id');
        if(id){
            var lbl = parent.getElements('label[for='+id+']');
            if(lbl.length > 0){
                lbl.addEvents({
                    'mouseover': img.fireEvent.bind(img,'mouseover'),
                    'mouseout': img.fireEvent.bind(img,'mouseout'),
                    'click': function(event){
                        img.fireEvent('click',event.stop());
                    }
                });
            }
        }

    })
}
function radio2image(parent){
    var radios = parent.getElements('input[type=radio]');
    var radioStore = {};
    var imageStore = {};
    radios.each(function(r){
        //r.addClass('hideInput');

        var name = r.get('name');
        var id = r.getProperty('id');

        if(typeOf(radioStore[name])!='array'){
            radioStore[name] = [];
            imageStore[name] = [];
        }

        var img = new Element('img', {
            'src': imgFolder + '/cb_'+ (r.get('checked') ? 'true' : 'false') +'.gif',
            'class': 'input imgCb input-'+name,
            'events': {
                'click': function(e){
                    radioStore[name] = $$(radioStore[name]);
                    imageStore[name] = $$(imageStore[name]);

                    radioStore[name].setProperty('checked',false);
                    imageStore[name].setProperty('src',imgFolder + '/cb_false.gif');

                    r.setProperty('checked',true);
                    img.setProperty('src',imgFolder + '/cb_true.gif');
                    img.store('gfx',imgFolder + '/cb_true.gif');

                    var f = _clickEvents[id];
                    if(typeOf(f) == 'function') f();

                    return false;
                },
                mouseover: function(){
                    var src = this.getProperty('src');
                    this.store('gfx',src);
                    if(src.contains('cb_false')){
                        this.setProperty('src',imgFolder + '/cb_trans.gif');
                    }
                },
                mouseout: function(){
                    this.setProperty('src',this.retrieve('gfx'));
                }
            }
        }).inject(r,'before');

        radioStore[name].push(r);
        imageStore[name].push(img);

        if(id){
            var lbl = parent.getElements('label[for='+id+']');
            if(lbl.length > 0){
                lbl.addEvents({
                    'mouseover': img.fireEvent.bind(img,'mouseover'),
                    'mouseout': img.fireEvent.bind(img,'mouseout'),
                    'click': function(event){

                        img.fireEvent('click',event.stop());
                    }
                })
            }
        }
        r.setStyle('display', 'none');
    })
}

function nfCRM(){
    var t = document.id('iv-2-termine');
    if(!t) return;

    var e = {};

    t.getElements('input.crm-teilnehmer').each(function(input){
        var c = input.get('class').split().pop().substr(7);
        //alert(c);
        if(!e[c]) e[c] = [];

        e[c].push(input);

        input.addEvent('blur', function(){
            var val = this.value.toInt();

            if(typeOf(val) != 'number') val=0;
            else if(val > 6)            val=6;
            else if(val < 0)            val=0;
            var clear = (val <= 0);

            this.value = val;

            var _this = this;
            e[c].each(function(i){
                if(_this != i && !_this.get('readonly')){
                    if(clear){
                        i.set('readonly',false);
                        i.set('value', '0');
                        i.set('title','');
                        i.removeClass('showOnly');
                    } else {
                        i.set('readonly',true);
                        i.set('value', _this.value);
                        i.set('title','Diese Teilnehmerzahl wurde automatisch aus einem anderen Termin transferriert.');
                        i.addClass('showOnly');
                    }
                }
            });
        });
    })
}

function nfAcc(){
    if(nfAcc_prepare()){
        var cfg = {
            opacity: false,
            alwaysHide: true,
            onActive: function(tog,elm){
                tog.addClass('acc-on');
            },
            onBackground: function(tog,elm){
                tog.removeClass('acc-on');
            },
            duration: 100
        }
    } else {
        var cfg = {
            display: -1,
            opacity: false,
            alwaysHide: true,
            onActive: function(tog,elm){
                tog.addClass('acc-on');
                elm.addClass('acc-con-on');
            },
            onBackground: function(tog,elm){
                tog.removeClass('acc-on');
                elm.removeClass('acc-con-on');
            },
            duration: 100
        }
    }

    var content = document.id('content');
    var cnt = content.getElements('div.acc-content');
    if(cnt.length == 0) return;



    cnt[cnt.length-1].setStyle('margin-bottom',5);
    var acc = new Fx.Accordion(content.getElements('.acc-title'), cnt, cfg);
}
/*
    html
    body #page-1407 .rl-634 rl-626 rl-617
    div #pageframe
    div #content_area
    div #content .content
    div #c7136 .csc-default
    div .acc-1 null-0
    div .paging_content
    div #c5703 .csc-default
*/
function nfAcc_prepare(){
    //transformiert die Inhalte des D'n'D Acc für die Bearbeitung via nfAcc
    var content = document.id('content');
    var cnt = content.getElements('div.acc-1 .paging_content > div');
    if(cnt.length == 0) return false;

    var parent = new Element('div');
    parent.inject(cnt[0],'before');

    cnt.each(function(c){
        var h = c.getElement('h5').addClass('acc-title').inject(parent);
        var p = c.addClass('acc-content').inject(parent);
    });
    return true;
}
function nfMap(){
    if(Browser.ie && (!Browser.ie9 && !Browser.ie10)){
        return;
    }


    var map = document.id('imap-orte');
    if(map){
        var p = document.id('table-zm-prod');
        map.getElements('area').each(function(a){
            var c = a.get('class');
            var e = p.getElements('td.'+c);
            a.addEvents({
                mouseover: e.addClass.bind(e,'hl'),
                mouseout:  e.removeClass.bind(e,'hl')
            });
        });
        p.getElements('td').each(function(td){
            var c = td.get('class').split(' ').erase('ort').pop();
            var e = p.getElements('td.'+c);
            td.addEvents({
                mouseover: e.addClass.bind(e,'hl'),
                mouseout:  e.removeClass.bind(e,'hl')
            });
            var a = td.getElement('a[href]');
            if(a) td.addEvent('click', a.get('href').toURI().go.bind(a));
        });
    }
    return;
}



/*

$zielW = intval($_GET['w']);
$src   = '/var/typo3/www/';
$dst   = '/var/typo3/www/typo3temp/temp/';

$SRC   = realpath($src.$_GET['f']);
if(substr($SRC,0,strlen($src))!=$src) die('no injection. Just ejection! Take a Fly... ^^');

$DST   = $dst.md5($SRC).'.png';

if((!is_file($DST) && is_file($SRC)) || true){
    $xy = getimagesize($SRC);
    $B = $xy[0];
    $H = $xy[1];




<div id="c3188" class="csc-default">
    <div class="csc-textpic csc-textpic-center csc-textpic-above">
        <div class="csc-textpic-imagewrap csc-textpic-single-image" style="width:500px;"><img src="uploads/pics/gen_thumb.php41.png" width="500" height="342" alt="" /></div>
        <div class="csc-textpic-text">
            <p class="bodytext"><b>Prof. Dr. Norbert Walter</b>, ehemaliger Chefvolkswirt der Deutschen Bank (FOM Frankfurt, Verabschiedung Juni 2009)</p>
        </div>
    </div>
    <div class="csc-textpic-clear"><!-- --></div>
</div>
<div id="c3189" class="csc-default">
    <div class="csc-textpic csc-textpic-center csc-textpic-above">
        <div class="csc-textpic-imagewrap csc-textpic-single-image" style="width:500px;"><img src="uploads/pics/gen_thumb_01.png" width="500" height="375" alt="" /></div>
        <div class="csc-textpic-text">
            <p class="bodytext"><b>Dr. Angela Merkel</b>, Bundeskanzlerin der Bundesrepublik Deutschland (FOM Essen, Semestereröffnung September 2004)</p>
        </div>
    </div>
    <div class="csc-textpic-clear"><!-- --></div>
</div>

*/

function nfGal(){
    document.id('content').getElements('div.nf-galery-1').each(function(g,i){
        //var prev = g.getPrevious('*');
        //if(prev && prev.tagName.toLowerCase() == 'h5')
        g.addClass('nf-galery-topline');
        g.getChildren('div')[0].setStyle('display','none');

        var fxConf = {duration: 'long', link: 'cancel'};




        var pics = new Element('div.picArea.highslide-gallery').inject(g,'bottom');
        var scroll = new Fx.Scroll(pics, fxConf);
        var curPos = 0;

        var as = g.getElements('a');

        var max = as.length-2;
        var maxl = 532; //Vollbreite abzüglich des bullets selbst
        var per = (maxl / max).ceil();


        //Button START
        var bul = new Element('div.nf-bullet[html=&nbsp;]').inject(g,'top');
        bul.set('tween', fxConf);
        //Button ENDE


        if(as.length > 3){
            var next = new Element('span.np.next[html=&raquo;]').inject(g,'top');
            var prev = new Element('span.np.npi.prev[html=&laquo;]').inject(g,'top');

            next.addEvent('click', function(){
                prev.removeClass('npi');
                next.removeClass('npi');

                if(curPos+3 > as.length-1){
                    curPos = as.length-1;
                } else {
                    curPos += 3;
                }

                if(curPos >= as.length-3){
                    next.addClass('npi');
                }
                scroll.toElement(as[curPos]);
                var go = curPos*per;
                if(go > maxl) go=maxl;
                bul.tween('width',go);
            });
            prev.addEvent('click', function(){
                next.removeClass('npi');


                if(curPos - 3 < 0){
                    curPos = 0;
                    prev.addClass('npi');
                } else {
                    curPos -= 3;
                }
                if(curPos == 0){
                    prev.addClass('npi');
                }
                scroll.toElement(as[curPos]);
                var go = curPos*per;
                if(go > maxl) go=maxl;
                bul.tween('width',go);
            });
        }


        var w = 0;
        as.each(function(a){
            var p = a.getParent('dl');
            if(p){
                p = p.getElement('dd.csc-textpic-caption');
                if(p){
                    title = p.get('text');
                    a.set('alt', title).set('title', title);
                }
            }

            a.addClass('highslide').addClass('hsgroup-'+i);
            var href = a.removeProperties('onclick','target').getProperty('href').toURI().getData('file');
            a.setProperty('href',href);

            a.setProperty('onclick','return hs.expand(this, { group: '+i+' })');
            a.inject(pics);
            w += a.getSize().x;
        });

        if(Browser.opera){
            g.addClass('nf-galery-op');
            pics.setStyles({
                /*width: w,*/
                position: 'absolute',
                top: 1
            });
            viewEl = new Element('div').wraps(pics);
        }


        //var n = hs.updateAnchors();
        //alert(JSON.encode(n))

    });

    //http://fom2.by.nf/index.php?eID=tx_cms_showpic&file=uploads%2Fpics%2Fberatungsteam.jpg&md5=54b532bfe035a634869268a08b343b2c5843f1be&parameters[0]=YTo0OntzOjU6IndpZHRoIjtzOjQ6IjgwMG0iO3M6NjoiaGVpZ2h0IjtzOjQ6IjYw&parameters[1]=MG0iO3M6NzoiYm9keVRhZyI7czo0MToiPGJvZHkgc3R5bGU9Im1hcmdpbjowOyBi&parameters[2]=YWNrZ3JvdW5kOiNmZmY7Ij4iO3M6NDoid3JhcCI7czozNzoiPGEgaHJlZj0iamF2&parameters[3]=YXNjcmlwdDpjbG9zZSgpOyI%2BIHwgPC9hPiI7fQ%3D%3D
//    $$('a[href*=tx_cms_showpic],a.mediathekgalerie').each(function(a){
//        a.addClass('highslide');
////        var oc = a.getProperty('onclick');
////        if(oc != null && oc.length > 0) {
////            var w = oc.match("width\=([0-9]*)")[1];
////            var h = oc.match("height\=([0-9]*)")[1];
////
////            a.store('storedWidth', w);
////            a.store('storedHeight', h);
////        } else {
////            a.store('storedWidth', 0);
////            a.store('storedHeight', 0);
////        }
//
//        a.removeProperties('onclick','target');
//        var href = '';
//        if(!a.hasClass('mediathekgalerie')) {
//            href = a.getProperty('href').toURI().getData('file');
//        } else {
//            href = a.removeProperties('onclick','target').getProperty('href');
//        }
//        a.setProperty('href',href).setProperty('onclick','hs.expand(this); return false')
//    })
    hs = new TMP_GALERY();

    $$('div.tx-nfmediathek2012-pi1 div.shuffledmedia').each(function(el) {
        new NFJK_SCROLL(el);
    });
    $$('div.tx-nfmediathek2012-pi1 div.mediatype2 a.gallerylink').addEvent('click', function() {
        hs.expand(this.getParent('div.rndmedia').getElement('div.mediathekgallery a.mediathekgalerie'));
        return false;
    });
    $$('div.tx-nfmediathek2012-pi1 div.gallery a.detailgallerylink').addEvent('click', function() {
        hs.expand(this.getParent('div.gallery').getElement('div.mediathekgallery a.mediathekgalerie'));
        return false;
    });
    $$('div.tx-nfmediathek2012-pi1 div.mediatype2 div.mediathekgallery a.mediathekgalerie img, div.tx-nfmediathek2012-pi1 div.gallery div.mediathekgallery a.mediathekgalerie img').hide();


    //$$('div.au_details').slide('hide');
}

var NFJK_SCROLL = new Class({
    Implements: Options,

    position: 1,
    maxElements: 1,

    lftBtn: null,
    rgtBrn: null,
    scrollers: null,
    stage: null,
    stagemargin: null,

    options: {
        fadings: {
            hover: 1,
            active: 1,
            inactive: 0.1
        },
        tween: {
            transition: 'expo:in:out',
            duration: 500
        },
        scrollClasses: {
            left: 'div.scrollknobleft',
            right: 'div.scrollknobright',
            def: 'div.scrollknob'
        },
        scrollElements: 'div.randomgroup',
        stageClass: 'div.mediascroller',
        scrollerClass: 'nfelementscroller'
    },
    initialize: function(el) {
        var _ = this;
        this.scrollers = el.getElements(this.options.scrollElements);
        if(this.scrollers.length > 0) {
            this.maxElements = this.scrollers.length;

            $$(this.options.scrollClasses.def).each(function(sn) {
                sn.fade(_.options.fadings.active);
                sn.addEvent('mouseenter', function() {
                    if(!sn.hasClass('inactive')) {
                        sn.fade(_.options.fadings.hover);
                    }
                });

                sn.addEvent('mouseleave', function() {
                    if(!sn.hasClass('inactive')) {
                        sn.fade(_.options.fadings.active);
                    }
                });
            });

            this.stage = el.getElement(this.options.stageClass);
            if(this.stage) {
                this.lftBtn = el.getElement(this.options.scrollClasses.left);
                if(this.lftBtn) {
                    this.lftBtn.addEvent('click', function(e) {
                        _.scrollLeft(this);
                    });
                }
                this.deactivateBtn(this.lftBtn);

                this.rgtBtn = el.getElement(this.options.scrollClasses.right);
                if(this.rgtBtn) {
                    this.rgtBtn.addEvent('click', function(e) {
                        _.scrollRight(this);
                    });
                }

                var c = 0;
                this.scrollers.each(function(scr) {
                    scr.addClass(_.options.scrollerClass + ++c);
                });
            }
        }
    },
    scrollLeft: function(el) {
        if(this.position > 1) {
            this.position--;
            this.scrollToCurrentPosition();
        }
    },
    scrollRight: function(el) {
        if(this.position < this.maxElements) {
            this.position++;
            this.scrollToCurrentPosition();
            if(this.position == this.maxElements) {
                el.addClass('deactivate');
            }
        }
    },
    scrollToCurrentPosition: function() {
        var scrTo = this.stage.getElement('.' + this.options.scrollerClass + this.position);
        var newPos = scrTo.getPosition(this.stage).x * (-1);
        new Fx.Tween(this.stage, Object.merge(
            {
                property: 'margin-left'
            },
            this.options.tween
        )).start(this.stagemargin, newPos);
        this.stagemargin = newPos;

        if(this.position == this.maxElements) {
            this.deactivateBtn(this.rgtBtn);
        } else if(this.position == 1) {
            this.deactivateBtn(this.lftBtn);
        } else {
            this.activateBtn(this.lftBtn);
            this.activateBtn(this.rgtBtn);
        }
    },
    deactivateBtn: function(el) {
        el.addClass('inactive');
        el.fade(this.options.fadings.inactive);
    },
    activateBtn: function(el) {
        el.removeClass('inactive');
        el.fade(this.options.fadings.active);
    }

});

var hs;
var TMP_GALERY = new Class({
    mask: null,
    window: null,
    e: {
        bildVon: null,
        bild: null,
        alt: null,
        next: null,
        prev: null
    },
    links: null,
    glinks: null,
    images: [], //array of preloaded images
    imagesP: [], //array of preloaded image names (really preloaded)
    imgPreSized: [],
    imagesI: {}, //Infos
    cur: 0,
    curInGal: 0,
    gal: 0,
    curgal: 0,
    preloaded: false,


    initialize: function(){

        this.glinks = new Array();

        var $this = this;
        this.mask = new Mask($(document.body), {
            hideOnClick: true,
            onHide: function(){
                $this.window.hide();
            }
        });

        this.window = new Element('div.nfPicView').inject($(document.body),'top').hide();

        var topBar = new Element('div.topBar').inject(this.window);
        this.e.bildVon = new Element('span[text=Bild x von y]').inject(topBar);
        new Element('a.close[text=schließen x][href=#]').inject(topBar).addEvent('click', function(){
            $this.mask.hide();
            $this.window.hide();
            return false;
        });

        this.e.bild = new Element('img.galim').inject(this.window);

        var botBar = new Element('div.botBar').inject(this.window);
        this.e.prev = new Element('a[text=« zurück][href=#]').inject(botBar).addEvent('click', this.prev.bind(this));
        this.e.alt = new Element('span.alt').inject(botBar);
        this.e.next = new Element('a[text=weiter »][href=#]').inject(botBar).addEvent('click', this.next.bind(this));

        this.assign();
        this.assign.delay(1000, this);
    },
    assign: function(){
        var imgList = [];
        var imgPreSized = [];
        var _ = this;
        var j = 0;
        var doc;
        this.links = $$('a.highslide').each(function(img, i){
            // img IST EIN A-TAG!!!
            doc = false;
            var par = img.getParent('div.highslide-gallery, div.csc-textpic-imagewrap, div.mediathekgallery');
            if(par) {
                if(!par.hasClass('highslide-gallery-revisited')) {
                    par.addClass('highslide-gallery-revisited').addClass('highslide-gallery-g' + _.gal);

                    _.glinks[_.gal] = new Array();
                    _.gal++;
                    j = 0;
                }
                //console.log(_.glinks);

                var sw = img.retrieve('storedWidth');
                var sh = img.retrieve('storedHeight');

                var childImg = img.getElement('img');
                if(childImg != null) {
                    childImg.setStyle('clear', 'both');

                    img.setStyles({
                        'height': childImg.getComputedSize().height + 'px',
                        'width': childImg.getComputedSize().width + 'px'
                    });

                    img.set('rel', i);
                    imgList.push(img.href);

                    imgPreSized[img.href] = {h: sh, w: sw};

                    if(!img.hasClass('inGallery')) {
                        img.addClass('inGallery').addClass('inGal-'+ (_.gal - 1));
                        img.store('gallery', _.gal - 1);
                        img.store('imingal', j);
                        if(_.glinks[_.gal - 1] != null) {
                            _.glinks[_.gal - 1].push(img);
                        } else {
                            _.glinks[_.gal - 1] = new Array();
                            _.glinks[_.gal - 1].push(img);
                        }
                    }
                }
                j++;
            }
        });

        //console.log(imgPreSized);
        //console.log(_.glinks);
        this.imgList = imgList;
        this.imgPreSized = imgPreSized;

        if(!this.preloaded){
            this.preloaded = true;
            this.preload();
        }
    },
    preload: function(){
        var _ = this;
        var I = this.images;
        I = Asset.images(this.imgList,{
            onProgress: function(c,i,s){
                var w = I[i].get('width');
                var h = I[i].get('height');
                if(w > 500){
                    h = h * (500/w);
                    w = 500;
                }

                var scale = h / w;
                var siz = _.imgPreSized[s];

                if(siz.h > 0) h = siz.h;
                if(siz.w > 0) w = siz.w;

                //console.log(siz);

                // Falls eine Größe nicht explizit gegeben ist oder das Seitenverhältnis nicht mehr stimmt, Seitenverhältnis wiederherstellen (Breite wird bevorzugt behandelt)
                if(siz.w > 0 && (siz.h == 0 || siz.h / siz.w != scale))  {
                    h = w * scale;
                } else if(siz.h > 0 && (siz.w == 0 || siz.h / siz.w != scale))  {
                    w = h / scale;
                }

                _.imagesI[s] = {
                    src: s,
                    width: w,
                    height: h
                };
                //console.log(_.imagesI[s]);
            }
        });
    },
    expand: function(t, conf){
        var grp=null;
        if(conf){
            grp = conf.group;
        }

        var gall = t.retrieve('gallery');

        var num = t.get('rel').toInt();
        this.cur = num;
        this.curgal = gall;

        var j = t.retrieve('imingal');

        var title = t.get('title') || t.get('alt');
        if(!title){
            var p = t.getParent('dl')
            if(p) title = p.getElement('dd.csc-textpic-caption').get('text');
        }

        var img = t.href;

        var sw = t.retrieve('storedWidth');
        var sh = t.retrieve('storedHeight');

        this.e.bild.setProperty('src', img);
        this.e.bild.setProperties(this.imagesI[img]);

        if(this.imagesI[img]) {
            this.window.setStyle('width', this.imagesI[img].width + 'px');
            this.e.alt.setStyle('width', (this.imagesI[img].width - 170) + 'px');
        }

//        if(sw != null && sw > 0) {
//            this.e.bild.setProperty('width' ,sw);
//            this.window.setStyle('width', sw + 'px');
//        }
//        if(sh != null && sh > 0) {
//            this.e.bild.setProperty('height',sh);
//            //this.window.setStyle('height', sh + 'px');
//        }

        this.e.bildVon.set('text', 'Bild '+ (j+1) +' von '+ this.glinks[this.curgal].length);

        //this.e.bild.setProperties(this.imagesI[img]);
        //this.e.bildVon.set('text', 'Bild '+ (num+1) +' von '+ this.links.length);

        this.e.alt.set('text', title);

        this.e.prev.fade('show');
        if(num==0 || j==0) this.e.prev.fade('hide');

        this.e.next.fade('show');

        if(this.glinks[this.curgal].length == j+1 || this.glinks[this.curgal].length == 1) this.e.next.fade('hide');
        else if(num==this.links.length-1) this.e.next.fade('hide');

        this.window.show().position();
        this.mask.show();
        return false;
    },
    next: function(){
        this.cur++;
        if(this.cur == this.links.length) this.cur = 0;
        //if(this.cur == this.glinks[this.curgal].length) this.cur = 1;                     ###

        this.expand(this.links[this.cur]);
        //console.log(this.glinks[this.curgal]);
        //this.expand(this.glinks[this.curgal][this.cur - 1]);                      ###
        return false;
    },
    prev: function(){
        this.cur--;
        if(this.cur < 0) this.cur = this.links.length-1;

        this.expand(this.links[this.cur]);
        return false;
    }
});



function expand(a){
    alert(a.tagName);
    alert(config1);
    alert(typeOf(hs.expand));
    return hs.expand.bind(hs,[a,config1]);
}

(function(){
    String.implement({
        'sub_str': function(start,stop){
            if(start < 0){
                start = this.length + start;
            }
            if(stop < 0){
                stop = this.length - start + stop;
            }
            return this.substr(start,stop);
        }
    });
})();

function toggleInfo(){
    document.id('logon_information').slide('toggle');
}

function checkForPH(e){

    if(typeOf(e)!='element'){
        //alert(typeOf(e));
        e = this;
    }

    var ph = e.get('placeholder');
    if(e.get('multiple')){
        //
    } else {
        var sel = e.getSelected().pop();
        if(sel.get('text') == ph){
            e.setStyle('color','#bbb');
        } else {
            e.setStyle('color','#000');
        }
    }


}






window.addEvent('load',function(){
    if(document.id('menu1') != null) {
        new nf.layerMenu(document.id('menu1').getElement('ul'),{
            initFn: function(ul){
            },
            redo: {
                'menu-637': function(div,ul){
                    var w = div.getStyle('width').toInt();
                    var h = $H({ li: 5, re: 5 });
                    div.setStyle('width', 2*w);

                    var lis = ul.getChildren('li');
                    lis.each(function(li,i){
                        li.getElement('a').setStyles({
                            'font-weight':'bold'
                        });
                        if(i > 0){
                            li.setStyles({
                                'position': 'absolute',
                                'left': w+9,
                                'top': h.re,
                                'width': w
                            });
                            h.re += li.getSize().y;
                        } else {
                            li.setStyles({
                                'position': 'absolute',
                                'left': 9,
                                'top': h.li,
                                'width': w
                            });
                            h.li += li.getSize().y;
                        }
                    })
                    var h = h.getValues().max();
                    div.setStyle('height', h);
                },
                'menu-636': function(div,ul){
                    this.deleteSub(ul);

                    var w = div.getStyle('width').toInt();
                    var h = 9, h2=9;
                    div.setStyle('width', 2*w);


                    var lis = ul.getChildren('li');
                    var half = (lis.length/2).ceil();
                    var lastLi = 0;

                    lis.each(function(li,i){
                        if(i >= half){
                            li.setStyles({
                                'position': 'absolute',
                                'left': w+9,
                                'top': h,
                                'width': w
                            });
                            var y = li.getSize().y;
                            h+= y;
                            lastLi = y;
                        } else {
                            li.setStyles({
                                'position': 'absolute',
                                'left': 9,
                                'top': h2,
                                'width': w
                            });
                            var y = li.getSize().y;
                            h2 += y;
                            //li.setStyle('width',w);
                        }
                    })
                    if(half != (lis.length/2).floor()){
                        h += lastLi;
                    }

                    div.setStyle('height', h-9)
                }
            }
        });
    }
    //initHighslide()

});


//var nf = new Object();

nf.tab = new Class({
    Implements: Options,

    tabHomeE: null,     //will hold the TabHome-Element
    tabHeadE: [],       //will hold the Headline-Elements (inside tabHomeE)
    tabE: [],           //will hold the Tab-Elements

    options: {
        'titleSelector': 'h2 span',
        'hideTitleElement': false,

        'tabActiveClass': 'aktiv',
        'inject': 'firstTab',
        'injectMode': 'before',
        'tabberClass': 'tabber',
        'classesToRemove': ['tabber', 'tabContent', 'dTabbed', 'tabbed'],

        'ignoreHash': false
    },
    currentTab: null,

    initialize: function(tabs,options){
        var _this = this;
        var _url = new URI(window.location.href);
        var _url2 = Object.clone(_url);
        var frag;
        this.tabE = tabs;

        this.setOptions(options);


        this.tabHomeE = new Element('div',{
            'class': this.options.tabberClass
        });
        new Element('div.clear').inject(this.tabHomeE);


        if(this.options.inject == 'firstTab'){
            this.options.inject = tabs[0];
        } else if(this.options.inject == 'lastTab'){
            this.options.inject = tabs.getLast;
        }
        this.tabHomeE.inject(this.options.inject,this.options.injectMode);


        tabs.each(function(tab,num){
            if(!tab) return;
            //Selector for getting Headline
            var selector = _this.options.titleSelector;
            //Headline-Element
            var hlE = tab.getElement(selector);
            //(bool) Allow Hide?
            var allowHide = true;

            if(!hlE){
                //If unable to get Element with selector, get next best Element
                hlE = tab.getElement('h1, h2, h3, h4, h5, h6, label, p');
                if(hlE) hlE = tab;
                //Do not allow to hide Element event if activated in options
                allowHide = false;
            }
            //get this Tabs Headline
            if(!hlE) return;
            var hl = hlE.get('text');

            //If element should be hidden AND is allowed to be hidden
            if(_this.options.hideTitleElement && allowHide){
                //Save Element to "del" to be able to overwrite later
                var del = hlE;
                //If option is a string it should be a selector. Treat as one:
                if(typeOf(_this.options.hideTitleElement) == 'string'){
                    del = hlE.getParent(_this.options.hideTitleElement);
                }
                //Get the Element outa here! ;)
                del.dispose();
            }
            //var urlName = hl.toLowerCase().toASCII('-') +'-'+(num+1);
            //var url = _url2.set('fragment','!'+urlName);
            _this.tabHeadE[num] = new Element('a', {
                'class': 'tab '+tab.get('class'),
                href: '#', //url.toString(),
                'text': hl,
                events: {
                    'click': _this.activate.bind(_this,num)
                }
            }).inject(_this.tabHomeE).removeClasses(_this.options.classesToRemove);
            _this.tabHeadE[num].store('name',hl.toLowerCase().toASCII('-') +'-'+(num+1));
            _this.tabHeadE[num].store('name2',hl.toLowerCase().toASCII('-'));

            if(tab.hasClass('aktiv')){
                frag = num+1;
            }

            tab.addClass('hiddenTab');
        });

        if(this.tabHeadE.length.between(4,6)){
            var max = 0;
            this.tabHeadE.each(function(e){
                var w = e.getSize().x;
                max = max.max(w);
            })
            var aThird = 531/3;
            if(max < aThird){
                $$(this.tabHeadE).addClass('third');
            }
        }


        /*
        if(!frag){
            var f = _url.get('fragment');
            frag = (f.split('-').pop())*1;
        }
        */
        if(!frag){
            frag = BROWSER.getHashKey('tab');
        }


        if(frag <= 0) frag = 1;
        this.activate(frag-1,1);



    },
    activate: function(num,isInit){
        var tab = this.tabE[num];
        var head = this.tabHeadE[num];

        if(tab){
            var urlName = head.retrieve('name');
            if(!this.options.ignoreHash) BROWSER.setHash('tab',urlName,isInit);

            this.inactivate();
            this.currentTab = num;
            tab.removeClass('hiddenTab');
            head.addClass(this.options.tabActiveClass);
            document.fireEvent('activateTab',tab);
        }
        return false;
    },
    inactivate: function(){
        var num = this.currentTab;

        if(num != null){
            var tab = this.tabE[num];
            var head = this.tabHeadE[num];

            tab.addClass('hiddenTab');
            head.removeClass(this.options.tabActiveClass);
        }
    }


});
nf.browser = new Class({
    initialize: function(){
        if(Browser.ie6)             this.ie6();
        else if(Browser.ie7)        this.ie7();
        else if(Browser.ie8)        this.ie8();
        else if(Browser.ie9)        this.ie9();
        else if(Browser.firefox2)   this.ff2();
        else if(Browser.firefox3)   this.ff3();
        else if(Browser.firefox4)   this.ff4();
        else if(Browser.firefox5)   this.ff5();
        else if(Browser.firefox6)   this.ff6();
        else if(Browser.firefox7)   this.ff7();
        else if(Browser.firefox8)   this.ff8();
        else if(Browser.firefox9)   this.ff9();
        else if(Browser.safari3)    this.sa3();
        else if(Browser.safari4)    this.sa4();
        else if(Browser.safari5)    this.sa5();
        else if(Browser.chrome)     this.chr();
        else if(Browser.opera)      this.opr();
        this.initHash();
    },

    //Versions-Spezifikat
    ie6: function(){
        this.ie6_7();

    },
    ie7: function(){ this.ie6_7(); },
    ie8: function(){
        nf.set('_layerMenu.addY',-17);
    },
    ie9: function(){
        nf.set('_layerMenu.addY',-16);
    },

    ff2: function(){ this.ff(); },
    ff3: function(){ this.ff(); },
    ff4: function(){ this.ff(); },
    ff5: function(){ this.ff(); },
    ff6: function(){ this.ff(); },
    ff7: function(){ this.ff(); },
    ff8: function(){ this.ff(); },
    ff9: function(){ this.ff(); },

    sa3: function(){ this.safari(); },
    sa4: function(){ this.safari(); },
    sa5: function(){ this.safari(); },

    chr: function(){ nf.set('_layerMenu.addY',-4); },

    opr: function(){},

    ff: function(){
        nf.set('_layerMenu.addY',-3);
    },

    //Versions-Zusammenfassungen
    ie6_7: function(){
        new nf.updateBrowser();
        var tc = document.id('content').getElements('.two_col1');

        tc.each(function(c1,num){
            var c2 = c1.getNext('div.two_col2');

            c2.inject(c1,'before');
            c2.setStyle('float','right');
        })
    },
    safari: function(){
        nf.set('_layerMenu.addY',-4);
    },



    hashConfig: $H(),
    hash: $H(),
    initHash: function(){
        var h = window.location.hash.substr(2).split('/');
        h.each(function(x){
            var d = x.split('=');
            this.hash.set(d[0], d[1]);
        }.bind(this));
    },
    setHash: function(name,value,isInit){
        if(this.hashConfig.has(name)) {
            this.hash.set(name,value);
            if(typeOf(this.hashConfig.get(name).clearOnChange) == 'string' && isInit!=1){
                this.hash.erase(this.hashConfig.get(name).clearOnChange);
            }
        } else {
            value = null;
        }

        var v = value.split('-');
        v = v.pop();

        if(v != 1 || !isInit) this.updateHash();
        return value;
    },
    getHash: function(name){
        return this.hash.get(name);
    },
    getHashKey: function(name, position){
        var val = this.getHash(name);
        if(!val) return null;
        val = val.split('-');
        return (position=='first' ? val.shift() : val.pop());
    },
    updateHash: function(){
        var h = []
        this.hash.each(function(value,name){
            if(name) h.push(name +'='+value);
        });

        window.location.hash = '!'+h.join('/');
    },
    addHash: function(name,config){
        if(!config) config = {};
        this.hashConfig.set(name,config);
    }
});
nf.updateBrowser = new Class({
    initialize: function(){
        return;
        if(Cookie.read('ignoreOldIE')!=1){
            var _this = this;
            var _body   = document.id(document.body);
            var msg = new Element('div', {
                styles: {
                    /*'position': 'absolute',
                    'left': 0,
                    'top': 0,
                    'width': '100%',
                    */'background-color': '#ffd',
                    'z-index': 9999,
                    'border-bottom': '1px dotted #666',
                    'padding': '4px 10px'
                },
                'html': '<strong><u>Information:</u> Sie benutzen einen veralteten und unsicheren Browser!</strong><br />Um den vollen Funktionsumfang der neuen FOM-Webseite zu erfahren, erwägen Sie bitte ein Update des <a href="http://www.microsoft.com/germany/windows/internet-explorer/" target="_blank">Internet-Explorers</a> oder benutzen Sie den <i>von uns empfohlenen</i> <a href="http://www.mozilla-europe.org/de/firefox/" target="_blank">Mozilla Firefox</a>!'
            }).inject(_body,'top').slide('hide').slide('in');

            new Element('button', {
                text: 'Meldung ignorieren und schließen',
                styles: {
                    'float': 'right',
                    'margin-top': 2
                },
                events: {
                    'click': function(){
                        msg.slide('out');
                        Cookie.write('ignoreOldIE', 1, {duration: 14});
                    }
                }
            }).inject(msg,'top');
        }
    }
})
nf.layerMenu = new Class({
    Implements: Options,

    parentE: null,

    deleteSub: function(ul){
        ul.getChildren('li ul').dispose();
        return ul;
    },

    initialize: function(parent,options){
        if(parent) {
            var _this = this;
            this.setOptions(options);

            if(typeOf(this.options.initFn)=='function'){
                this.options.initFn.apply(null,[parent]);
            }

            this.parentE = parent;
            var _header = document.id('header');
            var _body   = document.id(document.body);

            var lis = parent.getChildren('li');
            var addY = lis[0].getElement('a').getSize().y;

            lis.each(function(li,num){
                var pos = li.getPosition(_header);
                var ul = li.getChild('ul');
                var liId = li.get('id');
                if(ul){
                    if(typeOf(_this.options.redo[liId])!='function'){
                        _this.deleteSub(ul);
                    }
                    //Create DIV to store Menu in
                    var d = new Element('div.floatingMenu#fm-'+liId).inject(_header,'top').addEvents({
                        'mouseenter': function(){ li.addClass('aktiv') },
                        'mouseleave': function(){ li.removeClass('aktiv') }
                    });
                    if(Browser.ie && !Browser.ie9) d.addClass('floatingMenuIE');
                    pos.y += addY + (nf.get('_layerMenu.addY') || 0);
                    d.setPosition(pos);

                    //Take first Child
                    ul.addClass('submenu');
                    ul.inject(d);

                    //Sets all links to bold in order to simulate the req. width
                    var inFett = d.clone();
                    inFett.getElements('a').setStyle('font-weight','bold');
                    inFett.inject(d,'after');
                    d.setStyle('width',inFett.getComputedSize().width+5);
                    inFett.dispose();

                    var s = d.getSize();
                    if(s.y > 300){
                        d.setStyle('height',300);
                    }

                    d.fade('hide');

                    var els = $$(li.getElement('a'),d);
                    els.addEvents({
                        'mouseenter': function(e){
                            //Destroyes last active Menu (if some)
                            var laml = _body.retrieve('lastActiveMenuLayer');
                            if(laml && laml != d) laml.fade('out');

                            //Clears Time (if on same menu)
                            var timer = d.retrieve('timer');
                            if(timer) clearTimeout(timer);
                            timer = d.fade.delay(85,d,'in');
                            d.store('timer',timer);

                            //Increments z-index to keep current layer on top
                            d.incrementZ();

                            _body.store('lastActiveMenuLayer',d);
                         },
                        'mouseleave': function(e){
                            var timer = d.retrieve('timer');
                            if(timer) clearTimeout(timer);

                            timer = d.fade.delay(500,d,'out');
                            d.store('timer',timer);
                        }
                    });
                    if(typeOf(_this.options.redo[liId])=='function'){
                        _this.options.redo[liId].apply(_this,[d,ul]);
                    }
                }

            });
        }
    },
    recursiveScan: function(ul){
        var _this = this;
        var list = [];

        ul.getChildren('li').each(function(li){
            var a = li.getElement('a');
            var entry = {
                title:   a.get('text'),
                link:    a.get('href'),
                'class': li.get('class'),
                _sub:    [],
                liE:     li
            }
            var nextUl = li.getElement('ul');
            if(nextUl){
                var sub = _this.recursiveScan(nextUl);
                if(sub) entry._sub = sub;
            }
            list.push(entry);
        })
        return list;
    }

});
nf.paging = new Class({
    Implements: Options,
    options: {
        selector: '#content div.paging',
        divide: 'selector',
        elementsPerPage: 2
    },
    initialize: function(options){
        this.setOptions(options);

        $$(this.options.selector).each(function(pg){
            var pager = new nf.pager(pg, this.options);
            pg.store('pager',pager);
        }.bind(this));

        var g = $$('div.pg-content !> div.csc-default');

        var opt = Object.clone(this.options);
        opt.divide = 'divider';

        g.each(function(pg){
            var pager = new nf.pager(pg, opt);
            pg.store('pager',pager);
        }.bind(this));
    }
});
nf.pager = new Class({
    Implements: Options,
    original: null,
    parent: null,
    current: null,
    al: null,
    force: false,
    pager: {},
    moveOutElements: Array(),
    hasArchive: false,
    maxPage: 0, //iterator starts at 0 - so maxPage is NoOfPages-1

    options: {
        //Elements that are taken account for paging (It's sick with slick!)
        allowedElements: [
            ':not(div.tx_nftestemonial_testemonial_wrap) !> div.csc-default',
            ':not(div.tx_nfaktuelles_pi2_paging) !> div.csc-default',
            ':not(div.archive-link-div) !> div.csc-default',
            ':not(div.forcepaging) !> div.csc-default',
            'div.csc-frame',
            'div.tx_nftestemonial',
            'div.tx_nfaktuelles_pi2_entry',
            'div.tx_nfaktuelles_pi2_entry-v2',
            'div.tx_nfaktuelles_pi2_termin_content',
            'div.tx-nfmediathek-pi1 div.video-frame'
        ],
        // Elements that are places over the page navigation
        overTopElements: [
            '.outOfPaging'
        ],
        //Classes that are going to be removed at each pages last Element
        removeClassesFromLast: [
            'csc-frame-rulerAfter',
            'csc-frame-rulerAfter-Full',
            'tx_nfaktuelles_pi2_entry-v2_line'
        ],
        //Elements per Page (default)
        elementsPerPage: 4,
        //if a class-name starting with that string is present in a paging-parent,
        //  the number of elements per page is overwritten with the value directly
        //  following that string (default: pg-epp-12 will allow 12 Elements per page)
        overrideElementsPerPage: 'epp-',
        allowOverrideElementsPerPage: true
    },
    initialize: function(parent, options){
        this.init(parent, options);
    },

    destroy: function() {
        //this.parent.set('html', this.original);
        this.original.replaces(this.parent);
        this.moveOutElements.each(function(moe) {
            try{
                moe.dispose();
                moe.destroy();
            } catch(e){}
        });
        this.parent = this.original;
        this.al = null;
        this.maxPage = 0;
        return this.parent;
    },

    reload: function(o) {
        this.original.replaces(this.parent);
        this.parent.destroy();
        this.parent = this.original;
        this.moveOutElements.each(function(moe) {
            moe.dispose();
            moe.destroy();
        });
        this.init(this.parent, o);
        return this.parent;
    },

    init: function(parent, options) {

        if(parent.getElement('.newStyle')) return;

        //this.original = parent.get('html');
        this.original = parent.clone(true, true);

        this.setOptions(options);
        this.div = this.options.divide;

        var _this = this;
        var o = this.options;

        var forceObjects = parent.getElements('div.forcePaging, div.archive-link-div');
        if(forceObjects.length > 0) _this.force = true;

        var cl = parent.get('class').split(' ');
        this.parent = parent;

        var pp = parent;


        var pagingselects = $$('select.paging-epp-select');
        pagingselects.each(function(psel) {
            var pseldiv = new Element('div.outOfPaging.paging-epp-select-div');
            psel.removeClass('outOfPaging');
            pseldiv.inject(psel, 'after');
            psel.inject(pseldiv);

            psel.addEvent('change', function() {
                var elpp = (parseInt(psel.value));
                if(elpp > 0) {
                    // Elements per page neu setzen
                    _this.options.elementsPerPage = elpp;
                    _this.options.allowOverrideElementsPerPage = false;
                    this.getParent('div').empty().destroy();
                    parent = _this.destroy();
                    _this.init(parent, _this.options);
                }
            });

            //var pselopts = psel.getElements('option');
            //var pseloptsArr = new Array();
            //pselopts.each(function(pselopt) {
            //    if(parseInt(pselopt.value) > 0) {
                    //paginga = new Element('a.paging-epp-select-a');
                    //paginga.store('epp', parseInt(pselopt.value));
                    //paginga.addEvent('click', function() {
                    //    // Elements per page neu setzen
                    //    _this.options.elementsPerPage = this.retrieve('epp');
                    //    _this.options.allowOverrideElementsPerPage = false;
                    //    this.getParent('div').empty().destroy();
                    //    parent = _this.destroy();
                    //    _this.init(parent, _this.options);
                    //});
                    //paginga.set('text', parseInt(pselopt.value));
                    //pseloptsArr.push(paginga);
            //    }
            //});
            //pseloptsArr.reverse();
            //pseloptsArr.each(function(paginga) {
            //    paginga.inject(psel, 'after');
            //});
        });

        var moveOuts = this.parent.getElements(o.overTopElements.join(', '));
        moveOuts.each(function(moe) {
            _this.moveOutElements.push(moe);
            moe.dispose();
        });

        if(o.divide == 'divider'){
            this.byDivider();
        } else {
            var epp  = this.options.overrideElementsPerPage;
            var eppL = epp.length;

            cl.each(function(x){
                if(x.substr(0,eppL)==epp && x.length>eppL && x.substr(eppL).toInt() > 0 && _this.options.allowOverrideElementsPerPage) _this.options.elementsPerPage = x.substr(eppL);
            })
            this.bySelector();
        }

        BROWSER.addHash('page');
    },

    bySelector: function(){
        var _this = this;
        var o = this.options;
        var showDiv = false;

        var pe = this.parent.getElements(o.allowedElements.join(', '));
        if($('c19821')){
            var pe = this.parent.getElements('div.video-frame');
            //this.options.elementsPerPage = 15;
            //this.options.allowOverrideElementsPerPage = false;
        }
        if(pe.length <= o.elementsPerPage && !_this.force) return;

        var aldiv = this.parent.getElement('div.archive-link-div');
        if(aldiv) {
            this.hasArchive = true;
            var allinks = aldiv.getChildren('a');
            if(allinks.length > 0) this.al = allinks[0];
            aldiv.destroy();
        }

        pe.dispose();

        var pe2 = new Elements();
        pe.each(function(pel) {
            pel.addClass('empty_' + pel.getChildren(':empty, div.clear, div.forcePaging').length);
            pel.addClass('children_' + (pel.getChildren().length));

            if(pel.getChildren(':empty, div.clear').length < pel.getChildren().length) {
                pe2.push(pel);
            } else {
                pel.addClass('allempty');
            }
        });
        pe = pe2;


        var page = 0;
        var div = new Element('div.singlePage.page-'+page);

        /*
        var showDiv = false;
        pe.each(function(el,i){
            if(i%o.elementsPerPage==0 && i > 0){
                new Element('div.clear').inject(div);
                div.inject(_this.parent);
                div = new Element('div.singlePage.hiddenPage.page-'+(++page));
                showDiv = false;
            }
            el.inject(div);
            showDiv = true;
        })
        if(showDiv){
            new Element('div.clear').inject(div);
            div.inject(_this.parent);
        }
        else page--;
        */
        pe.each(function(el,i){
            el.inject(div);
            showDiv = true;

            if(i%o.elementsPerPage==o.elementsPerPage-1 && (i > 0 || o.elementsPerPage==1)){
                el.removeClasses(o.removeClassesFromLast);
                new Element('div.clear').inject(div);
                div.inject(_this.parent);
                div = new Element('div.singlePage.hiddenPage.page-'+(++page));
                showDiv = false;
            }
        })

       //if(_this.force) showDiv = true;

        if(showDiv){
            new Element('div.clear').inject(div);
            div.inject(_this.parent);
        }
        else page--;

        this.maxPage = page;
        //alert(this.maxPage);
        this.go(0);
        return;
    },
    arrangeMoveOutElements: function() {
        var pT=this.pager.top, pB=this.pager.bottom;
        if(this.moveOutElements && this.moveOutElements.length > 0) {
            this.moveOutElements.each(function(moe) {
                try {
                    moe.inject(pT, 'before');
                } catch(e){}
            });
        }
    },
    addLink: function(page){
        var pT=this.pager.top, pB=this.pager.bottom;

        if(this.div == 'divider'){
            //console.log('fpt');
            //console.log(this.foreignPageTitles);
            if(this.foreignPageTitles[page]){
                var html = this.foreignPageTitles[page].get('html');

                var a = new Element('a.pg.pg-'+page+'[html='+html+'][href=#]').addEvent('click', this.go.bind(this,page)).inject(pT);
                a.clone().cloneEvents(a).inject(pB);
            }
        } else {

            var html = page+1;
            if(html<10) html = '0'+html;
            else        html = html;

            var a = new Element('a.pg.pg-'+page+'[html='+html+'][href=#]').addEvent('click', this.go.bind(this,page)).inject(pT);
            a.clone().cloneEvents(a).inject(pB);
        }
    },
    preparePager: function(){
        var pT=this.pager.top, pB=this.pager.bottom;
        if(this.hasArchive) pT.addClass('pagerT-no-margin-bottom');

        // Hier war vorher " > 1" eingetragen ... Krusy 31.10.2011
        if(this.maxPage > 0) {
            new Element('a#topNext.np[html=weiter &raquo;][href=#]').addEvent('click', this.next.bind(this)).inject(pT);
            new Element('a#topPrev.np[html=&laquo; zurück][href=#]').addEvent('click', this.prev.bind(this)).inject(pT);

            new Element('a#botNext.np[html=weiter &raquo;][href=#]').addEvent('click', this.next.bind(this)).inject(pB);
            new Element('a#botPrev.np[html=&laquo; zurück][href=#]').addEvent('click', this.prev.bind(this)).inject(pB);
        }
    },
    arrangePager: function(num){
        var _this = this;
        var mp=this.maxPage;

        if(this.parent.retrieve('hasPager') == true){
            var pT = this.pager.top.empty();
            var pB = this.pager.bottom.empty();
            //var pT = this.parent.getElement('div.pager.pagerT').empty();
            //var pB = this.parent.getElement('div.pager.pagerB').empty();
        } else {
            var pT = this.pager.top = new Element('div.pager.pagerT').inject(_this.parent,'top');
            var pB = this.pager.bottom = new Element('div.pager.pagerB').inject(_this.parent,'bottom');
            //var pT = new Element('div.pager.pagerT').inject(_this.parent,'top');
            //var pB = new Element('div.pager.pagerB').inject(_this.parent,'bottom');
            this.parent.store('hasPager',true);
        }
        this.preparePager();

        if(mp < 20){
            for(var i=0; i<=mp;i++) this.addLink(i);
            if(this.al) {
                var pT=this.pager.top, pB=this.pager.bottom;
                var alc = $(this.al).clone();
                this.al.inject(pT);
                alc.inject(pB);
            }
        } else if(mp.between(20,40)) {
            var max1 = 5 + (num.between(0,7) ? num : -1);

            for(var i=0; i<= max1;i++) this.addLink(i);

            var a = new Element('span.pg[html= ... ]').inject(pT);
            a.clone().cloneEvents(a).inject(pB);

            if(num.between(8,mp-10)){
                for(var i=num-2; i<= num+5;i++) this.addLink(i);

                var a = new Element('span.Pg[html= ... ]').inject(pT);
                a.clone().cloneEvents(a).inject(pB);
            }

            if(num.between(mp-9,mp-4)){
                for(var i=num-2; i<=mp;i++) this.addLink(i);
            }  else {
                for(var i=mp-4; i<=mp;i++) this.addLink(i);
            }
        }
        this.arrangeMoveOutElements();
    },

    byDivider: function(){
        var page = 0;

        //console.log(this);

        var pe = this.parent.getChildren('.pg-content');
        this.foreignPageTitles = this.parent.getElements('.pg-content > .pg-title').addClass('pg-tab-hl');

        pe.each(function(el,i){
            el.addClass('singlePage').addClass('hiddenPage').addClass('page-'+i);
        })

        this.maxPage = pe.length-1;
        this.go(0);
        return;
    },
    go: function(num){
        this.arrangePager(num);
        if(this.current != null){
            this.parent.getElement('.page-'+this.current).addClass('hiddenPage');
            this.parent.getElements('a.pg-'+this.current).removeClass('aktiv');
        }
        if(this.parent.getElement('.page-'+num)) this.parent.getElement('.page-'+num).removeClass('hiddenPage');
        if(this.parent.getElements('a.pg-'+num)) this.parent.getElements('a.pg-'+num).addClass('aktiv');
        this.current = num;
        return false;
    },

    next: function(){
        var go = this.current+1;
        if(go > this.maxPage) go = 0;

        return this.go(go);
    },
    prev: function(){
        var go = this.current-1;
        if(go < 0) go = this.maxPage;

        return this.go(go);
    }
});



nf.paging_gallery = new Class({
    galeries: [],
    initialize: function(){
        this.galeries = document.id('content').getElements('div.nfPGal');
        this.galeries.each(this.single.bind(this));

    },
    single: function(gal,num){
        var _ = this;
        var parent = new Element('div.thumbs.nfPGal-'+num).inject(gal);
        var images = gal.getElements('.singlePage');



        //Fügt "Übersicht" zum Paging <->
        var s1 = new Element('a[text=« zurück zur Übersicht][href=#].zurUbersicht').addEvent('click', function(){
            gal.getElements('div.pager, div.singlePage, a.zurUbersicht').addClass('nfPGal_hidden');
            gal.getElements('.thumbs').removeClass('nfPGal_hidden');
            s1.slide('hide');
            return false;
        }).inject(gal,'top').slide('hide');

        gal.store('zurUebersicht',s1);

        var max = 0;
        var singleThumbs=[];

        images.each(function(g,num){
            var img = g.getElement('.csc-textpic-imagewrap img');

            //Texting
            var txt = g.get('text');
            var htm = g.getElements('.csc-textpic-text p');

            //Thumbing
            var w = 170;
            var h = w / (img.get('width') / img.get('height'));

            var t = new Element('img',{
                src: '/thumb/?mode=gal&f='+ img.get('src'),
                width: w,
                height: h,
                alt: img.get('alt') || txt,
                title: img.get('title') || txt,
                events: {
                    click: function(){
                        _.onePic(num, gal);
                    }
                }
            })
            var tt = new Element('div.thethumb');
            t.inject(tt);


            var bo = new Element('div.singleThumb').inject(parent);
            tt.inject(bo);

            max = max.max(h);
            singleThumbs.push(tt);

            htm.each(function(h){
                h.clone().inject(bo);
            })
        });
        singleThumbs.each(function(e){
            e.setStyle('height',max);
        })
        gal.getElements('div.pager, div.singlePage, a.zurUbersicht').addClass('nfPGal_hidden');
    },
    onePic: function(page,gal){
        gal.getElements('div.pager, div.singlePage, a.zurUbersicht').removeClass('nfPGal_hidden');
        gal.getElements('.thumbs').addClass('nfPGal_hidden');
        gal.retrieve('pager').go(page);
        gal.retrieve('zurUebersicht').slide('show');
        //alert('hmmmkay');
    }
});

function nfGal2(){
    new nf.paging_gallery();
}



nf.gm = [];
nf.google_map = new Class({
    map: null,      //GMap2-Object
    bounds: null,   //GLatLngBounds-Object
    coords: null,   //GLatLng-Object
    lat: 0,         //(float) Latitude
    lon: 0,         //(float) Longitude

    E: {            //Object containing required DOM-Elements
        map: null,
        route: null,

        str: null,
        plz: null,
        ort: null
    },

    initialize: function(k,icon,lat,lon){
        var _ = this;
        this.E = {
            map: $('map-'+k),
            route: $('mapinfobox'+ k),

            str: $('direction_street'+ k),
            plz: $('direction_zip'+ k),
            ort: $('direction_city'+ k)
        }

        var pIcon = new GIcon;
        pIcon.iconSize = new GSize(59,59);
        pIcon.iconAnchor = new GPoint(30,59);
        pIcon.infoWindowAnchor = new GPoint(6,6);
        pIcon.image = '/uploads/tx_nffomgooglemap/'+icon;

        this.lat = lat;
        this.lon = lon;

        this.bounds = new GLatLngBounds();
        this.map = new GMap2(this.E.map);
        this.map.setCenter(new GLatLng(0.0, 0.0), 1);
        this.map.enableScrollWheelZoom();

        this.dir = new GDirections(this.map, this.E.route);

        this.coords = new GLatLng(lat,lon);
        this.bounds.extend(this.coords);
        this.map.setCenter(_.bounds.getCenter(), 15);

        var marker = new GMarker(new GPoint(this.coords.x, this.coords.y), {icon: pIcon});
        this.map.addOverlay(marker);

        document.addEvent('activateTab', function(tab){
            if(tab.getElements('div.mapmap').length > 0){
                _.map.checkResize();
                _.map.setCenter(_.bounds.getCenter(), 15);
            }
        });
    },
    direction: function(){
        var street = this.E.str.value;
        var plz = this.E.plz.value;
        var ort = this.E.ort.value;

        this.dir.clear();
        this.E.route.empty();
        this.E.route.setStyle('display', 'block');
        this.dir = new GDirections(this.map, this.E.route);

        var _ = this;
        GEvent.addListener(_.dir, "error", function() {


            var req = new Request.HTML({
                url:'/typo3conf/gdirections_logging.php',
                onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
                    _.E.route.set('html', responseHTML);
                }
            }).post({'status': _.dir.getStatus().code});
        });

        GEvent.addListener(_.dir, "load", function() {
            var req = new Request.HTML({url:'/typo3conf/gdirections_logging.php'}).post({'status':_.dir.getStatus().code});
        });
        var go = 'from: ' + street + ', ' + plz + ' ' + ort + ', germany to: '+ this.lat +', '+ this.lon;
        this.dir.load(go, {'locale': 'de_DE'});
        return false;
    }
});

nf.google_map3 = new Class({
    map: null,      //
    bounds: null,   //
    coords: null,   //
    lat: 0,         //(float) Latitude
    lon: 0,         //(float) Longitude

    E: {            //Object containing required DOM-Elements
        map: null,
        route: null,

        str: null,
        plz: null,
        ort: null
    },

    initialize: function(k,icon,lat,lon){
        var _ = this;
        this.E = {
            map: $('map-'+k),
            route: $('mapinfobox'+ k),

            str: $('direction_street'+ k),
            plz: $('direction_zip'+ k),
            ort: $('direction_city'+ k)
        }

        var pIcon = new google.maps.MarkerImage(
            '/uploads/tx_nffomgooglemap/'+icon,
            new google.maps.Size(59,59)
        );
        pIcon.iconAnchor = new google.maps.Point(30,59);
        pIcon.infoWindowAnchor = new google.maps.Point(6,6);

        this.lat = lat;
        this.lon = lon;
        this.coords = new google.maps.LatLng(lat,lon);

        this.bounds = new google.maps.LatLngBounds();
        this.map = new google.maps.Map(this.E.map, {
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            center: this.coords,
            zoom: 1
        });

        this.s_dir = new google.maps.DirectionsService();
        this.dir = new google.maps.DirectionsRenderer();
        this.dir.setMap(this.map);

        this.bounds.extend(this.coords);
        this.map.setCenter(this.bounds.getCenter());
        this.map.setZoom(15);

        var marker = new google.maps.Marker({
          position: this.coords,
          map: this.map,
          icon: pIcon
        });

        document.addEvent('activateTab', function(tab){
            if(tab.getElements('div.mapmap').length > 0){
                google.maps.event.trigger(_.map, "resize");
                _.map.setCenter(_.bounds.getCenter(), 15);
            }
        });
    },
    direction: function(){
        var street = this.E.str.value;
        var plz = this.E.plz.value;
        var ort = this.E.ort.value;

        var _ = this;

        //this.dir.clear();
        _.E.route.empty();
        _.E.route.setStyle('display', 'block');

        _.dir = new google.maps.DirectionsRenderer({
            suppressMarkers: true,
            panel: _.E.route,
            map: _.map
        });

        var request = {
            origin:street + ', ' + plz + ' ' + ort + ', germany',
            destination: _.lat +', '+ _.lon,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
        };

        _.s_dir.route(request, function(result, status) {
            _.dir.setDirections(result);
        });
    }
});


nf.map = new Class({
    nrw: null,
    parent: null,
    de: null,

    allowHide: false,
    timer: null,

    initialize: function(){
        var evts = {
            mouseenter: this.show.bind(this),
            mousemove: this.show.bind(this),
            mouseleave: this.hide.bind(this)
        };
        this.parent = document.id('deKarte');

        this.de     = document.getElements('#de, #deKarte > div.punkt, #deKarte > div.name');
        this.nrw    = this.parent.getElement('#nrwKarte').fade('hide').addEvents(evts);
        this.parent.getElement('#nrw').addEvents(evts);
        this.parent.getElement('#mapOv1').addEvent('mouseenter', this.show.bind(this));
    },
    show: function(){
        window.clearTimeout(this.timer);
        this.allowHide = false;
        this.nrw.fade('in');
        this.de.fade(0.5);
    },
    doHide: function(){
        if(this.allowHide){
            this.nrw.fade('out');
            this.de.fade(1);
        }
    },
    hide: function(){
        this.timer = this.doHide.delay(300,this);
        this.allowHide = true;
    }
});
nf.CAMPAGNE = function(){
    $(document.body).setStyle('background-color', '#25A297');
    $('logo').getElement('img').set('src', '/fileadmin/templates/fom/img/toplogo-hochschule.gif');
}
nf.home = function(){
    var file = '/fileadmin/fom/home/ReFOM.swf';


	if($(document.body).get('id') =='page-617'){
	    document.id('box').setStyles({
	        'background-image': 'url(/fileadmin/fom/kampagne/Startseite/header_startseite.jpg)',
	        height: 347,
	        width: 916
	    }).grab(new Element('a[href=/bietet-mehr/]').setStyles({display: 'block', height: 347, width: 916}));
        //nf.CAMPAGNE();
	    return;
	}


    if($(document.body).get('id') =='page-6599') file = '/fileadmin/FOM_International/home/banner.swf';
    window.addEvent('domready', function(){
        if(Browser.Plugins.Flash.version > 9){
            new Element('div#flashContent2').inject(document.id('content_area'),'before');
            document.id('box').destroy();

		    var so = new SWFObject(file,'flashContent3','936','353','10.0.0','#000000');
		    so.addParam('quality','high');
		    so.addParam('bgcolor','#dee2de');
		    so.addParam('allowscriptaccess','sameDomain');
		    so.addParam('wmode','opaque');
		    so.addParam('allowfullscreen','true');
		    so.write('flashContent2');
		    $('flashContent2').setStyles({
		        'display': 'block',
		        'padding-top': 9
		    });
        } else if(Browser.Plugins.Flash.version > 10000){
            new Element('div#flashContent').inject(document.id('content_area'),'before');
            document.id('box').dispose();

            var swfVersionStr = "10.0.0";

            var xiSwfUrlStr = "/fileadmin/fom/home/playerProductInstall.swf";
            var flashvars = {};
            var params = {};
            params.quality = "high";
            params.bgcolor = "#dee2de";
            params.allowscriptaccess = "sameDomain";
            params.allowfullscreen = "true";
            params.wmode = 'opaque';

            var attributes = {};
            attributes.id = "ReFOM";
            attributes.name = "ReFOM";
            attributes.align = "middle";

            swfobject.embedSWF(
                file, "flashContent",
                "936", "353",
                swfVersionStr, xiSwfUrlStr,
                flashvars, params, attributes);

        	swfobject.createCSS("#flashContent", "display:block;text-align:left;");
        } else {
            if(Browser.ie6) { return; } // flash-detection von mootools klappt nicht richtig,
            if(Browser.ie7) { return; } // deswegen weden IE6,7 vom Flashheader vollkommen befreit.
            $('right_content').setStyle('margin-top', '-180px');
        }
    });
}

Element.implement({
    getChild: function(selector){
        var children = this.getChildren(selector);
        return (children.length>0 ? children[0] : null);
    },
    incrementZ: function(){
        var z = document.body.retrieve('_last-z-index',1000)+1;
        this.setStyle('z-index',z);
        document.body.store('_last-z-index',z);
        return this;
    },
    removeClasses: function(){
        [arguments].flatten().each(this.removeClass,this);
        return this;
    }
});
String.implement({
    toASCII: function(allowSpace){
        if(allowSpace == null) allowSpace=true;

        var out = '';
        for (var i=0;i<this.length;i++){
            var asciiNum = this.charCodeAt(i); //Decimal-Number
            if(
                (asciiNum >= 48 && asciiNum <= 57)  || //0-9
                (asciiNum >= 65 && asciiNum <= 90)  || //A-Z
                (asciiNum >= 97 && asciiNum <= 122) || //a-z
                (asciiNum == 32 && typeOf(allowSpace)!='string')
            ){
                out += this.charAt(i);
            } else if(asciiNum == 32 && typeOf(allowSpace)=='string'){
                out += allowSpace;
            }
        }
        return out;
    }
});
Array.implement({
    chunk: function(size){
        var ret = [];
        for(var i=0; i < (this.length/size).ceil(); i++){
            var start = i*size;
            ret.push(this.slice(start,start+size));
        }
        return ret;
    }
});
Number.implement({
    max: function(i){ return (this < i ? i : this); },
    min: function(i){ return (this > i ? i : this); },
    between: function(min,max) { return ( this>=min && this<=max ); }
})
