﻿function tGetLink(node)
{
    var linkList = node.getElementsByTagName('a');
    
    for (var i = 0; i < linkList.length; i++) {
        if (linkList[i].className.search(/\bmore\b/) != -1) {
            return linkList[i].getAttribute('href');
        }
    }
    
    return false;
}

function tGetPopupLink(node)
{
    var linkList = node.getElementsByTagName('a');
    
    for (var i = 0; i < linkList.length; i++) {
        if (linkList[i].className.search(/\bmore\b/) != -1 && linkList[i].className.search(/\bpopup\b/) != -1) {
            return linkList[i].getAttribute('href');
        }
    }
    
    return false;
}

function tHover(e)
{
    if (!e) {
        e = window.event;
    }
    
    if (tGetLink(this)) {
        if (e.type.toLowerCase() == 'mouseover') {
            this.style.cursor = 'pointer';
            window.status = tGetLink(this);
            
            tCurrentClass = this.className;
        
            if (this.parentNode.id == 'column') {
                this.className = tCurrentClass + ' hover';
            } else {
                this.className = tCurrentClass + ' hover';
            }
        } else if (e.type.toLowerCase() == 'mouseout') { 
            window.status = '';
        
            this.className = tCurrentClass;
        }
    }
}
        
function tClick(e)
{
    if (!e) {
        e = window.event;
    }
    
    var link, popup;
    
    if (link = tGetPopupLink(this)) {
        if (link.search(/buendnis-fuer-kinder/) != -1) {
            popup = window.open(
                tGetPopupLink(this),
                "PopUp",
                "width=720,scrollbars=yes,resizable=yes,status=yes"
            );
        } else {
            popup = window.open(
                tGetPopupLink(this),
                "PopUp"
            );
        }
        popup.focus();
    } else if (tGetLink(this)) {
        window.location.href = tGetLink(this);
    }
    
    return false;
}

function tAttach()
{
    var tList = document.getElementsByTagName('div');

    for (var i = 0; i < tList.length; i++) {
        if (tList[i].className.search(/\bteaser\b/) != -1) {
            tList[i].onmouseover = tHover;
            tList[i].onmouseout  = tHover;
            tList[i].onclick     = tClick;
        }
    }
}

function popUp(e)
{
    if (!e) {
        e = window.event;
    }

    // --> onClick-Event abbrechen (für Popup-Links innerhalb von Teasern)
    if (e.stopPropagation) {
        e.stopPropagation();
    } else {
        e.cancelBubble = true;
    } // <--

    var popup;
    
    if (this.getAttribute('href').search(/buendnis-fuer-kinder/) != -1) {
        popup = window.open(
            this.getAttribute('href'), 
            "PopUp",
            "width=720,scrollbars=yes,resizable=yes,status=yes"
        );
    } else {
        popup = window.open(
            this.getAttribute('href'), 
            "PopUp"
        );
    }
    popup.focus();
 
    return false;
}
    
function popAttach()
{
    var popList = document.getElementsByTagName('a');
    var i = -1;
    for (var i = 0; i < popList.length; i++) {
        if (popList[i].className.search(/\bpopup\b/) != -1) {
            popList[i].onclick = popUp;
        }
    }
}

function sHintsToggle(e)
{
    var sHint  = document.getElementById('s-hint');
    var sHints = document.getElementById('s-hints');

    if (sHints.className == 'inactive') {
        sHint.className  = 'active';
        sHints.className = 'active';
    } else {
        sHint .className = 'inactive';
        sHints.className = 'inactive';
    }
}

function sAttach()
{

    if (document.getElementById('s')) {
        document.getElementById('s').focus();
    }
    
    if (document.getElementById('s-hint') && document.getElementById('s-hints')) {
        document.getElementById('s-hint').className  = 'inactive';
        document.getElementById('s-hints').className = 'inactive';
        
        document.getElementById('s-hint').onclick    = sHintsToggle;
    }
}


function init()
{
    tAttach();
    popAttach();
    sAttach();
}

var tCurrentClass = '';
window.onload = init;
