// global js
window.onscroll = doFloating;
window.onresize = doFloating;
var floatingFunc = null;
function doFloating() {
	if (floatingFunc != null) {
		this[floatingFunc]();
	}
}

var quicks = [];
function addQuickPDF(file, text, size){
var o = new Object();
o.file = file;
o.text = text;
o.size = size;
quicks.push(o);
}
function fillQuickPdf(){
qpdf = document.getElementById('quickpdfcontent'); if(qpdf){ for(i = 0; i < quicks.length; ++i){ var x = quicks[i];
var newPdf = document.createElement("div");
newPdf.setAttribute("onclick", "window.open('" + x.file + "');");
newPdf.setAttribute("class", "quickpdfline");
var pdfInner = document.createElement("div");
pdfInner.setAttribute("class", "quickpdfline_inner");
pdfInner.appendChild(document.createTextNode(x.text));
var pdfInnerSize = document.createElement("div");
pdfInnerSize.setAttribute("class", "quickpdfline_size");
pdfInnerSize.appendChild(document.createTextNode(" (" + x.size + ")"));
pdfInner.appendChild(pdfInnerSize);
newPdf.appendChild(pdfInner);
qpdf.appendChild(newPdf); }}
}

//set onload function
if(window.addEventListener){
	window.addEventListener("load", function(){ loadJS();}, false);
}
else{
	window['onload'] = function(){ loadJS();};
}

function loadJS(){
	linkify();
}

function linkify(){
	//find eMail-addresses and links that don't have an a-href around them
	var content = document.getElementById("rightpart");
	if(content){
		linkifyChildren(content);
	}
}

function linkifyChildren(content){
	for(var i = 0; i < content.childNodes.length; ++i){
		var c = content.childNodes[i];
		if(c.nodeName.toLowerCase() == "a")
			continue;
		else if(c.nodeName.toLowerCase() == "#text"){
			if(c.nodeValue.match(/^.*@.*[.].*$/)){
				addLink(c, "mailto:" + c.nodeValue);
			}
			else if(c.nodeValue.match(/^(http:|https:)\S*$/)){
				addLink(c, c.nodeValue);
			}
			else if(c.nodeValue.match(/^www[.]\S*$/)){
				addLink(c, "http://" + c.nodeValue);
			}
		}
		else if(c.childNodes)
			linkifyChildren(c);
	}
}

function addLink(node, link){
	var linkNode = document.createElement("a");
	linkNode.setAttribute("href", link);
	linkNode.appendChild(document.createTextNode(node.nodeValue));
	node.parentNode.replaceChild(linkNode, node);
}

// gallery
var PictureGallery =  [];
var CurrentPicture = 0;

function addPicture(url, name){
	var p = new Object();
	p.url = url;
	p.name = name;
	PictureGallery.push(p);
}

function openPicture(id){
	var p = PictureGallery[id];
	var title = "";
	if(p.name && p.name != "")
		title = p.name;
	var img = new Image();
	img.onload = function(){
		document.getElementById("thePhoto").src = img.src;
		var nw = this.width + 30;
		var nh = this.height + 46;
		var view = document.getElementById("photoView");
		view.children[1].style.width = nw + "px";
		view.children[1].style.height = nh + "px";
		view.children[1].style.marginLeft = (-nw/2) + "px";
		view.children[1].style.marginTop = (-nh/2) + "px";
		view.style.width = (nw + 47) + "px";
		view.style.height = (nh + 62) + "px";
		view.style.marginLeft = (-(nw + 47)/2) + "px";
		view.style.marginTop = (-(nh + 62)/2) + "px";
		view.style.display = "block";
	}
	img.src = p.url;
	document.getElementById("thePhotoTitle").firstChild.nodeValue = title;
	CurrentPicture = id;
}

function nextPicture(){
	CurrentPicture++;
	if(CurrentPicture >= PictureGallery.length)
		CurrentPicture = 0;
	openPicture(CurrentPicture);
}

function previousPicture(){
	CurrentPicture--;
	if(CurrentPicture < 0)
		CurrentPicture = PictureGallery.length-1;
	openPicture(CurrentPicture);
}

// \gallery

// global js end
