// JavaScript Document

function newsmax(obj, max) {
  obj = obj.parentNode.parentNode;
  obj.className = (max) ? "newsEintrag max" : "newsEintrag";
}

                         
//		Settings: Define in Template
var setG = {						// general Settings
    'popupDiv':          'popup',       // string
    'popupContentDiv':   'popupInhalt',
    'popupBackground':   'popupHintergrund',
    'popupAjax':         'popupAjax',
    'popupClose':        'popupClose'  
}; 
                       

var general = {
    showPopup: function(toShow){
        if (toShow) {
            setG.popupDiv.setStyle('display', 'block');
            if (toShow == 'background') setG.popupBackground.effect.start(0.78);
            else setG.popupContentDiv.effect.start(1);
        } else { 
            if(setG.activeMeta) setG.activeMeta.removeClass('active');
            setG.popupDiv.setStyle('display', 'none');
            setG.popupBackground.effect.set(0);
            setG.popupContentDiv.effect.set(0);
        }
    },
    preparePopup: function(){
        // find elements
        setG.popupDiv = $(setG.popupDiv);
	    setG.popupContentDiv = $(setG.popupDiv.getElementById(setG.popupContentDiv));
	    setG.popupBackground = $(setG.popupDiv.getElementById(setG.popupBackground));
	    setG.popupClose = $(setG.popupDiv.getElementById(setG.popupClose)); 
	    
	    // prepare effects
	    setG.popupContentDiv.effect = new Fx.Style( setG.popupContentDiv, 'opacity', {
        	duration: 800,
        	wait: true
        });
        setG.popupBackground.effect = new Fx.Style( setG.popupBackground, 'opacity', {
        	duration: 800,
        	wait: true
        });
        
        // init Settings
        general.showPopup(false);
        
        setG.popupBackground.onclick = function(evt) {
            general.showPopup(false);
        };
        setG.popupClose.onclick = function(evt) {
            general.showPopup(false);
        };
    /*    $('navContainer').onclick = function(evt) {
            general.showPopup(false);
        };
        console.log($('navContainer'));       */
    },
    metaRollover: function(){
        // find elements
        menuItems = $$('a.ajaxMeta');
        menuItems.each(function(elA){
            elA.onclick = function(evt){
                if(setG.activeMeta) setG.activeMeta.removeClass('active');
                if(setG.activeMeta == elA) { 
                    setG.popup.fireEvent('showBg');
                    setG.popup.fireEvent('showIt');
                }
                setG.activeMeta = elA;
                elA.addClass('active');
            };
        });
    },                        
	init: function(){
	    // remove 'noJS' marks to avoid disturbing CSS
		removeClassHere = $$('.noJS');
		removeClassHere.removeClass('noJS');
		
		// set navbar opacity 
//		$('navBackground').setOpacity(0.6);

        general.preparePopup(true);                                                
        general.metaRollover(true);
        
  //      setG.popup = setG.popupDiv.getElementById(setG.popupAjax);
        setG.popup = $($('popup').getElementById('popupAjax'));                
        setG.popup.addEvent('showBg', function(){general.showPopup('background');});
        setG.popup.addEvent('showIt', function(){general.showPopup(true);});
        setG.popup.addEvent('hideIt', function(){general.showPopup(false);});
    //    setG.popup.fireEvent('showIt'); 


        // target für externe Links auf '_blank' setzen
        $$('a').each(function(elA){                  
            if (!$defined(elA.getAttribute('target')) && $defined(elA.hreff = elA.getAttribute('href')) && elA.hreff.test("//", "i") && !elA.hreff.test(window.location.host, "i")) elA.setAttribute('target', '_blank');
        });        
	}
	
}