// Makes all links with rel=ext open in a new window
function makeExternalLinks() {

    if(document.getElementsByTagName) {

        var as = document.getElementsByTagName('a');

        for(var i=0;i < as.length; i++) {
           var thisTag = as[i];
            
           if(thisTag.getAttribute('href') && thisTag.getAttribute('rel') == "external") {
                
                thisTag.target = "_blank";
            }
            
            if(thisTag.getAttribute('href') && thisTag.getAttribute('rel') == "pop") {
                            
                            thisTag.href= "javascript:disclaimWin('http://miranda.hemscott.com/legal/cust_disclaim.htm')";
            }
            
            if(thisTag.getAttribute('href') && thisTag.getAttribute('rel') == "textpop") {
	                                var href1=thisTag.getAttribute('href');
	                                thisTag.href= "javascript:textPopUp('"+href1+"');"
            }
        }
    }
}

// api_addEvent() 
// Gets around the problem of having multiple onload handlers
// http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
// http://www.quirksmode.org/js/events_advanced.html

function api_addEvent(obj, evType, fn) { 

    // W3C type of event registration model
    if (obj.addEventListener) { 
        obj.addEventListener(evType, fn, false); 
        return true; 

    // MS event registration model 
    } else if (obj.attachEvent) { 
        return obj.attachEvent("on"+evType, fn); 
    
    // Bad browsers that can't do either
    } else { 
        return false; 
    } 
}


api_addEvent(window, 'load', makeExternalLinks);


function disclaimWin(page) {
         OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,height=505,width=658,location=no,scrollbars=yes,resizable=no,status=no,left=100,top=100");
}

function textPopUp(page) {
         OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,height=350,width=650,location=no,scrollbars=no,resizable=no,status=no,left=100,top=100");
}

/***********************************************
* Zap_ImgPop JavaScript Source
* Author: Tom Koehler
* Author URI: http://www.zappelfillip.de
* Plugin URI: http://www.zappelfillip.de/index.php/2005-10-25/zap_imgpop/
*
* Based on:
* Image Thumbnail viewer- ? Dynamic Drive (www.dynamicdrive.com)
* Last updated Sept 26th, 03'. This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code

***********************************************/
// true if you want images shrinked when showed. false shows images in original size
resize = false;

var ie=document.all;
var ns6=document.getElementById&&!document.all;
// If resize=true you can specify maxwidth and maxheight of the shown image. Use 0 if you want images shrinked to browser size, so that they are always displayed completely
maxwidth = 0;
maxheight = 0;

function ietruebody(){
  return (document.compatMode && document.compatMode!="BackCompat" && !window.opera)? document.documentElement : document.body;
}



function enlarge(pluginurl, which, description, e, imgwidth, imgheight,x,y) {

  if (ie||ns6) {

    preload = new Image();
    preload.src = which;

    plugurl = '.';
    beschr = description;
    crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage;


    position(e,x,y);


    crossobj.innerHTML='<div id="img-shadow"><table id="tabelle" border="0" cellpadding="0" cellspacing="4"><tr><td valign=middle id="dragbar"><div style="float:left;" id="dragbar">'+description+'</div><img style="float:right;" src="images/interface/closebutton.gif" id="close" onclick="closepreview();" alt="close" title="close" /></td></tr><tr><td><img id="picture" src="images/interface/loading.gif" alt="Image View" /></td></tr></table></div>';
    crossobj.style.visibility="visible";

    setTimeout("loadpicture()", 200);

    return false;
  }
  else //if NOT IE 4+ or NS 6+, simply display image in full browser window
    return true;
}

function position(e,x,y) {
    var posx = 0;
    var posy = 0;
    if (!e) var e = window.event;
    if (e.pageX || e.pageY)     {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY)    {
        posx = e.clientX + document.body.scrollLeft
            + document.documentElement.scrollLeft;
        posy = e.clientY + document.body.scrollTop
            + document.documentElement.scrollTop;
    }
    // posx and posy contain the mouse position relative to the document
    // Do something with this information
    crossobj.style.left=posx+x+"px";
    crossobj.style.top=posy+y+"px";

}

function loadpicture() {
  if(preload.complete) {
    originalWidth = preload.width;
    originalHeight = preload.height;

        if(maxwidth == 0) insideWidth=ns6 ? window.innerWidth-47 : ietruebody().clientWidth-47;
        else insideWidth=maxwidth;
        if(maxheight == 0) insideHeight=ns6 ? window.innerHeight-55 : ietruebody().clientHeight-55;
        else insideHeight=maxheight;

    if(((preload.width > insideWidth) || (preload.height > insideHeight)) && resize) {
            showPop();

        }
        else {
            imgwidth=preload.width;
            imgheight=preload.height;

            crossobj.style.visibility="hidden";
            //position(imgwidth,imgheight);

            picture1=document.getElementById? document.getElementById("picture") : document.all.picture;
            picture1.src = preload.src;
            picture1.style.width=preload.width+"px";
            picture1.style.height=preload.height+"px";
            crossobj.style.visibility="visible";


        }

  }
  else { setTimeout("loadpicture()", 200) }
}




function makeSmaller() {
    imgwidth=preload.width;
    imgheight=preload.height;
    crossobj.style.visibility="hidden";
//  position(imgwidth,imgheight);
  crossobj.innerHTML='<div id="img-shadow"><table id="tabelle" border="0" cellpadding="0" cellspacing="4"><tr><td valign=middle id="dragbar"><div style="float:left;" id="dragbar">'+beschr+'</div><img style="float:right;" src="images/interface/closebutton.gif" id="close" onclick="closepreview();" onmouseover="showhover(\''+plugurl+'\');" onmouseout="showdefault(\''+plugurl+'\');" onmousedown="showpush(\''+plugurl+'\');" alt="close" title="close" /></td></tr><tr><td><img id="picture" src="'+preload.src+'" alt="Image View" title="Click to zoom in" onclick="makeBigger()" style="cursor:url('+plugurl+'/cur/plus.cur)" /></td></tr></table></div>';
  picture1=document.getElementById? document.getElementById("picture") : document.all.picture;
    picture1.style.width=preload.width+"px";
    picture1.style.height=preload.height+"px";
  crossobj.style.visibility="visible";
}

function makeBigger() {
    imgwidth=originalWidth;
    imgheight=originalHeight;
    crossobj.style.visibility="hidden";

    crossobj.innerHTML='<div id="img-shadow"><table id="tabelle" border="0" cellpadding="0" cellspacing="4"><tr><td valign=middle id="dragbar"><div style="float:left;" id="dragbar">'+beschr+'</div><img style="float:right;" src="images/interface/closebutton.gif" id="close" onclick="closepreview();" onmouseover="showhover(\''+plugurl+'\');" onmouseout="showdefault(\''+plugurl+'\');" onmousedown="showpush(\''+plugurl+'\');" alt="close" title="close" /></td></tr><tr><td><img id="picture" src="'+preload.src+'" alt="Image View" title="Click to zoom out" onclick="makeSmaller()" style="cursor:url('+plugurl+'minus.cur)" /></td></tr></table></div>';
    picture1=document.getElementById? document.getElementById("picture") : document.all.picture;
    picture1.style.width=originalWidth+"px";
    picture1.style.height=originalHeight+"px";
    var horzpos=ns6? pageXOffset+15 : ietruebody().scrollLeft+15
    var vertpos=ns6? pageYOffset : ietruebody().scrollTop
//  crossobj.style.left=horzpos+"px";
//  crossobj.style.top=vertpos+15+"px";
    crossobj.style.visibility="visible";
}

function showPop() {
    ratio = preload.width / preload.height;

    if(maxwidth == 0) insideWidth=ns6 ? window.innerWidth-47 : ietruebody().clientWidth-47;
    else insideWidth=maxwidth;
    if(maxheight == 0) insideHeight=ns6 ? window.innerHeight-55 : ietruebody().clientHeight-55;
    else insideHeight=maxheight;
    if((maxwidth != 0) && (maxheight != 0)) {
        insideWidth=maxwidth;
        insideHeight=maxheight;
    }

    if(preload.width > insideWidth) {
        preload.width = insideWidth;
        preload.height = preload.width / ratio;
        if(preload.height > insideHeight) {
            preload.height = insideHeight;
            preload.width = preload.height * ratio;
        }
    }
    else if(preload.height > insideHeight) {
        preload.height = insideHeight;
        preload.width = preload.height * ratio;
        if(preload.width > insideWidth) {
            preload.width = insideWidth;
            preload.height = preload.width / ratio;
        }
    }


    imgwidth=preload.width;
    imgheight=preload.height;
    crossobj.style.visibility="hidden";

  crossobj.innerHTML='<div id="img-shadow"><table id="tabelle" border="0" cellpadding="0" cellspacing="4"><tr><td valign=middle id="dragbar"><div style="float:left;" id="dragbar">'+beschr+'</div><img style="float:right;" src="images/interface/closebutton.gif" id="close" onclick="closepreview();" onmouseover="showhover(\''+plugurl+'\');" onmouseout="showdefault(\''+plugurl+'\');" onmousedown="showpush(\''+plugurl+'\');" alt="close" title="close" /></td></tr><tr><td><img id="picture" src="'+preload.src+'" alt="Image View" title="Click to zoom in" onclick="makeBigger()" style="cursor:url('+plugurl+'/cur/plus.cur)" /></td></tr></table></div>';
  picture1=document.getElementById? document.getElementById("picture") : document.all.picture;
    picture1.style.width=preload.width+"px";
    picture1.style.height=preload.height+"px";
  crossobj.style.visibility="visible";
}



function showhover(pluginurl){
    closepicture1=document.getElementById? document.getElementById("close") : document.all.close;
  closepicture1.src=pluginurl+"closeover.gif"
}


function showdefault(pluginurl){
    closepicture1=document.getElementById? document.getElementById("close") : document.all.close;
  closepicture1.src=pluginurl+"closebutton.gif"
}


function showpush(pluginurl){
    closepicture1=document.getElementById? document.getElementById("close") : document.all.close;
  closepicture1.src=pluginurl+"closepush.gif"
}


function closepreview(){
  crossobj.style.visibility="hidden"
}


function drag_drop(e){
  if (ie&&dragapproved){
    crossobj.style.left=tempx+event.clientX-offsetx+"px"
    crossobj.style.top=tempy+event.clientY-offsety+"px"
  }
  else if (ns6&&dragapproved){
    crossobj.style.left=tempx+e.clientX-offsetx+"px"
    crossobj.style.top=tempy+e.clientY-offsety+"px"
  }
  return false
}


function initializedrag(e){
  if (ie&&event.srcElement.id=="dragbar"||ns6&&e.target.id=="dragbar"){
    offsetx=ie? event.clientX : e.clientX
    offsety=ie? event.clientY : e.clientY

    tempx=parseInt(crossobj.style.left)
    tempy=parseInt(crossobj.style.top)

    dragapproved=true
    document.onmousemove=drag_drop
  }

}


document.onmousedown=initializedrag
document.onmouseup=new Function("dragapproved=false")

// <div id="showimage"></div> erzeugen

function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
        window.onload = func;
    } else {
        window.onload = function(){
        oldonload();
        func();
        }
    }

}

addLoadEvent(makeDiv);  // makeDiv aufrufen onLoad

function makeDiv() {

  var DerBody = document.getElementsByTagName("body").item(0);
  var objImagediv = document.createElement("div");
  objImagediv.setAttribute('id','showimage');
  DerBody.appendChild(objImagediv);

}
