// xModalDialog r2, Copyright 2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL


//xAddEventListener(window, 'load', function() {
	//	    if (document.getElementById && document.createElement && document.body.appendChild) {


		//	    new xModalDialog('idMD1');
			//    xModalDialog.grey.onclick=function(){xModalDialog.instances.idMD1.hide();}


			  //  }})


function getPicSize(ww,wh,pic)
{

var picw=pic.width;
var pich=pic.height;
if(picw<ww && pich<wh)
{

pic.width=picw;
pic.height=pich;

}
else
{
	
		
		if((picw/ww)>(pich/wh))
		{
		
		pic.width=ww-100;		
		pic.height=(pich*((ww-100)/picw));
		}
		if((picw/ww)<(pich/wh))
		{
		
		pic.height=wh-100;		
		pic.width=(picw*((wh-100)/pich));
		}
	
}

return pic;


}





function vollbild(picid)
{
ds = xDocSize();
$('body1').insert("<div id='DialogGreyElement' class='xModalDialogGreyElement'></div>");
newObj=$('DialogGreyElement');
xMoveTo(newObj, 0, 0);
xResizeTo(newObj, ds.w, ds.h);
newObj.style.zindex=1000;
$('body1').insert("<div id='dlgwait' class='xdlgwait'><h4>Bitte warten...</h4><img src='pics/warten.gif'></div>");
newObj=$('dlgwait');
xResizeTo(newObj, 200, 200);
xMoveTo(newObj, xScrollLeft()+(xClientWidth()-newObj.offsetWidth)/2,xScrollTop()+(xClientHeight()-newObj.offsetHeight)/2);

newObj.style.zindex=1001;

var bild = new Image();
bild.onload=function(){weiter(picid);};
bild.src='data/pics/big/'+picid+'.jpg';

//var masse=picwidth + " X " +picheight + " win: " + ds.w + " X " + ds.h + " Verh: " + (ds.h/ds.w);








}






function weiter(picid)
{
//alert("Hier"+picid);
$('dlgwait').remove();
ds = xDocSize();
var bild = new Image();
bild.src='data/pics/big/'+picid+'.jpg';
var cw=xClientWidth();
var ch=xClientHeight();
bild=getPicSize(cw,ch,bild);

var imgtxt = "<img src='data/pics/big/"+picid+".jpg'  width='"+bild.width+"' height='"+bild.height+"'>"



//alert(imgtxt);

$('body1').insert("<div id='ModalPictureDiv' class='xModalPictureDiv'><div id='closeBtn' onclick='xModalDialogremove()'>Schlie&szlig;en</div>"+imgtxt+"</div>");
newObj=$('ModalPictureDiv');
//newObj.insert(bild);

xMoveTo(newObj, xScrollLeft()+(xClientWidth()-newObj.offsetWidth)/2,xScrollTop()+(xClientHeight()-newObj.offsetHeight)/2);
newObj.style.zindex=1002;


}





function xModalDialog(innerHtml) // Object Prototype
{
  /*@cc_on @if (@_jscript_version >= 5.5) @*/ //  not supported in IE until v5.5
  //this.dialog = xGetElementById(sDialogId);
 // xModalDialog.instances[sDialogId] = this;
  
  
  var e = xModalDialog.grey;
 if (!e) { // only one per page
    e = document.createElement('div');
    e.className = 'xModalDialogGreyElement';
    e.setAttribute("id","DialogGreyElement");
    document.body.appendChild(e);
    f=document.createElement('div');
    f.className = 'xModalPictureDiv';
    f.setAttribute("id","ModalPictureDiv");
    document.body.appendChild(f);
    
    sp=document.createElement('span');
    
    sp.setAttribute("id","closeBtn");
    
    //
    
    txt=document.createTextNode("Close");
    sp.appendChild(txt);
    
    
    
    f.appendChild(sp);
    e.style.zindex=1000;
    f.style.zindex=1001;
    ds = xDocSize();
    xMoveTo(e, 0, 0);
   	xResizeTo(e, ds.w, ds.h);
    xMoveTo(f, xScrollLeft()+(xClientWidth()-f.offsetWidth)/2,xScrollTop()+(xClientHeight()-f.offsetHeight)/2);
   
   sp.onclick=function(){xModalDialogremove()};
    //sp.setAttribute('onclick','xModalDialogremove()');
   // alert("Hallo");
    
    
  }
  /*@end @*/
}

// Public Methods



function xModalDialogremove()
{
$('closeBtn').remove();
$('DialogGreyElement').remove();
$('ModalPictureDiv').remove();


}





