/*ä*/

var germany_time = 0;

function calcTime()
{
	far = germany_time - (9 * 3600 * 1000);
	var time = new Date(germany_time);

	document.getElementById('time_local').innerHTML = (fstring(2, time.getDate()) + '.' + fstring(2, time.getMonth()+1) + '.' + fstring(4, time.getFullYear()) + 
	' ' + fstring(2, time.getHours()) + ':' + fstring(2, time.getMinutes()+1) + ':' + fstring(2, time.getSeconds()) );
	
	time = new Date(far);
	document.getElementById('time_far').innerHTML = (fstring(2, time.getDate()) + '.' + fstring(2, time.getMonth()+1) + '.' + fstring(4, time.getFullYear()) + 
	' ' + fstring(2, time.getHours()) + ':' + fstring(2, time.getMinutes()+1) + ':' + fstring(2, time.getSeconds()) );
	germany_time += 1000;
}

function fstring(width, value)
{
	var gesamt = '000000' + value;
	return gesamt.substr(gesamt.length - width);
}

function mkZoomImage(url, width, height, imgsrc, parent, text, cl)
{
var imgdiv = document.createElement('div');
var zoomdiv = document.createElement('div');
var linkname = url;
var alt = text;
imgdiv.setAttribute('style', 'width: '+width+'px; height: '+height+'px; background: url('+imgsrc+');');
imgdiv.setAttribute('title', text);
imgdiv.setAttribute('class', cl);
zoomdiv.setAttribute('style', 'width: '+width+'px; height: '+height+'px;');
zoomdiv.setAttribute('class', 'lupe');
imgdiv.appendChild(zoomdiv);
parent.onclick = function()
{
	if(document.getElementById('zoomWindow') != null && document.getElementById('zoomImage') != null)
	{
		document.getElementById('zoomImage').setAttribute('src', linkname);
		document.getElementById('zoomImage').setAttribute('alt', alt);
		document.getElementById('zoomWindow').setAttribute('style', 'background: url(img/inactiv.png) transparent; height: 100%; width: 100%; position: fixed; top: 0; left: 0; zIndex: 99; text-align: center;');
		return false;
	}
	return true;
}
return imgdiv;
}

function mkZoomImg(url, parent, text, format, orient)
{
var iconspan = document.createElement('span');
var lupeimg = document.createElement('img');
var linkname = url;
var alt = text;

iconspan.setAttribute('class', 'zoom-icon');
lupeimg.setAttribute('src', '/img/lupe.png');
lupeimg.setAttribute('width', '32');
lupeimg.setAttribute('height', '32');
lupeimg.setAttribute('alt', 'Zoom');
parent.setAttribute('class', 'zi' + format + orient);
iconspan.appendChild(lupeimg);

parent.onclick = function()
{
	if(document.getElementById('zoomWindow') != null && document.getElementById('zoomImage') != null)
	{
		document.getElementById('zoomImage').setAttribute('src', linkname);
		document.getElementById('zoomImage').setAttribute('alt', alt);
		document.getElementById('zoomWindow').setAttribute('style', 'background: url(img/inactiv.png) transparent; height: 100%; width: 100%; position: fixed; top: 0; left: 0; zIndex: 99; text-align: center;');
		return false;
	}
	return true;
}
return iconspan;
}

var textn  = 0;
function sc(t){textn++;}
function traverse(root, fn)
{
	var children = root.childNodes,
	l = children.length;
	while( l-- )
	{
		node = children[l];
		if( node.nodeType == 3 && node.parentNode.nodeName.toLowerCase() != 'textarea')
		{ // Text node
			fn(node);
		}
		else if( node.nodeType == 1)
		{
			traverse(node, fn);
		}
		// Element node
	}	
}

var EmoIcons = [{i: 'Face-smile.png', t: ':-)'}, {i: 'Face-sad.png', t: ':-('}, {i: 'Face-wink.png', t: ';-)'}, {i: 'Face-clown.png', t: ':o)'}, {i: 'Face-kiss.png', t: ':-*'}];
function FindIndexOfEmoIcon(text)
{
	var obj = {i: '', t: '', p: -1};
	var min = text.length;
	var p = 0;
	var e = -1;
	for(i = 0; i < EmoIcons.length; i++)
	{
		p = text.indexOf(EmoIcons[i].t);
		if(p < min && p > -1)
		{
			min = text.indexOf(EmoIcons[i].t)
			e = i;
		}
	}
	if(e > -1)
	{
		obj.i = EmoIcons[e].i;
		obj.t = EmoIcons[e].t;
		obj.p = min;
	}
	
	return obj;
}

function replaceEmoicons(textnode)
{
	var image = document.createElement('img');
	
	var text = textnode.nodeValue;
	var pos = FindIndexOfEmoIcon(text); // text.indexOf(':-)');
	var parent = textnode.parentNode;
	
	var before = null;
	var txt = null;
	var tn = null;
	if(pos.p >= 0)
	{
		before = textnode.nextSibling;
		parent.removeChild(textnode);
	}
	
	while(pos.p >= 0)
	{
		txt = text.substring(0, pos.p);
		tn = document.createTextNode(txt);
		parent.insertBefore(tn, before);
		clone = image.cloneNode(true);
		clone.setAttribute('src', 'img/' + pos.i);
		clone.setAttribute('alt', pos.t);
		clone.setAttribute('title', pos.t);
		
		
		parent.insertBefore(clone, before);

//		text = text.substr(text.indexOf(':-)')+3);
		text = text.substr(pos.p + pos.t.length);
		pos = FindIndexOfEmoIcon(text); //text.indexOf(':-)');
		if(pos.p < 0)
		{
			tn = document.createTextNode(text);
			parent.insertBefore(tn, before);
		}
	}

	
}



window.onload = function()
{
	var imgs = document.getElementsByTagName('img');
	
	for(i = imgs.length-1; i >= 0 ; i--)
	{
		if(imgs[i].getAttribute('class') != null &&
			imgs[i].getAttribute('class').indexOf('zoomImage')>= 0 &&
			imgs[i].parentNode.tagName.toUpperCase() == 'A')
		{
			alt = imgs[i].getAttribute('alt');
			var orient = '';			
			cl = imgs[i].getAttribute('class');
			for(cls = 0; cls < cl.length; cls++)
			{
				if(cl[cls] == 'l')
				{
					orient = ' lo';
					break;
				}

				if(cl[cls] == 'r')
				{
					orient = ' ro';
					break;
				}
			}
			
			imgs[i].setAttribute('class', 'jszoomImage');
			var parent = imgs[i].parentNode;
			var linkname = parent.getAttribute('href');
			var format = imgs[i].width < 200 ? ' po' : ' lc';
			
			parent.appendChild(mkZoomImg(linkname, parent, alt, format, orient));
		}
	}
	
	if(document.getElementById('time_local') != null)
	{
		germany_time = parseInt(document.getElementById('time_local').getAttribute('title'));
		window.setInterval("calcTime()", 1000);
	}
	traverse(document.getElementsByTagName('html')[0], replaceEmoicons);
//	calcTime();

	// 1242247275000
//	var germany = Date.parse(new Date());
//	Objektname = new Date(Millisekunden);

//	alert(germany);
};



