var pll = new Image(); pll.src = '/common/img/pic_loading.gif';
var popCnt=0; var ilCnt=0; var moCnt=0;

function prepPics() {
	objBody = document.getElementsByTagName('body').item(0);
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href")) {
			var rel = anchor.getAttribute("rel");
			if (/^(popPic)/.test(rel)) {														// check if REL contains popPic
				popCnt++;
				anchor.onclick = function () { showPopPic(this); return false; }; 
				window['plPop'+popCnt] = new Image(); window['plPop'+popCnt].src = anchor;									// preload picture
			}

			if (/^(ilPic)/.test(rel)) { 															// check if REL contains ilPic
				if (!document.getElementById('il_pic')) { initIlPic(); var plp = new Image(); plp.src = '/common/img/pic_prev.gif'; var pln = new Image(); pln.src = '/common/img/pic_next.gif'; var plc = new Image(); plc.src = '/common/img/pic_close.gif'; }
				ilCnt++;
				var pTxt = anchor.getAttribute("title");												// if any, assign text that goes with picture
				if (/\[(.*)\]/.test(rel)) {														// check if REL contains picture group (check for '[*groupname*]')
					var pgName = /\[(.*)\]/.exec(rel)[1];												// determine picture group name
					if (typeof(window['p_'+pgName]) == 'object') { pgNr = window['p_'+pgName].push(anchor); window['t_'+pgName].push(pTxt); }				// add picture to array 'p_pictureGroupName' and txt to 't_pictureGroupName' if array exists...
					else { window['p_'+pgName] = new Array(anchor); window['t_'+pgName] = new Array(pTxt); var pgNr = 1; }						// or create 'p_pictureGroupName' & 't_pictureGroupName' and add picture & text
				} else { var pgName = ''; var pgNr = ''; }
				anchor.pgName = pgName; anchor.pgNr = pgNr;	anchor.pTxt = pTxt; anchor.ilCnt = ilCnt;								// dereference variables for dynamic event handler assigning
				anchor.onclick = function () { showIlPic(this, this.pgName, this.pgNr, this.pTxt, this.ilCnt); return false; }
				window['plIl'+ilCnt] = new Image(); window['plIl'+ilCnt].src = anchor; 										// preload picture
			}

			if (/^(moPic)/.test(rel)) {															// check if REL contains moPic
				if (!document.getElementById('mo_pic')) { initMoPic(); var plb = new Image(); plb.src = '/common/img/wrrect_b.png'; var plbl = new Image(); plbl.src = '/common/img/wrrect_bl.png'; var plbr = new Image(); plbr.src = '/common/img/wrrect_br.png'; var pll = new Image(); pll.src = '/common/img/wrrect_l.png'; var plr = new Image(); plr.src = '/common/img/wrrect_r.png'; var plt = new Image(); plt.src = '/common/img/wrrect_t.png'; var pltl = new Image(); pltl.src = '/common/img/wrrect_tl.png'; var pltr = new Image(); plr.src = '/common/img/wrrect_tr.png'; }
				moCnt++;
				var imgTS = /\[(.*)\]/.exec(rel)[1];													// determine url of image to show
				anchor.imgTS = imgTS; anchor.moCnt = moCnt;												// dereference variables for dynamic event handler assigning
				anchor.onmouseover = function() { showMoPic(this.imgTS, this.moCnt); }
				anchor.onmouseout = function() { hideMoPic(); }
				window['plMo'+moCnt] = new Image(); window['plMo'+moCnt].src = anchor.imgTS;									// preolad picture
			}
		}
	}
}

// POPUP STYLE
function showPopPic(which) {
	var html = '<HTML><HEAD><TITLE>GC EUROPE - click anywhere to close</TITLE></HEAD><BODY STYLE="margin:0px; font-family:tahoma,arial,helvetica; font-size:11px" onBlur="this.close()"><CENTER><BR><BR><IMG SRC="/common/img/pic_loading.gif" WIDTH=110 HEIGHT=50></CENTER><DIV STYLE="position:absolute; left:0px; top:0px"><IMG SRC="' + which +'" onClick="window.close()" ALT="click anywhere to close"></DIV></BODY></HTML>';
	var venster=window.open('', 'mywindow', 'width=250,height=100');													// IE: min clientWidth=250, min clientHeight=100 when creating popup
	if (venster) {
		venster.document.open();
		venster.document.write(html);
		venster.document.close();
		venster.document.images[1].onload = function() { venster.resizeBy(venster.document.images[1].width-venster.document.body.clientWidth, venster.document.images[1].height-venster.document.body.clientHeight); }	// when image has to be loaded from server
		if (venster.document.images[1].complete) { venster.resizeBy(venster.document.images[1].width-venster.document.body.clientWidth, venster.document.images[1].height-venster.document.body.clientHeight); }	// when image is in cache
		venster.focus();
	} else alert('You are using pop-up blocking software.\nIn order to see the picture, please enable pop-ups for this site.');
}

// INLINE STYLE
function initIlPic() {
	var objBgpic = document.createElement('div');
	objBgpic.setAttribute('id','il_bgpic');
	objBgpic.style.position = 'absolute';
	objBgpic.style.top = '0';
	objBgpic.style.left = '0';
	objBgpic.style.backgroundColor = '000000';
	objBgpic.style.display = 'none';
	objBgpic.style.zIndex = '101';
	objBgpic.onclick = hideIlPic;
	objBgpic.style.filter = 'alpha(opacity=70)'; objBgpic.style.opacity = '0.7';													// filter: IE only, opacity: all
	objBody.insertBefore(objBgpic, objBody.firstChild);
	
	var objPic = document.createElement('div');
	objPic.setAttribute('id','il_pic');
	objPic.style.position = 'absolute';
	objPic.style.backgroundColor = 'FFFFFF';
	objPic.style.border = '5px solid #FFFFFF';
	objPic.style.display = 'none';
	objPic.style.zIndex = '102';
	objBody.insertBefore(objPic, objBgpic.nextSibling);

	addResizeEvent(function() { if(document.getElementById('il_pic').offsetWidth>0) posIlPic(document.getElementById('il_pic').offsetWidth-10, document.getElementById('il_pic').offsetHeight); });			// addResizeEvent to allow several onresizes (function declared in /common/menu.js) - checks first if there is an inline pic opened
}

function showIlPic(which, pgName, pgNr, pTxt, plNr) {
	if(!pTxt) pTxt = '&nbsp;'; document.getElementById('il_pic').innerHTML = '<IMG NAME="il_picts" ID="il_picts" SRC="/common/img/pic_loading.gif"><DIV NAME="il_nav" ID="il_nav" STYLE="display:none"><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 STYLE="padding-top:5px"><TR><TD NAME="il_prev" ID="il_prev" STYLE="cursor:pointer; padding-right:5px"><IMG SRC="/common/img/pic_prev.gif" WIDTH=16 HEIGHT=16 ALT="previous"></TD><TD NAME="il_next" ID="il_next" STYLE="cursor:pointer; padding-right:5px"><IMG SRC="/common/img/pic_next.gif" WIDTH=16 HEIGHT=16 ALT="next"></TD><TD NAME="il_txt" ID="il_txt" STYLE="font-family:tahoma,arial,helvetica; font-size:11px; color:#706D6D">' + pTxt + '</TD><TD onClick="hideIlPic()" STYLE="cursor:pointer; padding-left:5px"><IMG SRC="/common/img/pic_close.gif" WIDTH=16 HEIGHT=16 ALT="close"></TD></TR></TABLE></DIV>';
	if (pgName) 	{																	// pgNr = place in array + 1
		document.getElementById('il_next').onclick = function() { showIlPic(window['p_'+pgName][pgNr], pgName, pgNr+1, window['t_'+pgName][pgNr], plNr+1); }
		document.getElementById('il_prev').onclick = function() { showIlPic(window['p_'+pgName][pgNr-2], pgName, pgNr-1, window['t_'+pgName][pgNr-2], plNr-1); }
		if (pgNr == 1) document.getElementById('il_prev').parentNode.removeChild(document.getElementById('il_prev'));
		if (pgNr == window['p_'+pgName].length) document.getElementById('il_next').parentNode.removeChild(document.getElementById('il_next'));
	} else { document.getElementById('il_prev').parentNode.removeChild(document.getElementById('il_prev')); document.getElementById('il_next').parentNode.removeChild(document.getElementById('il_next')); }
	document.getElementById('il_bgpic').style.width = (document.body.scrollWidth > document.body.clientWidth) ? (document.body.scrollWidth) : (document.body.clientWidth);					// get bg to right size when loading image
	document.getElementById('il_bgpic').style.height = (document.body.scrollHeight > document.body.clientHeight) ? (document.body.scrollHeight) : (document.body.clientHeight);
	document.getElementById('il_pic').style.left = document.body.clientWidth/2 - pll.width/2 + document.body.scrollLeft;									// center /pic_loading.gif
	document.getElementById('il_pic').style.top = document.body.clientHeight/2 - pll.height/2 + document.body.scrollTop;
	document.getElementById('il_bgpic').style.display = document.getElementById('il_pic').style.display = 'inline';
	window['plIl'+plNr].onload = function() { document.getElementById('il_picts').src = which; posIlPic(window['plIl'+plNr].width, window['plIl'+plNr].height); }						// when image has to be loaded from server
	if (window['plIl'+plNr].complete) { document.getElementById('il_picts').src = which; posIlPic(window['plIl'+plNr].width, window['plIl'+plNr].height); }							// when image is in cache (opera)
}

function posIlPic(picW, picH) {
	document.getElementById('il_txt').style.width = picW - 21 - (document.getElementById('il_prev')?(21):(0)) - (document.getElementById('il_next')?(21):(0));						// set width of txt area
	document.getElementById('il_nav').style.display = 'inline';														// show navigation
	picH += document.getElementById('il_nav').offsetHeight;
	if (picW > document.body.clientWidth) document.getElementById('il_pic').style.left = 10;											// position image in viewport											
	else document.getElementById('il_pic').style.left = document.body.clientWidth/2 - picW/2 + document.body.scrollLeft;
	if (picH > document.body.clientHeight) document.getElementById('il_pic').style.top = 10;
	else document.getElementById('il_pic').style.top = document.body.clientHeight/2 - picH/2 + document.body.scrollTop;
	document.getElementById('il_bgpic').style.width = (document.body.scrollWidth > document.body.clientWidth) ? (document.body.scrollWidth) : (document.body.clientWidth);					// adapt bg size:	- in case of window resize
	document.getElementById('il_bgpic').style.height = (document.body.scrollHeight > document.body.clientHeight) ? (document.body.scrollHeight) : (document.body.clientHeight);				//		- if image dimensions exceed client- or scrollWidth|Height
	if (picW >= (document.getElementById('il_bgpic').offsetWidth - 30)) document.getElementById('il_bgpic').style.width = document.getElementById('il_bgpic').offsetWidth + 10;				// give image a margin of 10px if it exceeds client- or scrollWidht|Height
	if (picH >= (document.getElementById('il_bgpic').offsetHeight - 30)) document.getElementById('il_bgpic').style.height = document.getElementById('il_bgpic').offsetHeight + 10;				// 30 = 10 above (left), 5+5 border, 10 below (right)
}

function hideIlPic() {
	document.getElementById('il_picts').src = '/common/img/pic_loading.gif';
	document.getElementById('il_bgpic').style.display = document.getElementById('il_pic').style.display = 'none';
}

// MOUSEOVER STYLE
function initMoPic() {
	var objPic = document.createElement('div');
	objPic.setAttribute('id','mo_pic');
	objPic.style.position = 'absolute';
	objPic.style.display = 'none';
	objPic.style.zIndex = '100';
	objBody.insertBefore(objPic, objBody.firstChild);
}

function showMoPic(which, plNr) {
	document.getElementById('mo_pic').innerHTML = '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD><IMG SRC="/common/img/wrrect_tl.png" WIDTH=30 HEIGHT=30></TD><TD BACKGROUND="/common/img/wrrect_t.png">&nbsp;</TD><TD><IMG SRC="/common/img/wrrect_tr.png" WIDTH=30 HEIGHT=30></TD></TR><TR><TD BACKGROUND="/common/img/wrrect_l.png">&nbsp;</TD><TD BGCOLOR="#FFFFFF"><IMG NAME="mo_picts" ID="mo_picts" SRC="/common/img/pic_loading.gif"></TD><TD BACKGROUND="/common/img/wrrect_r.png">&nbsp;</TD></TR><TR><TD><IMG SRC="/common/img/wrrect_bl.png" WIDTH=30 HEIGHT=30></TD><TD BACKGROUND="/common/img/wrrect_b.png">&nbsp;</TD><TD><IMG SRC="/common/img/wrrect_br.png" WIDTH=30 HEIGHT=30></TD></TR></TABLE>';
	document.getElementById('mo_pic').style.left = window.event.clientX + document.body.scrollLeft; document.getElementById('mo_pic').style.top = window.event.clientY + document.body.scrollTop;			// move image to cursor position
	document.getElementById('mo_pic').style.display = 'inline';
	window['plMo'+plNr].onload = function() { document.getElementById('mo_picts').src = which; posMoPic(window['plMo'+plNr].width, window['plMo'+plNr].height); }					// when image has to be loaded from server
	if (window['plMo'+plNr].complete) { document.getElementById('mo_picts').src = which; posMoPic(window['plMo'+plNr].width, window['plMo'+plNr].height); }						// when image is in cache (opera)
}

function posMoPic(picW, picH) {
	if (document.getElementById('mo_pic').offsetLeft + picW + 60 + 5 < document.body.clientWidth) var xPos = document.getElementById('mo_pic').offsetLeft + 5;
	else var xPos = document.getElementById('mo_pic').offsetLeft - picW - 60 - 5;
	if (document.getElementById('mo_pic').offsetTop + picH +60 + 5 < document.body.clientHeight) var yPos = document.getElementById('mo_pic').offsetTop + 5;
	else var yPos = document.getElementById('mo_pic').offsetTop - picH - 60 - 5;
	document.getElementById('mo_pic').style.left = xPos; document.getElementById('mo_pic').style.top = yPos;
}

function hideMoPic() {
	document.getElementById('mo_picts').src = '/common/img/pic_loading.gif';
	document.getElementById('mo_pic').style.display = 'none';
}

addLoadEvent(prepPics);																	// addLoadEvent to allow several onloads (function declared in /common/menu.js)