function click (e) {
  if (!e)
    e = window.event;
  if ((e.type && e.type == "contextmenu") || (e.button && e.button == 2) || (e.which && e.which == 3)) {
    if (window.opera)
      window.alert("Sorry: Diese Funktion ist deaktiviert.");
    return false;
  }
}
if(!boo_debug) {
    if (document.layers)
      document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown = click;
    document.oncontextmenu = click;
}
var offsetfromcursorX=5;
var offsetfromcursorY=5;
var offsetdivfrompointerX=-15;
var offsetdivfrompointerY=0;

document.write('<div id="dhtmltooltip"></div>');
document.write('<img id="dhtmlpointer" style="height: 15px;" src="/img/tooltip.gif" />');

var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody()
{
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
    if (enabletip){
        var nondefaultpos=false
        var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
        var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
        //Find out how close the mouse is to the corner of the window
        var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
        var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

        var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
        var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

        var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

        //if the horizontal distance isn't enough to accomodate the width of the context menu
        if (rightedge<tipobj.offsetWidth){
            //move the horizontal position of the menu to the left by it's width
            tipobj.style.left=curX-tipobj.offsetWidth+"px"
            nondefaultpos=true
        }
        else if (curX<leftedge)
        tipobj.style.left="5px"
        else{
            //position the horizontal position of the menu where the mouse is positioned
            tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
            pointerobj.style.left=curX+offsetfromcursorX+"px"
        }
            //same concept with the vertical position --- modified
            if (bottomedge<tipobj.offsetHeight){
                tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
                nondefaultpos=true
            }
            else{
                tipobj.style.top=curY-offsetfromcursorY-offsetdivfrompointerY-tipobj.offsetHeight+"px"
                pointerobj.style.top=curY-offsetfromcursorY-1+"px"
            }
            
            tipobj.style.visibility="visible"
            if (!nondefaultpos)
                pointerobj.style.visibility="visible"
            else
                pointerobj.style.visibility="hidden"
    }
}

function hideddrivetip(){
    if (ns6||ie){
        enabletip=false
        tipobj.style.visibility="hidden"
        pointerobj.style.visibility="hidden"
        tipobj.style.left="-1000px"
        tipobj.style.backgroundColor=''
        tipobj.style.width=''
    }
}
document.onmousemove=positiontip

function toggle_menu(str_id,str_idpicture)
{
    var toggle = document.getElementById(str_id).style.display;
    
    if ( toggle == 'block' )
    {
        document.getElementById(str_id).style.display  = 'none';
        changepicture(document.getElementById(str_idpicture),false);
    }
    else
    {
        document.getElementById(str_id).style.display  = 'block';
        changepicture(document.getElementById(str_idpicture),true);
    }
}

function changepicture(obj_element,boo_hover) {
    var currentPic = obj_element.src;
    var int_lastPos = currentPic.lastIndexOf("_")+1;
    var fileEnding = currentPic.substr((currentPic.lastIndexOf(".")+1));
    var int_aktivCheck = currentPic.lastIndexOf("_aktiv");
    if(int_aktivCheck == -1) {
        if(boo_hover) {
            obj_element.src = currentPic.substr(0,int_lastPos)+'hover.'+fileEnding;
        } else {
            obj_element.src = currentPic.substr(0,int_lastPos)+'normal.'+fileEnding;
        }
    }
}

function create_bigPictureContainer(str_picpath,str_picturetext) {
    if(document.getElementById('bigpicture')) {
        document.getElementById('bigpicture_image').src = str_picpath;
        document.getElementById('bigpicture_image').alt = str_picturetext;
        document.getElementById('bigpicture_image').title = str_picturetext;
        document.getElementById('bigpicture_text').innerHTML = str_picturetext;
        document.getElementById('bigpicture').style.display = 'block';
    }
}

function remove_bigPictureContainer() {
    
    
    document.getElementById('bigpicture').style.display = 'none';
    document.getElementById('bigpicture_image').src = '';
}

document.observe("dom:loaded",function() {
    if($('maschinenKategorieReiter')) {
      /*
        var kategorienElements = $('maschinenKategorieReiter').down(0).childElements();
        
        var int_lenght = kategorienElements.length;
        kategorienElements.each(function(item,index){
            var int_zIndexInit = (int_lenght-index);
            
            item.setStyle({'zIndex':int_zIndexInit});
            
            item.childElements().each(function(subitem){
                subitem.observe('mouseover',function(event) {
                    event.stop();
                    
                    var int_zIndex = int_zIndexInit+2;
                    alert(int_zIndex);
                    item.setStyle({'zIndex':int_zIndex});
                });
                subitem.observe('mouseout',function(event) {
                    event.stop();
                    
                    var int_zIndex = parseInt(item.getStyle('zIndex'))-2;
                    item.setStyle({'zIndex':int_zIndex});
                });
            });
        });*/
    } 
});
