/* Spam protection
------------------------------------------------------------------------------------------------ */

function getAdr(prefix, postfix, text) {
    document.write('<a href="mailto:' + prefix + '@' + postfix + '">' + (text ? text.replace(/&quot;/g, '"').replace(/%EMAIL%/, prefix + '@' + postfix) : prefix + '@' + postfix) + '</a>');
}

function swapImage(element, newimage, direction) {
    var oldsrc = element.src
    element.src = newimage
    if (direction){
        element.onmouseout = null
        element.onmouseover = function (event) { swapImage(this, oldsrc); }
    }
    else{
        element.onmouseover = null;
        element.onmouseout = function (event) { swapImage(this, oldsrc, 1); }
    }
}

function CheckAufloesung() {
    var Hide = new Array('author', 'author_background', 'start_kassen', 'dot', 'tipps', 'tipps_suche', 'tipps_background', 'tipps_head', 'tipps_head2', 'linie_below_navigation', 'suche', 'dot', 'tipps_image');
    var Preferences = new Array();
    
    var StandardWidth = 996;
    var StandardHeight = 560;

    var obj;
    var content = document.getElementById('content');
    var head_images = document.getElementById('head_images');
    var content_background = document.getElementById('content_background');
    var start_container = document.getElementById('start_container');

    if (document.body.offsetWidth < StandardWidth || document.body.offsetHeight < StandardHeight) {
        if(content) {
            content.style.right='13px';
            content.style.right='0px';
        }

        if(head_images) {
            head_images.style.right='13px'
            head_images.style.right='14px'
        }

        if(start_container) {
            start_container.style.right='0px'
            start_container.style.bottom='40px'
        }

        if(content_background) {
            content_background.style.right='0px'
        }
    } else {
        if(content) {
            content.style.right='209px';
            content.style.right='210px';
        }

        if(head_images) {
            head_images.style.right='203px'
            head_images.style.right='204px'
        }

        if(start_container) {
            start_container.style.right='205px'
            start_container.style.bottom='-100px'
        }

        if(content_background) {
            content_background.style.right='210px'
        }
    }

    for(i=0;i<Hide.length;i++) {
        Preferences = Hide[i].split('+');
        if(!Preferences[1]) Preferences[1] = StandardWidth;
        if(!Preferences[2]) Preferences[2] = StandardHeight;

        obj = document.getElementById(Preferences[0])

        if(obj)
        {
            if (document.body.offsetWidth < Preferences[1] || document.body.offsetHeight < Preferences[2]) {
                obj.style.display = 'none'                
            } else {
                obj.style.display = 'block'
            }
        }
    }
}

window.onresize = CheckAufloesung;

function createMenu(id) {
    var nav = document.getElementById(id);
    if(nav)    {
        var uls = nav.getElementsByTagName('ul');
        for(var i = 0; i < uls.length; i++)
            new xMenu1(uls[i], 0, 'mouseover');
    }
}

function getRandom(to) {
    var v = Math.round(Math.random() * to);
    return (v == to ? 0 : v);
}

window.onload = function() {
    createMenu('treeNavigation');
    createMenu('treeNavigation2');
    if (rightpics) {
        x = getRandom(rightpics.length);
    
        var obj = document.getElementById('tipps_image');
        if (obj) {
            obj.src = rightpics[x];
            var tipp = document.getElementById('tipp_'+x)
            if (tipp) tipp.style.display = 'list-item';
        }
    }
    CheckAufloesung();
}

var newWnd;

function open_dia(pic, width, height) {
    if (newWnd)
        newWnd.close();
    newWnd = window.open('','tmp','height='+height+',width='+width+',scrollbars=no');
    var img_str='<html><head><title>Bild</title><style type="text/css">body{margin:0px;padding:0px;}</style></head><body margin=0 padding=0><img src="'+pic+'" alt=""></body></html>';

    if (newWnd.document)
        newWnd.document.write(img_str);
    newWnd.focus();
    return false;
}

function xMenu1(menu, mouseMargin, openEvent) {
    var isOpen = false;
    if (menu)
        xAddEventListener(menu.parentNode, openEvent, onOpen, false);

    function onOpen() {
        if (!isOpen) {
            xShow(menu);
            HideSelects(xPageX(menu), xPageY(menu), xWidth(menu), xHeight(menu));
            xAddEventListener(document, 'mousemove', onMousemove, false);
            isOpen = true;
        }
    }
    function onMousemove(ev) {
        var e = new xEvent(ev);
        contains = (xHasPoint(menu, e.pageX, e.pageY, -mouseMargin) || xHasPoint(menu.parentNode, e.pageX, e.pageY, -mouseMargin));
        if(!contains) {
            var submenus = menu.getElementsByTagName('UL');
            for(var i = 0; i < submenus.length; i++) {
                if(xHasPoint(submenus[i], e.pageX, e.pageY, -mouseMargin)) {
                    contains = true;
                    break;
                }
            }
        }
        if(!contains) {
            xHide(menu);
            HideSelects(0,0,0,0);
            xRemoveEventListener(document, 'mousemove', onMousemove, false);
            isOpen = false;
        }
    }
}

var sel;
function HideSelects(x,y,w,h) {
    if(xIE4Up && !xMac) {
        var selx,sely,selw,selh,i
        if(!sel) sel = document.getElementsByTagName("SELECT");
        for(i=0;i<sel.length;i++){
            selx=xPageX(sel[i]);
            sely=xPageY(sel[i]);
            selw=sel[i].offsetWidth;
            selh=sel[i].offsetHeight;
            sel[i].style.visibility = (selx+selw>x && selx<x+w && sely+selh>y && sely<y+h) ? "hidden" : "visible";
        }
    }
}




function ChangeActive(name) {
    active_name = name;
}

function ChangePic(name) {
    if(hover_name == name) {
        document.getElementById('big').src = common_dir + 'images/team_' + active_name + '.jpg';
        document.getElementById(name+'_image').src = common_dir + 'images/team_' + name + '_klein.jpg';

        var text = document.getElementById(active_name + '_text');

        document.getElementById('name').innerHTML = text.getElementsByTagName('h3')[0].innerHTML;
        document.getElementById('text').innerHTML = text.getElementsByTagName('span')[0].innerHTML;

        document.getElementById(active_name + '_image').src = common_dir + 'images/teamklein_hover.gif';
        hover_name = ''
    } else {
        if(active_name != name) {
            document.getElementById('big').src = common_dir + 'images/team_' + name + '.jpg';
            document.getElementById(name+'_image').src = common_dir + 'images/teamklein_hover.gif';

            var text = document.getElementById(name + '_text');

            document.getElementById('name').innerHTML = text.getElementsByTagName('h3')[0].innerHTML;
            document.getElementById('text').innerHTML = text.getElementsByTagName('span')[0].innerHTML;

            document.getElementById(active_name + '_image').src = common_dir + 'images/team_' + active_name + '_klein.jpg';
            hover_name = name
        }
    }
}
