﻿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.getElementById('content').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 internal = window.open(
        this.getAttribute('href'), 
        "internal_a"+ (++popupNo_a),
        "width=480, height=640, top=20, left=40, scrollbars=yes, resizable=yes, status=yes"
    );
    internal.focus();
 
    return false;
}

function popUpExternal(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 external = window.open(
        this.getAttribute('href'), 
        "external_a"+ (++popupNo_a)
    );
    external.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;
        } else if (popList[i].className.search(/\bexternal\b/) != -1) {
            popList[i].onclick = popUpExternal;
        }
    }
}

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

var popupNo_a     = 0;
var tCurrentClass = '';

window.onload = init;
