var js_popup =
{
settings :
{

triggerCssClass : "bildergallerie",
parentDiv : {
cssID : "js-popup"
},

popupBox : {
cssID : "js-popup-box"
},

overlayBackground : {
src_png : "img/overlay.png",
src_blank_gif : "img/blank.gif"
},

fullViewImage : {
cssID : "js-popup-image"
},

waitAnimation : {
src : "img/sanduhr.gif",
alt : "Sanduhr",
cssID : "js-popup-wait"
},

closeIcon : {
src : "img/x-beenden.gif",
alt : "schlie&szlig;en",
cssID : "js-popup-close"
},

resizeIcon : {
src_resize : "img/resize.gif",
alt_resize : "verkleinern",
src_fullSize : "img/resize_full.gif",
alt_fullSize : "volle Gr&ouml;&szlig;e",
cssID : "js-popup-resize"
},

waitText : "Bild wird geladen...",
altCaption : "..."
},




controls :
{
oversize : "resize",
boxWidth : 90,
boxHeight : 90,
boxMaxWidth : 100,
boxMaxHeight : 100,
winInnerWidth : 100,
winInnerHeight : 100
},




htmlElements : { },




functions :
{

preload : function (linkObj)
{

js_popup.preloadImage = new Image();
js_popup.preloadImage.src = linkObj.href;

var html_code = js_popup.settings.waitText
+ ' <img src="' + js_popup.settings.waitAnimation.src
+ '" alt="' + js_popup.settings.waitAnimation.alt
+ '" id="' + js_popup.settings.waitAnimation.cssID
+ '" />';

js_popup.htmlElements.box.innerHTML = html_code;
js_popup.controls.boxWidth = 200;
js_popup.controls.boxHeight = 50;

js_popup.functions.center();

js_popup.preloadImage.caption = '';

var caption = linkObj.getElementsByTagName("img")[0].getAttribute("alt");
js_popup.preloadImage.caption = (caption && caption != "") ? caption : js_popup.settings.altCaption;

js_popup.htmlElements.div.style.display = "block";

if(js_popup.preloadImage.width > 0)
{

js_popup.functions.display();
}
else
{

js_popup.functions.addEvent("load", js_popup.preloadImage, js_popup.functions.display);
js_popup.functions.addEvent("error", js_popup.preloadImage, js_popup.functions.display);
}

return false;
},


display : function ()
{

js_popup.htmlElements.box.style.display = "none";


js_popup.controls.boxWidth = 90;
js_popup.controls.boxHeight = 90;


var html_code = '<img id="' + js_popup.settings.closeIcon.cssID + '" src="' + js_popup.settings.closeIcon.src + '" alt="' + js_popup.settings.closeIcon.alt + '" />';

if(js_popup.preloadImage.width > js_popup.controls.boxWidth || js_popup.preloadImage.height > js_popup.controls.boxHeight)
{
js_popup.controls.boxWidth = js_popup.preloadImage.width;
js_popup.controls.boxHeight = js_popup.preloadImage.height;
}

if(js_popup.controls.boxWidth > js_popup.controls.boxMaxWidth || js_popup.controls.boxHeight > js_popup.controls.boxMaxHeight)
{
html_code += '<img src="';
html_code += (js_popup.controls.oversize == "resize") ? js_popup.settings.resizeIcon.src_fullSize : js_popup.settings.resizeIcon.src_resize;
html_code += '" alt="';
html_code += (js_popup.controls.oversize == "resize") ? js_popup.settings.resizeIcon.alt_fullSize : js_popup.settings.resizeIcon.alt_resize;
html_code += '" id="' + js_popup.settings.resizeIcon.cssID + '" />';

if(js_popup.controls.oversize == "resize")
{
var ratio = js_popup.preloadImage.width / js_popup.preloadImage.height;
var scale = js_popup.preloadImage.width / js_popup.controls.boxMaxWidth;
if(js_popup.preloadImage.height / scale > js_popup.controls.boxMaxHeight) scale = js_popup.preloadImage.height / js_popup.controls.boxMaxHeight;

js_popup.controls.boxWidth = Math.ceil(js_popup.preloadImage.width / scale);
js_popup.controls.boxHeight = Math.ceil(js_popup.preloadImage.height / scale);
}
}

js_popup.functions.center();

html_code += '<img id="' + js_popup.settings.fullViewImage.cssID + '" alt="' + js_popup.preloadImage.caption + '" />';
if(js_popup.preloadImage.caption != "") html_code += '<br />' + js_popup.preloadImage.caption;

js_popup.htmlElements.box.innerHTML = html_code;

js_popup.htmlElements.fullViewImage = document.getElementById(js_popup.settings.fullViewImage.cssID);
js_popup.htmlElements.fullViewImage.src = js_popup.preloadImage.src;
js_popup.htmlElements.fullViewImage.width = js_popup.controls.boxWidth;
js_popup.htmlElements.fullViewImage.height = js_popup.controls.boxHeight;

js_popup.htmlElements.box.style.display = "block";

js_popup.htmlElements.resizeIcon = document.getElementById(js_popup.settings.resizeIcon.cssID);
if (js_popup.htmlElements.resizeIcon)
{
js_popup.functions.addEvent("click", js_popup.htmlElements.resizeIcon, js_popup.functions.toggleResize);
js_popup.functions.addEvent("mouseover", js_popup.htmlElements.resizeIcon,
function ()
{ this.style.display = "inline"; } );
js_popup.htmlElements.resizeIcon.style.display = "none";

js_popup.functions.addEvent("mouseover", js_popup.htmlElements.fullViewImage,
function ()
{ document.getElementById(js_popup.settings.resizeIcon.cssID).style.display = "inline"; } );

js_popup.functions.addEvent("mouseout", js_popup.htmlElements.fullViewImage,
function ()
{ document.getElementById(js_popup.settings.resizeIcon.cssID).style.display = "none"; } );
}

return false;
},




center : function ()
{
var x_pos = 0;
var y_pos = 0;

if(window.innerWidth)
{
x_pos = Math.ceil((js_popup.controls.winInnerWidth - js_popup.controls.boxWidth)/2 + window.pageXOffset);
y_pos = Math.ceil((js_popup.controls.winInnerHeight - js_popup.controls.boxHeight)/2 + window.pageYOffset);
}
else
{
x_pos = Math.ceil((js_popup.controls.winInnerWidth - js_popup.controls.boxWidth)/2 + js_popup.IE.scrollLeft);
y_pos = Math.ceil((js_popup.controls.winInnerHeight - js_popup.controls.boxHeight)/2 + js_popup.IE.scrollTop);
}

x_pos -= 15;
y_pos -= 15;

if(x_pos < 0) x_pos = 0;
if(y_pos < 0) y_pos = 0;

js_popup.htmlElements.box.style.left = x_pos + "px";
js_popup.htmlElements.box.style.top = y_pos + "px";

return false;
},

toggleResize : function (e)
{
if(!e) e = window.event;
if(e.stopPropagation) e.stopPropagation();
e.cancelBubble = true;

js_popup.controls.oversize = (js_popup.controls.oversize == "resize") ? "fullView" : "resize";
js_popup.functions.display();

return false;
},

hide : function ()
{
js_popup.htmlElements.div.style.display = "none";

return false;
},

getBrowserDimensions : function ()
{
if(window.innerWidth)
{
js_popup.controls.winInnerWidth = window.innerWidth;
js_popup.controls.winInnerHeight = window.innerHeight;
}
else
{
js_popup.controls.winInnerWidth = js_popup.IE.offsetWidth;
js_popup.controls.winInnerHeight = js_popup.IE.offsetHeight;
}

js_popup.controls.boxMaxWidth = js_popup.controls.winInnerWidth - 50;
js_popup.controls.boxMaxHeight = js_popup.controls.winInnerHeight - 50;

return false;
},

addEvent : function (ev, obj, handle)
{
if(navigator.userAgent.toLowerCase().lastIndexOf("msie") < 0)
{
obj.addEventListener(ev, handle, false);
obj.addEventListener(ev, handle, false);
}
else
{
obj.attachEvent("on" + ev, handle);
obj.attachEvent("on" + ev, handle);
}
},

removeEvent : function (ev, obj, handle)
{
if(navigator.userAgent.toLowerCase().lastIndexOf("msie") < 0)
{
obj.removeEventListener(ev, handle, false);
obj.removeEventListener(ev, handle, false);
}
else
{
obj.detachEvent("on" + ev, handle);
obj.detachEvent("on" + ev, handle);
}
},

init : function ()
{
js_popup.IE = (document.compatMode && document.compatMode == "CSS1Compat") ? document.documentElement : document.body || null;

js_popup.functions.getBrowserDimensions();

js_popup.htmlElements.div = document.getElementById(js_popup.settings.parentDiv.cssID);
if(!js_popup.htmlElements.div)
{
js_popup.htmlElements.div = document.createElement("div");
js_popup.htmlElements.div.id = js_popup.settings.parentDiv.cssID;
document.body.appendChild(js_popup.htmlElements.div);

js_popup.htmlElements.div.style.display = "none";
js_popup.htmlElements.div.style.position = "absolute";
js_popup.htmlElements.div.style.backgroundImage = "url(" + js_popup.settings.overlayBackground.src_png + ")";

js_popup.htmlElements.box = document.createElement("div");
js_popup.htmlElements.box.id = js_popup.settings.popupBox.cssID;
js_popup.htmlElements.box.style.position = "absolute";

js_popup.htmlElements.div.appendChild(js_popup.htmlElements.box);
js_popup.functions.addEvent("click", js_popup.htmlElements.div, js_popup.functions.hide);
js_popup.functions.addEvent("click", js_popup.htmlElements.box, js_popup.functions.hide);

if(typeof(js_popup.htmlElements.div.style.filter) != "undefined")
{
js_popup.htmlElements.div.style.backgroundImage = "url(" + js_popup.settings.overlayBackground.src_blank_gif + ")";
js_popup.htmlElements.div.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'
+ js_popup.settings.overlayBackground.src_png + '", sizingMethod="scale")';
}
}

if(window.innerWidth && typeof(window.scrollMaxY))
{
js_popup.htmlElements.div.style.width = document.body.scrollWidth + "px";
js_popup.htmlElements.div.style.height = window.innerHeight + window.scrollMaxY + "px";
}

if(js_popup.IE.scrollWidth)
{
js_popup.htmlElements.div.style.width = js_popup.IE.scrollWidth + "px";
js_popup.htmlElements.div.style.height = js_popup.IE.scrollHeight + "px";
}

var allElements = document.getElementsByTagName("*");

var allGalleries = new Array();
for (var index_e = 0; index_e < allElements.length; index_e++)
{
if(allElements[index_e].className.indexOf(js_popup.settings.triggerCssClass) != -1)
{
var test = "," + allElements[index_e].className.split(" ").join(",") + ",";
if(test.indexOf("," + js_popup.settings.triggerCssClass + ",") != -1) allGalleries.push(allElements[index_e]);
}
}

for (var index_g = 0; index_g < allGalleries.length; index_g++)
{
var allLinks = allGalleries[index_g].getElementsByTagName("a");

for (var index_a = 0; index_a < allLinks.length; index_a++)
{
if(allLinks[index_a].getElementsByTagName("img")[0])
allLinks[index_a].onclick = function () { return js_popup.functions.preload(this); };
}
}
}
}
}

js_popup.functions.oldOnLoad = window.onload;
js_popup.functions.oldResize = window.onresize;
window.onload = function () { if(js_popup.functions.oldOnLoad) js_popup.functions.oldOnLoad(); js_popup.functions.init(); }
window.onresize = function () { if(js_popup.functions.oldResize) js_popup.functions.oldResize(); js_popup.functions.init(); }

