﻿/*
 *  Simple Ajax Toolset 2.3 (small)
 *
 *  tested with: IE 5.01/5.5/6/7, Firefox 1/1.5/2, Opera 8.5/9, Safari 1.3/2/3
 *  (to some extent on IE 5.0 SP2)
 *
 *  (c) Copyright by Soeren Mueller, 2006-2010 - soeren.mueller@all-digital.de
 */

function _$(e) {
	if (typeof e == 'object' || typeof e == 'function') {
		return e;
	}
	if (document.getElementById) {
		return document.getElementById(e);
	}
	if (document.all) {
		return document.all[e];
	}
	return null;
}

function $C(e) {
	return document.createElement(e);
}

function $AT(el, attr, val) {
	if (typeof val != 'undefined') {
		el.setAttribute(attr, val);
		return el;
	}
	return el.getAttribute(attr);
}

function $A(iterable, source) {
	var result = source || [], i;
	if (iterable) {
		for (i=0; i<iterable.length; ++i) {
			result.push(iterable[i]);
		}
	}
	return result;
}

function $E(doc, tag) {
	if (typeof doc == 'string') {
		if (typeof tag == 'undefined') {
			tag = doc;
			doc = null;
		} else {
			doc = _$(doc);
		}
	}
	doc = doc || document;
	var result = null;
	try {
		result = doc.getElementsByTagName(tag || 'e');
	} catch(e) {}
	if (!result || !result.length) {
		if (tag == '*' && document.all) {
			result = document.all;
		} else {
			result = null;
		}
	}
	return result;
}

function $EA(doc, tag) {
	var e = $E(doc, tag);
	if (e) {
		return $A(e);
	}
	return [];
}

function $isTag(el, tag) {
	return (el && el.tagName && el.tagName.toLowerCase() == tag);
}

function $hasClass(el, cname) {
	try {
		el = _$(el);
		if (el.className && el.className.length > 0) {
			var cn = el.className.split(' ');
			return cn.contains(cname);
		}
	} catch(e) {}
	return false;
}

function $remClass(el, cname) {
	try {
		el = _$(el);
		if (el.className && el.className.length > 0) {
			var cn = el.className.split(' ');
			el.className = cn.without(cname).join(" ");
		}
	} catch(e) {}
	return el;
}

function $addClass(el, cname) {
	if (typeof el == 'function') {
		this._cb = el;
		return el;
	}
	el = _$(el);
	if (cname.charAt(0) == '-') {
		$remClass(el, cname.substring(1));
		if (this._cb) {
			this._cb(el);
		}
	} else if (!$hasClass(el, cname)) {
		el.className = ((el.className && el.className.length > 0) ? (el.className + " ") : "") + cname;
		if (this._cb) {
			this._cb(el);
		}
	}
	return el;
}

function $CNS(doc, cname) {
	if (typeof cname == 'undefined' && typeof doc == 'string') {
		cname = doc;
		doc = null;
	}
	var result = [], el = $E(doc, '*'), i;
	if (el) {
		for (i=0; i<el.length; ++i) {
			if ($hasClass(el[i], cname)) {
				result.push(el[i]);
			}
		}
	}
	return result;
}

function $CN(doc, cname) {
	if (typeof cname == 'undefined' && typeof doc == 'string') {
		cname = doc;
		doc = null;
	}
	var el = $E(doc, '*'), i;
	if (el) {
		for (i=0; i<el.length; ++i) {
			if ($hasClass(el[i], cname)) {
				return el[i];
			}
		}
	}
	return null;
}

function $CNP(el, cname) {
	el = _$(el);
	if (el) {
		for (el = el.parentNode; el; el = el.parentNode) {
			if ($hasClass(el, cname)) {
				break;
			}
		}
	}
	return el;
}

String.prototype.trim = function() {
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

Array.prototype.iterate = function(func, bind) {
	var i;
	for (i=0; i<this.length; ++i) {
		if (bind) {		/* mootools compatibility! - required in Array.prototype.each */
			func.call(bind, this[i], i, this);
		} else {
			func(this[i], i);
		}
	}
};

Array.prototype.contains = function(what) {
	var i;
	for (i=0; i<this.length; ++i) {
		if (this[i] == what) {
			return true;
		}
	}
	return false;
};

if (!Array.prototype.each) {
	Array.prototype.each = Array.prototype.iterate;
}

String.prototype.contains = function(what) {
	return this.indexOf(what) >= 0;
};

Array.prototype.without = function(what) {
	var result = [], i;
	for (i=0; i<this.length; ++i) {
		if (this[i] != what) {
			result.push(this[i]);
		}
	}
	return result;
};

function $css(sel, dec) {
	var //ua = navigator.userAgent.toLowerCase(), isIE = (/msie/.test(ua)) && (/win/.test(ua) && !window.opera),
		style = $C("style"), lastStyle;
	$AT(style, "type", "text/css");
	$AT(style, "media", "screen");
	if (!util.isIE) {
		style.appendChild(document.createTextNode(sel+" {"+dec+"}"));
	}
	$E("head")[0].appendChild(style);
	if (util.isIE && document.styleSheets && document.styleSheets.length > 0) {
		lastStyle = document.styleSheets[document.styleSheets.length-1];
		if (lastStyle.addRule) {
			lastStyle.addRule(sel, dec);
		}
	}
}

function $attachEvent(el, evt, func) {
	el = _$(el);
	if (el) {
		if (el.each) {
			el.each(function(e){
				$attachEvent(e, evt, func);
			});
		} else {
			try {
				if (evt != 'click' && evt != 'dblclick' && el.addEventListener) {
					el.addEventListener(evt, func, false);
				} else if (el.attachEvent) {
					el.attachEvent("on"+evt, func);
				} else {
					el["on"+evt] = func;
				}
				el["__"+evt] = [(el["__"+evt] || [0])[0] + 1];
			} catch(e) {}
		}
	}
}

function $detachEvent(el, evt, func) {
	el = _$(el);
	if (el) {
		if (el.each) {
			el.each(function(e){
				$detachEvent(e, evt, func);
			});
		} else {
			try {
				if (evt != 'click' && evt != 'dblclick' && el.removeEventListener) {
					el.removeEventListener(evt, func, false);
				} else if (el.detachEvent) {
					el.detachEvent("on"+evt, func);
				} else {
					el["on"+evt] = null;
				}
				var useCount = (el["__"+evt] || [0])[0];
				if (useCount > 1) {
					el["__"+evt] = [useCount-1];
				} else {
					el["__"+evt] = null;
				}
			} catch(e) {}
		}
	}
}

/* REMOVED FOR MOOTOOLS COMPAT
Function.prototype.bind = function() {
	var method = this, args = $A(arguments), object = args.shift();
	return function() {
		return method.apply(object, args);
	};
};*/

if (!Function.prototype.apply) {
	Function.prototype.apply = function(thisArg, argArray) {
		if (typeof this != 'function') {
			// throw is commented out because safari 1.3 requires the ';' after throw which is removed by yui compressor!!!
			return null; //throw new Error('apply called on incompatible object (not a function)');
		}
		if (argArray != null && !(argArray instanceof Array) && typeof argArray.callee != 'function') {
			return null; //throw new Error('The 2nd argument to apply must be an array or arguments object');
		}

		thisArg = (thisArg == null) ? window : Object(thisArg);
		thisArg.__applyTemp = this;

		// youngpup's hack
		var parameters = [], length = (argArray || '').length >>> 0, i, functionCall;
		for (i = 0; i < length; i++) {
			parameters[i] = 'argArray[' + i + ']';
		}
		functionCall = 'thisArg.__applyTemp(' + parameters + ')';

		try {
			return eval(functionCall);
		} finally {
			try {
				delete thisArg.__applyTemp;
			} catch (e){}
		}
	};
}

if (!Function.prototype.call) {
	Function.prototype.call = function(thisArg) {
		return this.apply(thisArg, Array.prototype.slice.apply(arguments, [1]));
	};
}

Function.prototype.bindAsEventListener = function(object) {
	var method = this;
	return function(evt) {
		evt = evt || window.event;
		var target = evt.currentTarget || evt.target || evt.srcElement, result;
		if (evt.type && target && !target["__"+evt.type]) {
			do {
				target = target.parentNode;
			} while(!target["__"+evt.type]);
		}
		result = method.call(object, evt, (target && target.nodeType == 3) ? target.parentNode : target);
		if (evt && result === false) {
			if (evt.stopPropagation) {
				evt.stopPropagation();
			}
			evt.cancelBubble = true;
			if (evt.preventDefault) {
				evt.preventDefault();
			}
			evt.returnValue = false;
		}
		return result;
	};
};

Function.prototype.delay = function() {
	var scope = this, args = $A(arguments), delay = args.shift();
	return setTimeout(function() {
		scope.apply(scope, args);
	}, delay);
};

Function.prototype.after = function(delay) {
	return setTimeout(this, delay);
};

function $style(el, which, def) {
	el = _$(el);
	var result = def, pos;
	try {
		if (document.defaultView && document.defaultView.getComputedStyle) {
			result = document.defaultView.getComputedStyle(el, "").getPropertyValue(which);
		} else if (el.currentStyle) {
			while((pos = which.indexOf('-')) != -1) {
				which = which.substring(0, pos) + which.substring(pos+1, pos+2).toUpperCase() + which.substring(pos+2);
			}
			result = el.currentStyle[which];
		}
		if ((pos = result.indexOf("px")) != -1) {
			return parseInt(result.substring(0, pos), 10);
		}
	} catch(e) {
	}
	return result;
}

function rand(max) {
	return Math.floor(Math.random()*max+1);
}

function $show(el, visible, opacity) {
	if (el.each) {
		el.each(function(e){
			$show(e, visible, opacity);
		});
		return el;
	}
	el = _$(el);
	if (typeof visible == 'number') {
		opacity = visible;
		visible = null;
	}
	if (typeof opacity != 'undefined') {
		$setOpacity(el, opacity);
	}
	try {
		el.style.display = (visible === false) ? 'none' : '';
		el.style.visibility = 'visible';
	} catch(e) {
	}
	return el;
}

function $hide(el, opacity) {
	return $show(el, false, opacity);
}

function $rem(el) {
	el = _$(el);
	if (el && el.parentNode) {
		el.parentNode.removeChild(el);
	}
}

function $append(where, el) {
	if (where.nextSibling) {
		where.parentNode.insertBefore(el, where.nextSibling);
	} else {
		where.parentNode.appendChild(el);
	}
}

function $visible(el) {
	el = _$(el);
	return ($style(el, "display").toLowerCase() != 'none' && $style(el, "visibility").toLowerCase() != 'hidden');
}

function $opacity(el, check) {
	if (check && !$visible(el)) {
		return 0;
	}
	try {
		var s = _$(el).style;
		if (s.opacity) {
			return (s.opacity.length > 0) ? (parseFloat(s.opacity) * 100) : 100;
		} else if (s.MozOpacity) {
			return (s.MozOpacity.length > 0) ? (parseFloat(s.MozOpacity) * 100) : 100;
		} else if (s.KhtmlOpacity) {
			return (s.KhtmlOpacity.length > 0) ? (parseFloat(s.KhtmlOpacity) * 100) : 100;
		} else if (s.KHTMLOpacity) {
			return (s.KHTMLOpacity.length > 0) ? (parseFloat(s.KHTMLOpacity) * 100) : 100;
		} else if (s.filter) {
			return (s.filter.length > 48) ? (parseInt(s.filter.substring(48), 10)) : 100;
		}
	} catch(e) {
	}
	return 100;
}

function $setOpacity(el, opacity) {
	if (el.each) {
		el.each(function(e){
			$setOpacity(e, opacity);
		});
		return;
	}
	try {
		var s = _$(el).style;
		if (typeof s.opacity != 'undefined') {
			s.opacity = (opacity / 100);
		} else if (typeof s.MozOpacity != 'undefined') {
			s.MozOpacity = (opacity / 100);
		} else if (typeof s.KhtmlOpacity != 'undefined') {
			s.KhtmlOpacity = (opacity / 100);
		} else if (typeof s.KHTMLOpacity != 'undefined') {
			s.KHTMLOpacity = (opacity / 100);
		} else if (typeof s.filter != 'undefined') {
			s.filter = (opacity > 99) ? "" : ("progid:DXImageTransform.Microsoft.Alpha(opacity=" + Math.round(opacity) + ")");
		}
	} catch(e) {
	}
}

function $fade(el, from, to, duration, startDelay, zindex) {
	if (!el.each) {
		from = (typeof from != 'number') ? ($visible(el) ? $opacity(el) : 0) : from;
		to = (typeof to != 'number') ? ($visible(el) ? $opacity(el) : 100) : to;
		if (to == from) {
			return;
		}
	}
	var me = this;
	this._el = _$(el);
	this._from = from || 0;
	this._to = to;
	this._duration = duration || 300;
	this._zindex = zindex || 0;
	this._update = function() {
		var time = 0;
		if (!me._starttime) {
			me._starttime = (new Date()).getTime();
		} else {
			time = (new Date()).getTime() - me._starttime;
			if (time > me._duration) {
				time = me._duration;
			}
		}
		$setOpacity(me._el, me._from+((me._to-me._from)*(-(Math.cos(Math.PI*(time/me._duration))-1)/2)));
		if (!time && !me._from) {
			$show(me._el);
		}
		if (me._zindex) {
			me._el.style.zIndex = me._zindex;
		}
		if (time < me._duration) {
			if (me._timer) {
				me._timer = me._update.after(13);	// was: 40
			}
		} else if (me._to === 0) {
			$hide(me._el);
		}
	};
	this.stop = function() {
		if (me._timer) {
			window.clearTimeout(me._timer);
			me._timer = null;
		}
	};
	this._timer = this._update.after(startDelay || 0);
}

function $anim(el, prop, from, to, duration, startDelay) {
	if (!el.each) {
		from = (typeof from != 'number') ? $style(el, prop, 0) : from;
		to = (typeof to != 'number') ? $style(el, prop, 0) : to;
		if (to == from) {
			return;
		}
	}
	var me = this;
	this._el = _$(el);
	this._prop = prop;
	this._from = from || 0;
	this._to = to;
	this._duration = duration || 300;
	this._update = function() {
		var time = 0;
		if (!me._starttime) {
			me._starttime = (new Date()).getTime();
		} else {
			time = (new Date()).getTime() - me._starttime;
			if (time > me._duration) {
				time = me._duration;
			}
		}
		me._el.style[prop] = me._from+((me._to-me._from)*(-(Math.cos(Math.PI*(time/me._duration))-1)/2)) + "px";
		if (time < me._duration) {
			if (me._timer) {
				me._timer = me._update.after(13);	// was: 40
			}
		}
	};
	this.stop = function() {
		if (me._timer) {
			window.clearTimeout(me._timer);
			me._timer = null;
		}
	};
	this._timer = this._update.after(startDelay || 0);
}

function $x(el) {
	el = _$(el);
	var left = 0;
	try {
		if (el.offsetParent) {
			do {
				left += el.offsetLeft;
			} while ((el = el.offsetParent));
		} else if (el.x) {
			left += el.x;
		}
	} catch(e) {}
    return left;
}

function $y(el) {
	el = _$(el);
	var top = 0;
	try {
		if (el.offsetParent) {
			do {
				top += el.offsetTop;
			} while ((el = el.offsetParent));
		} else if (el.y) {
			top += el.y;
		}
	} catch(e) {}
    return top;
}

function $width(el, client) {
	try {
		if (el) {
			el = _$(el);
			if (client && el.clientWidth) {
				return el.clientWidth;
			} else if (el.innerWidth) {
				return el.innerWidth;
			} else {
				return el.offsetWidth;
			}
		}
		if (window.innerWidth) {
			return window.innerWidth;
		} else if (document.documentElement && document.documentElement.clientWidth) {
			return document.documentElement.clientWidth;
		} else if (document.body && document.body.offsetWidth) {
			return document.body.offsetWidth;
		}
	} catch(e) {}
	return 0;
}

function $height(el, client) {
	try {
		if (el) {
			el = _$(el);
			if (client && el.clientHeight) {
				return el.clientHeight;
			} else if (el.innerHeight) {
				return el.innerHeight;
			} else {
				return el.offsetHeight;
			}
		}
		if (window.innerHeight) {
			return window.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			return document.documentElement.clientHeight;
		} else if (document.body && document.body.offsetHeight) {
			return document.body.offsetHeight;
		}
	} catch(e) {}
	return 0;
}

function $setWidth(el, w) {
	el = _$(el);
	try {
		el.style.width = (w) ? w+'px' : '';
	} catch(e){}
}

function $setHeight(el, h) {
	el = _$(el);
	try {
		el.style.height = (h) ? h+'px' : '';
	} catch(e){}
}

function $link(text, url, target, title) {
	if (typeof url == 'undefined') {
		url = text;
	}
	var isMail = false;
	if (url && url.substring(0, 7) != "http://") {
		if (url.indexOf('@') >= 0) {
			isMail = true;
		} else {
			url = "http://"+url;
		}
	}
	return ((url)?("<a href='"+((isMail)?"mailto:":'')+url+"'"+((isMail)?" class='email'":'')+((target)?(" target='"+target+"'"):'')+((title)?(" title='"+title+"'"):'')+">"):'') + text + ((url)?"</a>":'');
}

function $pad(value, length, padding) {
	value = String(value);
	length = parseInt(length, 10) || 2;
	padding = padding || "0";
	while (value.length < length) {
		value = padding + value;
	}
	return value;
}

var pngfix = {
	fix : function(what) {
		if (util.isIE && util.browserVersion < 7.0 && !util.isMac) {
			pngfix._fixImg(what);
		}
	},
	_transparent : "/fileadmin/template/v1/img/transparent.gif",
	_fixImg : function(img) {
		if (img.src.contains(".png") && !img.__pngfix) {
			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,src='"+img.src+"',sizingMethod='scale')";
			img.src = pngfix._transparent;
			img.attachEvent('onpropertychange', pngfix._onchange);
			img.__pngfix = true;
		}
	},
	_init : function() {
		if (util.isIE && util.browserVersion < 8.0 && !util.isMac) {
			try {
				document.execCommand('BackgroundImageCache', false, true);
			} catch(e){}
			if (util.browserVersion < 7.0) {
				$EA('img').each(pngfix._fixImg);
					$EA('*').each(function(el){
						var image = el.currentStyle.backgroundImage, urlStart, urlEnd, sizingMethod;
						if (image.contains(".png") && !el.__pngfix) {
							urlStart = image.indexOf("url(");
							urlEnd = image.indexOf(")", urlStart);
							image = image.substring(urlStart+5, urlEnd-1);
//							if (el.currentStyle.width == 'auto') {
//								el.style.width = '100%';
//							}
							el.style.backgroundImage = "url("+pngfix._transparent+")";
							sizingMethod = (el.currentStyle.backgroundRepeat == 'no-repeat') ? 'crop' : 'scale';
							el.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,src='"+image+"',sizingMethod='"+sizingMethod+"')";
							el.__pngfix = true;
						}
					});
			}
		}
	    return true;
	},
	_inchange : false,
	_onchange : function() {
		if (window.event.propertyName == 'src' && !window.event.srcElement.src.contains(pngfix._transparent) && !pngfix._inchange) {
			pngfix._inchange = true;
			window.event.srcElement.filters.item(0).src = window.event.srcElement.src;
			window.event.srcElement.src = pngfix._transparent;
			pngfix._inchange = false;
		}
	}
};

var $focusElement = null;

function $focus(el, doSelect) {
	el = _$(el);
	$focusElement = el;
	try {
		if (doSelect) {
			el.select();
		}
		el.focus();
	} catch(e) {}
}

function $restoreFocus() {
	if ($focusElement) {
		$focusElement.focus();
	}
}

var util = {

	waitForStyles : false,

	isIE : false,
	isGecko : false,
	isFirefox : false,
	isSafari : false,
	isOpera : false,
	isKonqueror : false,

	isWin : false,
	isMac : false,
	isLinux : false,

	browserVersion : 0,
	webkitVersion : 0,

	onInit : function(func) {
		if (util._inited) {
			func();
		} else {
			util._initqueue.push(func);
		}
	},
	onStart : function(func) {
		if (util._started) {
			func();
		} else {
			util._startqueue.push(func);
		}
	},
	css : function() {
		if (!util._css) {
			util._css = [];
			if (document.styleSheets) {
				var i;
				for (i=0; i<document.styleSheets.length; ++i) {
					util._css = $A(document.styleSheets[i].cssRules || document.styleSheets[i].rules, util._css);
				}
			}
		}
		return util._css;
	},

	_css : null,
	_initqueue : [],
	_startqueue : [],
	_inited : false,
	_started : false,
	_timer : null,
	_load : function() {
		var ua = navigator.userAgent.toLowerCase(), pos, ver;
		ver = parseFloat(navigator.appVersion);
		if (window.opera) {
			util.isOpera = true;
			if ((pos = ua.indexOf("opera")) > 0) {
				ver = parseFloat(ua.substring(pos+6));
			}
		} else if (window.attachEvent) {
			util.isIE = true;
			if ((pos = ua.indexOf("msie")) > 0) {
				ver = parseFloat(ua.substring(pos+5));
			}
		} else if (document.childNodes) {
			if (navigator.taintEnabled) {
				util.isGecko = true;
				if ((pos = ua.indexOf("firefox")) > 0) {
					util.isFirefox = true;
					ver = parseFloat(ua.substring(pos+8));
				}
			} else if (!navigator.accentColorName) {
				if (navigator.vendor == 'KDE') {
					util.isKonqueror = true;
					if ((pos = ua.indexOf("konqueror")) > 0) {
						ver = parseFloat(ua.substring(pos+10));
					}
				} else {
					util.isSafari = true;
					if ((pos = ua.indexOf("safari")) > 0) {
						ver = parseFloat(ua.substring(pos+7));
						if (ver >= 525) {
							ver = 3.1;
						} else if (ver >= 522) {
							ver = 3.0;
						} else if (ver >= 412) {
							ver = 2.0;
						} else if (ver >= 312) {
							ver = 1.3;
						} else if (ver >= 125) {
							ver = 1.2;
						} else if (ver >= 100) {
							ver = 1.1;
						} else if (ver >= 85) {
							ver = 1.0;
						} else if (ver >= 73) {
							ver = 0.9;
						} else if (ver >= 48) {
							ver = 0.8;
						}
					}
				}
			}
		}
		util.browserVersion = ver;
		if ((pos = ua.indexOf("webkit")) > 0) {
			util.webkitVersion = parseFloat(ua.substring(pos+7));
		}
		if (ua.contains("win")) {
			util.isWin = true;
		} else if (ua.contains("mac")) {
			util.isMac = true;
		} else if (ua.contains("linux")) {
			util.isLinux = true;
		}

//		window.onerror = function(){return true;};	// at least try to not totally bug out old browsers
		if (util.isIE) {
			// DOMContentLoaded event hack for IE
			try {
				document.write("<scr"+"ipt id=__onDOMContentLoaded defer src=//:><\/scr"+"ipt>");
				ua = _$("__onDOMContentLoaded");
				if (ua) {
					ua.onreadystatechange = function(){
						if (this.readyState == "complete") {
							this.parentNode.removeChild(this);
							util._start();
						}
					};
				}
			} catch(e) {
				ua = null;
			}
		} else if ((util.isSafari || util.isKonqueror) && typeof document.readyState != 'undefined') {
			// DOMContentLoaded event hack for old Safari and Konqueror (newer Safari builds fire DOMContentLoaded natively!)
			util._timer = setInterval(function(){
				if (document.readyState == "loaded" || document.readyState == "complete") {
					util._start();
				}
			}, 10);
		}
		$attachEvent(document, 'DOMContentLoaded', util._start);
		$attachEvent(window, 'load', util._start);
		$attachEvent(window, 'unload', util._unload);
		
		util._init();
	},
	_unload : function() {
	},
	_init : function() {
		if (util.waitForStyles && document.styleSheets && !document.styleSheets.length) {
			util._init.after(10);
			return;
		}
		util._inited = true;
		var i;
		for (i=0; i<util._initqueue.length; ++i) {
			(util._initqueue[i])();
			util._initqueue[i] = null;
		}
		util._initqueue = [];
	},
	_start : function() {
		if (util._timer) {
			clearInterval(util._timer);
			util._timer = null;
		}
		if (util._started) {	// we only start once!
			return;
		}
		util._started = true;
		pngfix._init();
		var i;
		for (i=0; i<util._startqueue.length; ++i) {
			(util._startqueue[i])();
			util._startqueue[i] = null;
		}
		util._startqueue = [];
	}
};

util._load();

var styledSelect = {
	
	lastOpen : null,
	
	preinit : function() {
		$css("select", "visibility:hidden");
	},

	init : function(doc) {
		$EA(doc, "select").each(function(e){
			var list = $addClass($C("ul"), "styled-select"),
				entry, i;
			for (i=0; i < e.options.length; ++i) {
				entry = $C("li");
				entry.innerHTML = "<span class='"+e.options[i].className+"'>"+e.options[i].text+"</span>";
//				entry.className = e.options[i].className;
				if (e.options[i].selected) {
					$addClass(entry, "styled-select-sel");
				}
				entry._idx = e.options[i].index;
				entry._id = e.id;
				list.appendChild(entry);
				$attachEvent(entry, "click", styledSelect.onClick);
				$attachEvent(entry, "mousedown", styledSelect.onMouseDown);
			}
			$append(e, list);
			$hide(e);
		});
	},
	
	onClick : function(evt, target) {
		var p = target.parentNode;
		if ($hasClass(p, "styled-select-open")) {
			$remClass(p, "styled-select-open");
			$EA(p, "li").each(function(e){
				if (e != target) {
					$remClass (e, "styled-select-sel");
				}
			});
			$addClass(target, "styled-select-sel");
			if (target._id) {
				var el = _$(target._id);
				el.selectedIndex = target._idx;
				if (el.onchange) {
					el.onchange();
				}
			}
		} else {
			$addClass(p, "styled-select-open");
			styledSelect.lastOpen = p;
			$attachEvent(document.body, "mousedown", styledSelect.onCancel);
		}
	}.bindAsEventListener(),
	
	onMouseDown : function(evt, target) {
		return false;
	}.bindAsEventListener(),

	onCancel : function(evt, target) {
		if (styledSelect.lastOpen) {
			$remClass(styledSelect.lastOpen, "styled-select-open");
		}
		$detachEvent(document.body, "mousedown", styledSelect.onCancel);
	}.bindAsEventListener()
};
util.onInit(styledSelect.preinit);
util.onStart(styledSelect.init);




//***********************
//  PICKLIST.JS
//***********************

var _lang = [{ /* german */
		tel:"Tel:",
		fax:"Fax:",
		suppliers:"Lieferanten",
		sortBy:"Sortieren nach",
		email:"E-Mail",
		vcard:"Vcard",
		details:"Details",
		detailsClose:"Schließen",
		contactPerson:"Ansprechpartner",
		gotoSite:"Website im neuen Fenster öffnen",
		sortAZ:"Aufsteigend (A-Z)",
		sortZA:"Absteigend (Z-A)",
		noResults:"Es wurden keine Lieferanten gefunden",
		sendMail:"Lieferant per E-Mail kontaktieren",
		openVcard:"Vcard des Lieferanten herunterladen",
		openDetails:"Detailansicht öffnen",
		closeDetails:"Detailansicht schließen",
		shortDesc:"Kurzprofil",
		
		showMap:"Navigation in neuem Fenster öffnen",
		showSuppliers:"Exporteure anzeigen die dieses Produkt vertreiben",
		showPhotos:"Fotos",
		show360:"360° Ansicht",
		showPDF:"Download PDF",
		articleNo:"Artikel-Nr.",
		specs:"Spezifikationen",
		showRotate:"Drehen",
		showZoom:"Zoom",
		products:"Produkte",
		noProducts:"Es wurden keine Produkte gefunden",
		nextPhoto:"Show next photo",
		prevPhoto:"Show previous photo"
	},{ /* english */
		tel:"Phone:",
		fax:"Fax:",
		suppliers:"Distributors",
		sortBy:"Sort by",
		email:"E-Mail",
		vcard:"Vcard",
		details:"Details",
		detailsClose:"Close",
		contactPerson:"Contact person",
		gotoSite:"Open website in new window",
		sortAZ:"Ascending (A-Z)",
		sortZA:"Descending (Z-A)",
		noResults:"No suppliers found",
		sendMail:"Contact supplier via E-Mail",
		openVcard:"Open Vcard of the supplier",
		openDetails:"Open detail view",
		closeDetails:"Close detail view",
		shortDesc:"Short description",

		showMap:"Open navigation in new window",
		showSuppliers:"Show distributors of this product",
		showPhotos:"Photos",
		show360:"360° View",
		showPDF:"PDF Download",
		articleNo:"Article No.",
		specs:"Specifications",
		showRotate:"Rotate",
		showZoom:"Zoom",
		products:"products",
		noProducts:"No products found",
		nextPhoto:"Show next photo",
		prevPhoto:"Show previous photo"
	},{ /* french */
		tel:"Téléphone:",
		fax:"Téléfax:",
		suppliers:"Distributeur",
		sortBy:"Trier selon",
		email:"E-Mail",
		vcard:"Vcard",
		details:"Détails",
		detailsClose:"Fermer",
		contactPerson:"Interlocuteur",
		gotoSite:"Ouvrer le site web dans une nouvelle fenêtre",
		sortAZ:"Ascendant (A-Z)",
		sortZA:"Descendant (Z-A)",
		noResults:"Aucun distributeur trouvé",
		sendMail:"Prendre contact par e-mail avec le distributeur",
		openVcard:"Ouvrir la V-Card du distributeur",
		openDetails:"Ouvrir la vue détaillée",
		closeDetails:"Fermer la vue détaillée",
		shortDesc:"Profil concis",
		
		showMap:"Ouvrir la navigation dans une nouvelle fenêtre",
		showSuppliers:"Afficher les exportateurs qui distribuent ce produit",
		showPhotos:"Photos",
		show360:"Vue à 360°",
		showPDF:"Télécharger PDF",
		articleNo:"N° d’article",
		specs:"Spécifications",
		showRotate:"Faire tourner",
		showZoom:"Zoom",
		products:"Produits",
		noProducts:"Aucun produit n’a été trouvé",
		nextPhoto:"Show next photo",
		prevPhoto:"Show previous photo"
	},{ /* italian */
		tel:"Telefono:",
		fax:"Fax:",
		suppliers:"Commercianti",
		sortBy:"Ordina per",
		email:"E-Mail",
		vcard:"Vcard",
		details:"Dettagli",
		detailsClose:"Chiudi",
		contactPerson:"Referente",
		gotoSite:"Apri il sito in una nuova finestra",
		sortAZ:"Ordine crescente (A-Z)",
		sortZA:"Ordine decrescente (Z-A)",
		noResults:"Non è stato trovato nessun commerciante",
		sendMail:"Contatta il commerciante via e-mail",
		openVcard:"Apri la Vcard del commerciante",
		openDetails:"Apri la Visualizzazione dettagli",
		closeDetails:"Chiudi la Visualizzazione dettagli",
		shortDesc:"Profilo in forma sommaria",
		
		showMap:"Apri navigazione in una nuova finestra",
		showSuppliers:"Mostra distributori di questo prodotto",
		showPhotos:"Foto",
		show360:"Vista a 360°",
		showPDF:"Scarica PDF",
		articleNo:"Cod. articolo",
		specs:"Specifiche",
		showRotate:"Ruota",
		showZoom:"Zooma",
		products:"prodotti",
		noProducts:"Nessun prodotto trovato",
		nextPhoto:"Show next photo",
		prevPhoto:"Show previous photo"
	},{ /* russian */
		tel:"тел.:",
		fax:"факс:",
		suppliers:"торговец",
		sortBy:"сортировать по",
		email:"E-Mail",
		vcard:"Vcard",
		details:"торговцев",
		detailsClose:"закрыть",
		contactPerson:"контактное лицо",
		gotoSite:"открыть веб-сайт в новом окошке",
		sortAZ:"поднимающийся (А-Я)",
		sortZA:"спускающийся (Я-А)",
		noResults:"Не было найдено торговцев",
		sendMail:"Вступить в контакт с торговцем через e-mail",
		openVcard:"Открыть Vcard торговца",
		openDetails:"открыть детальный вид",
		closeDetails:"закрыть детальный вид",
		shortDesc:"краткое описание",
		
		showMap:"Окрыть навигацию в новом окне",
		showSuppliers:"Показать дистрибьютеров этой продукции",
		showPhotos:"Фотографии",
		show360:"360° вид",
		showPDF:"Скачать PDF",
		articleNo:"Статья №",
		specs:"Спецификации",
		showRotate:"Повернуть",
		showZoom:"Увеличить",
		products:"Продукты",
		noProducts:"Продуктов не найдено",
		nextPhoto:"Show next photo",
		prevPhoto:"Show previous photo"
	},{ /* chinese */
		tel:"电话:",
		fax:"传真:",
		suppliers:"供应商",
		sortBy:"按 … 排序",
		email:"电邮",
		vcard:"名片",
		details:"详情",
		detailsClose:"关闭",
		contactPerson:"联系人",
		gotoSite:"打开新的视窗",
		sortAZ:"按A-Z 排序",
		sortZA:"按Z-A 排序",
		noResults:"没有找到供应商",
		sendMail:"给供应商发邮件",
		openVcard:"打开供应商的电子名片",
		openDetails:"打开详情说明",
		closeDetails:"关闭详情说明",
		shortDesc:"简介",
		
		showMap:"新建窗口",
		showSuppliers:"展示您所需产品的出口公司",
		showPhotos:"Photos",
		show360:"360°全视图",
		showPDF:"下载PDF文件",
		articleNo:"商品号码",
		specs:"订单说明书",
		showRotate:"旋转",
		showZoom:"放缩",
		products:"产品",
		noProducts:"没有找到此产品",
		nextPhoto:"Show next photo",
		prevPhoto:"Show previous photo"
	}, { /* korean */
		tel:"Phone:",
		fax:"Fax:",
		suppliers:"Distributors",
		sortBy:"Sort by",
		email:"E-Mail",
		vcard:"Vcard",
		details:"Details",
		detailsClose:"Close",
		contactPerson:"Contact person",
		gotoSite:"Open website in new window",
		sortAZ:"Ascending (A-Z)",
		sortZA:"Descending (Z-A)",
		noResults:"No suppliers found",
		sendMail:"Contact supplier via E-Mail",
		openVcard:"Open Vcard of the supplier",
		openDetails:"Open detail view",
		closeDetails:"Close detail view",
		shortDesc:"Short description",

		showMap:"Open navigation in new window",
		showSuppliers:"Show distributors of this product",
		showPhotos:"Photos",
		show360:"360° View",
		showPDF:"PDF Download",
		articleNo:"Article No.",
		specs:"Specifications",
		showRotate:"Rotate",
		showZoom:"Zoom",
		products:"products",
		noProducts:"No products found",
		nextPhoto:"Show next photo",
		prevPhoto:"Show previous photo"
	}, { /* vietnamese */
		tel:"Phone:",
		fax:"Fax:",
		suppliers:"Distributors",
		sortBy:"Sort by",
		email:"E-Mail",
		vcard:"Vcard",
		details:"Details",
		detailsClose:"Close",
		contactPerson:"Contact person",
		gotoSite:"Open website in new window",
		sortAZ:"Ascending (A-Z)",
		sortZA:"Descending (Z-A)",
		noResults:"No suppliers found",
		sendMail:"Contact supplier via E-Mail",
		openVcard:"Open Vcard of the supplier",
		openDetails:"Open detail view",
		closeDetails:"Close detail view",
		shortDesc:"Short description",

		showMap:"Open navigation in new window",
		showSuppliers:"Show distributors of this product",
		showPhotos:"Photos",
		show360:"360° View",
		showPDF:"PDF Download",
		articleNo:"Article No.",
		specs:"Specifications",
		showRotate:"Rotate",
		showZoom:"Zoom",
		products:"products",
		noProducts:"No products found",
		nextPhoto:"Show next photo",
		prevPhoto:"Show previous photo"
	},{ /* japanese */
		tel:"電話:",
		fax:"ファックス:",
		suppliers:"販売店",
		sortBy:"分類する",
		email:"Eメール",
		vcard:"Vカード",
		details:"詳細",
		detailsClose:"閉じる",
		contactPerson:"連絡先",
		gotoSite:"新しいウィンドウでウェブサイトを開く。",
		sortAZ:"AからZの順で並べ替え",
		sortZA:"ZからAの順で並べ替え",
		noResults:"サプライヤーは見つかりませんでした。",
		sendMail:"Eメールでサプライヤーに連絡する。",
		openVcard:"サプライヤーのVカードを開く。",
		openDetails:"詳細を見る。",
		closeDetails:"詳細を閉じる。",
		shortDesc:"簡単な説明",

		showMap:"新しいウィンドウでナビを開く。",
		showSuppliers:"この製品を販売している輸出業者を表示する。",
		showPhotos:"写真",
		show360:"360度ビュー",
		showPDF:"PDFをダウンロードする。",
		articleNo:"アイテムナンバー",
		specs:"特性",
		showRotate:"回る",
		showZoom:"ズーム",
		products:"製品",
		noProducts:"製品は見つかりませんでした。",
		nextPhoto:"次の写真を表示する。",
		prevPhoto:"前の写真を表示する。"
	}], _l,
	_isos = ['de', 'en', 'fr', 'it', 'ru', 'zh', 'ko', 'vi', 'ja'], _i;

var picklist = {
	isLoaded : false,
	isProducts : false,
	isIntranet : false,
	selection : [],
	selectedItems : 0,
	updateTimer : null,
	updateCancel : false,
	listView : null,
	listHeader : null,

	init : function() {
		if (!$hasClass(document.body, "picklist") && !$hasClass(document.body, "productlist")) {
			return;
		}
		if ($hasClass(document.body, "productlist")) {
			picklist.isProducts = true;
		}
		if ($hasClass(document.body, "intranett")) {
			picklist.isIntranet = true;
		}
		
		var intranet = _$("intranet2");
		if (intranet) {
			intranet.innerHTML = 'debug: empty string / JSON syntax error!';
		}

		$CNS("navbar").each(function(nb) {
			$EA(nb, "li").each(function(e) {
				var sub = $EA(e, "ul");
				if (sub && sub[0]) {
					$addClass(e, "sub");
					e._sub = sub[0];
					if (picklist.isProducts) {
						e._sub.style.display = "block";
						$addClass(e, "open");
					}
				}
				$attachEvent(e, "click", picklist.onClick);
				$attachEvent(e, "mousedown", picklist.onMouseDown);
				if ($isTag(e.firstChild, 'b')) {
					e._switch = e.firstChild;
					e._id = e._switch.innerHTML.trim().toLowerCase();
					e.id = "switch"+e._id;
					e._switch.innerHTML = "";
					$attachEvent(e._switch, "click", picklist.onSelect);
				}
			});
		});
		
		var _l = _lang[sl];
		var _i = _isos[sl];
        
		picklist.listHeader = $CN("content").appendChild($hide($addClass($C("div"), "picklist-header")));
		picklist.listView = $CN("content").appendChild($hide($addClass($C("div"), "picklist-wrap")));
		picklist.listHeader.innerHTML = "<div class='stat'>0</div> | <div class='sel'>-</div>"+
			"<select size='1' onchange='picklist.switchSort(this);return false' id='picklist-sort'>"+
			"<option value='AZ' selected='selected'>"+_l.sortAZ+"</option>"+
			"<option value='ZA'>"+_l.sortZA+"</option>"+
			"</select>";
		styledSelect.init(picklist.listHeader);
	},
	
	onClick : function(evt, target) {
		if (target._sub) {
			if ($visible(target._sub)) {
				target._sub.style.display = "none";
				$remClass(target, "open");
			} else {
				target._sub.style.display = "block";
				$addClass(target, "open");
			}
		} else if (target._switch) {
			picklist.handleSwitch(target);
		}
		return false;
	}.bindAsEventListener(),
	
	onMouseDown : function(evt, target) {
		return false;
	}.bindAsEventListener(),
	
	onSelect : function(evt, target) {
		picklist.handleSwitch(target.parentNode);
		return false;
	}.bindAsEventListener(),
	
	handleSwitch : function(el, state, isRecursive) {
		if (!el._switch) {
			return;
		}
		if ($hasClass(el._switch, "act")) {
			if (state !== true) {
				$remClass(el._switch, "act");
				if (picklist.selection[el._id]) {
					--picklist.selectedItems;
				}
				delete picklist.selection[el._id];

				if (!isRecursive) {
					if(el._sub) {
						$EA(el, "li").each(function(e){picklist.handleSwitch(e, false, true);});
					}
					picklist.update();
				}
			}
		} else if (state !== false) {
			$addClass(el._switch, "act");
			picklist.handleSwitch(el.parentNode.parentNode, true, true);
			if (!picklist.selection[el._id]) {
				++picklist.selectedItems;
			}
			picklist.selection[el._id] = {name:el.firstChild.nextSibling.data.trim(), hasSub:((el._sub)?true:false)};

			if (!isRecursive) {
				if (el._sub) {
					$EA(el, "li").each(function(e){picklist.handleSwitch(e, true, true);});
				}
				picklist.update();
			}
		}
	},
	
	clearSel : function() {
		picklist.selection = [];
		picklist.selectedItems = 0;

		$EA($CN("navbar"), "li").each(function(el) {
			if (el._switch) {
				$remClass(el._switch, "act");
			}
		});
	},
	
	update : function() {

		picklist.updateCancel = true;
		if (picklist.updateTimer) {
			window.clearTimeout(picklist.updateTimer);
		}

		if (picklist.selectedItems > 0) {
			picklist.updateTimer = picklist.updateHTML.after(300);

		} else {
			picklist.showPicklist(false);
		}
	},
	
	showPicklist : function(sw) {
		var el = $CN("picklist-intro-flash");
		if (sw && $visible(el)) {
			$hide(el);
			new $fade($CN("newsbar"), 100, 0, 300);
			new $fade($CN($CN("newsbar-wrap"), "bg"), 100, 0, 300);
			new $fade($CN($CN("newsbar-wrap"), "login"), 100, 0, 300);
			new $fade($CN("col23"), 100, 0, 300);
			$show.delay(300, picklist.listHeader);
			$show.delay(500, picklist.listView);
//			$show(picklist.listView);
		} else if (!sw && !$visible(el)) {
			$hide(picklist.listView);
			$hide(picklist.listHeader);
//			new $fade(picklist.listView, 100, 0, 100);
			new $fade($CN("col23"), 0, 100, 300, 100);
			new $fade($CN($CN("newsbar-wrap"), "bg"), 0, 100, 300, 100);
			new $fade($CN($CN("newsbar-wrap"), "login"), 0, 100, 300, 100);
			new $fade($CN("newsbar"), 0, 100, 300, 100);
			$show(el);
		}
	},
	
	sortAs : "AZ",

	updateHTML : function() {
		picklist.updateCancel = false;
		picklist.updateTimer = null;
		picklist.listView.innerHTML = "";
		picklist.showPicklist(true);

		var i, sel, matches, total = 0, idx, newDiv;
        var _l = _lang[sl];
		var _i = _isos[sl];
        
		if (picklist.isProducts) {
			for (i=0; i<ad_productcatalog_db.length && !picklist.updateCancel; ++i) {
				idx = (picklist.sortAs == "AZ") ? i : (ad_productcatalog_db.length - i - 1);
				matches = false;
				for (sel in picklist.selection) {
					if (typeof picklist.selection[sel] != 'function') {
						if (ad_productcatalog_db[idx].cat == sel) {
							matches = true;
						}
					}
				}
	
				if (matches) {
					if (!ad_productcatalog_db[idx].html) {
						picklist.printProductHTML(ad_productcatalog_db[idx], idx);
					}
					if (!ad_productcatalog_db[idx].html) {
						continue;
					}
					++total;
					newDiv = $C("div");
					newDiv.innerHTML = ad_productcatalog_db[idx].html;
					newDiv.lastChild.id = idx;
					picklist.listView.appendChild(newDiv);
				}
			}
			jQuery(".jqfancybox").fancybox({
				"padding": 0,
				"speedIn": 300,
				"speedOut": 300,
				"changeSpeed": 300,
				"transitionIn": "elastic",
				"transitionOut": "elastic",
				"titlePosition": "over",
				"titleShow": true,
				"easingIn": "swing",
				"easingOut": "swing",
				"showCloseButton": true,
				"showNavArrows": true,
				"enableEscapeButton": true,
				"overlayShow": true,
				"overlayOpacity": 0.7,
				"overlayColor": "#666",
				"centerOnScroll": true,
				"hideOnContentClick": true
			});
		} else {
			for (i=0; i<ad_picklist_db.length && !picklist.updateCancel; ++i) {
				idx = (picklist.sortAs == "AZ") ? i : (ad_picklist_db.length - i - 1);
				matches = false;
				for (sel in picklist.selection) {
					if (typeof picklist.selection[sel] != 'function' && ad_picklist_db[idx][sel]) {
						matches = true;
					}
				}
	
				if (matches) {
					++total;
					if (!ad_picklist_db[idx].html) {
						picklist.printHTML(ad_picklist_db[idx]);
					}
					newDiv = $C("div");
					newDiv.innerHTML = ad_picklist_db[idx].html;
					newDiv.lastChild.id = idx;
					picklist.listView.appendChild(newDiv);
				}
			}
		}
		if(!total) {
			picklist.listView.innerHTML = "<div class='list-no-results'>" + ((picklist.isProducts)?_l.noProducts:_l.noResults) + "</span>";
		}
		$CN(picklist.listHeader, 'stat').innerHTML = total+' '+((picklist.isProducts)?_l.products:_l.suppliers);

		var buf = "", entry = null;
		for (sel in picklist.selection) {
			if (typeof picklist.selection[sel] == 'function' || (picklist.selection[sel].name && picklist.selection[sel].name == 'array')) {
				continue;
			}
			if (entry) {
				buf += (entry.hasSub) ? ": " : " + ";
			}
			entry = picklist.selection[sel];
			buf += entry.name;
			if (buf.length > 150) {
				buf += "...";
				break;
			}
		}
		$CN(picklist.listHeader, 'sel').innerHTML = buf;
	},

	viewPrev : function(el) {
		var entry = $CNP(el, 'entry'),
			image = $CN(entry, 'productImage2'),
			zoom = $CN(entry, 'jqfancybox');
		if ($visible(image)) {
			new $fade(image, 100, 0, 250);
			zoom.href = zoom.href.replace("_2.jpg", "_1.jpg");
		} else {
			new $fade(image, 0, 100, 250);
			zoom.href = zoom.href.replace("_1.jpg", "_2.jpg");
		}
	},
	viewNext : function(el) {
		picklist.viewPrev(el);
	},

	printProductHTML : function(db, id) {
		var _l = _lang[sl];
		var _i = _isos[sl];
		var name = db['name'+_i];
		if (!name) {
			name = db['nameen'];
			if (!name) {
				return;
			}
		}
		db.part = db.part.toLowerCase();

		db.html = "<div class='entry'>";
		if (db.image) {
			db.html += "<div class='logo'><a href='#showPhotos' class='details' onclick='picklist.showPhotos(this);return false' style='outline:none' title='"+_l.showPhotos+"' ><img src='/media/" + db.thumb + "' width='145' alt='"+name+" Photo' /></a></div>";
		}
		db.html += "<span class='id'>"+_l.articleNo+": " + db.articleid + "</span>";
		db.html += "<h1>"+name+"</h1>";

		db.html += "<div class='overview'>";
//		db.html += _l.specs+": ";
		db.html += "</div>";

		db.html += "<div class='buttons'>";
		db.html += "<a href='/media/" + db.pdf +"' class='details last' target='_blank' title='"+_l.showPDF+"' >"+_l.showPDF+"</a>";
		db.html += "<a href='#show360' class='show360 details"+((db.base360)?"":" inact")+"' onclick='picklist.show360(this);return false' title='"+_l.show360+"' >"+_l.show360+"</a>";
		db.html += "<a href='#showPhotos' class='showphotos details"+((db.image)?"":" inact")+"' onclick='picklist.showPhotos(this);return false' title='"+_l.showPhotos+"' >"+_l.showPhotos+"</a>";
		db.html += "<a href='#showSuppliers' class='showsuppliers details' onclick='picklist.showSuppliers(this);return false' title='"+_l.showSuppliers+"' >"+_l.suppliers+"</a>";
		db.html += "</div>";
        
		db.html += "<div class='view-wrap'><div class='supplierview' style='display:none'></div>";
		db.html += "<div class='photoview' style='display:none'><a href='#viewPrev' onclick='picklist.viewPrev(this);return false' class='photoViewPrev' title='"+_l.prevPhoto+"' style='"+((db.imagenum>1)?"":"visibility:hidden")+"'></a><a href='#viewNext' onclick='picklist.viewNext(this);return false' class='photoViewNext' title='"+_l.nextPhoto+"' style='"+((db.imagenum>1)?"":"visibility:hidden")+"'></a><a href='/media/"+db.image+"' rel='fancybox"+id+"' class='jqfancybox' title='"+name+" &nbsp;|&nbsp; "+_l.articleNo+": "+((db.id)?db.id:((db.idcma)?db.idcma:db.idwf))+"'><img src='/media/"+db.image+"' width='530' alt='"+name+" Photo' title='"+name+" &nbsp;|&nbsp; "+_l.articleNo+": "+((db.id)?db.id:((db.idcma)?db.idcma:db.idwf))+"' class='productImage' /><img src='/media/"+db.image.replace("_1.jpg", "_2.jpg")+"' width='530' alt='"+name+" Photo' title='"+name+" &nbsp;|&nbsp; "+_l.articleNo+": "+((db.id)?db.id:((db.idcma)?db.idcma:db.idwf))+"' class='productImage2' style='visibility:hidden' /></a></div>";
		db.html += "<div class='threesixtyview' style='display:none'></div></div>";

		db.html += "</div>";
	},
	
	printOverviewHTML : function(dest, db) {
		var _l = _lang[sl];
		var _i = _isos[sl];
		db.postalcode = $pad(db.postalcode, 5);
		if (db.logoname) {
			dest.html += "<div class='logo'>"+$link("<img src='/media/"+db.logoname+"' width='"+((dest == db)?155:100)+"' alt='Logo "+db.name+"' />", db.url, "_blank", _l.gotoSite)+"</div>";
		}
		dest.html += "<h1>"+db.name+"</h1>";
		dest.html += "<div class='overview'><div class='c1'>";
		if (dest == db) {
			dest.html += $link(db.name1+' '+db.surname1, db.email1, null, _l.sendMail)+"<br/>"+((db.surname2)?$link(db.name2+' '+db.surname2, db.email2, null, _l.sendMail):'')+"<br/><br/>";
		}
		dest.html += db.street+' '+db.streetnr+"<br/>"+db.postalcode+' '+db.city;
		dest.html += "</div><div class='c2'>";
		if (dest == db) {
			dest.html += $link(db.email1, db.email1, null, _l.sendMail)+"<br/>"+((db.email2)?$link(db.email2, db.email2, null, _l.sendMail):'')+"<br/><br/>";
		}
		dest.html += _l.tel+' '+db.phone+"<br/>";
		dest.html += _l.fax+' '+db.fax+"<br/>";
		dest.html += "</div><div class='c3'>";
		dest.html += ((db.url)?$link(db.url, db.url, "_blank", _l.gotoSite):'');
		if (dest != db) {
			dest.html += "<br/>"+$link(db.email1, db.email1, null, _l.sendMail);
		}
		dest.html += "</div></div>";
	},
	
	showSuppliers : function(el) {
		var entry = $CNP(el, "entry"),
			suppliers = $CN(entry, "supplierview"),
			photos = $CN(entry, "photoview"),
			threesixty = $CN(entry, "threesixtyview");
		if (!$visible(suppliers)) {
			if ($visible(photos)) {
				$remClass($CN(entry, "showphotos"), "act");
				new $fade(photos, 100, 0, 200);
				if(util.isIE && util.browserVersion >= 8.0) {
					new $fade($EA(photos, "img"), 100, 0, 200);
				}
			}
			if ($visible(threesixty)) {
				$remClass($CN(entry, "show360"), "act");
				$hide(threesixty);
			}
			if (!suppliers.firstChild) {
				var db = ad_productcatalog_db[entry.id];
				if (!db.supplierview) {
					db.supplierview = { html:"" };
					for (var i=0; i<ad_picklist_db.length && !picklist.updateCancel; ++i) {
						if (ad_picklist_db[i][db.part] == 1) {
							db.supplierview.html += "<div class='supplier'>";
							picklist.printOverviewHTML(db.supplierview, ad_picklist_db[i]);
							db.supplierview.html += "</div>";
						}
					}
				}
				suppliers.innerHTML = db.supplierview.html;
			}
			new $fade(suppliers, 0, 100, 300);
			$addClass($CN(entry, "showsuppliers"), "act");
//			window.location.hash = entry.id;
		} else {
			new $fade(suppliers, 100, 0, 200);
			$remClass($CN(entry, "showsuppliers"), "act");
		}
	},
	
	showPhotos : function(el) {
		if ($hasClass(el, "inact")) {
			return;
		}
		var entry = $CNP(el, "entry"),
			suppliers = $CN(entry, "supplierview"),
			photos = $CN(entry, "photoview"),
			threesixty = $CN(entry, "threesixtyview");
		if (!$visible(photos)) {
			if ($visible(suppliers)) {
				$remClass($CN(entry, "showsuppliers"), "act");
				new $fade(suppliers, 100, 0, 200);
			}
			if ($visible(threesixty)) {
				$remClass($CN(entry, "show360"), "act");
				$hide(threesixty);
			}
			new $fade(photos, 0, 100, 300);
			if(util.isIE && util.browserVersion >= 8.0) {
				new $fade($EA(photos, "img"), 0, 100, 300);
			}
			$addClass($CN(entry, "showphotos"), "act");
		} else {
			new $fade(photos, 100, 0, 200);
			if(util.isIE && util.browserVersion >= 8.0) {
				new $fade($EA(photos, "img"), 100, 0, 200);
			}
			$remClass($CN(entry, "showphotos"), "act");
		}
	},
	
	show360 : function(el) {
		if ($hasClass(el, "inact")) {
			return;
		}
		var entry = $CNP(el, "entry"),
			suppliers = $CN(entry, "supplierview"),
			photos = $CN(entry, "photoview"),
			threesixty = $CN(entry, "threesixtyview");
		if (!$visible(threesixty)) {
			if ($visible(suppliers)) {
				$remClass($CN(entry, "showsuppliers"), "act");
				new $fade(suppliers, 100, 0, 200);
			}
			if ($visible(photos)) {
				$remClass($CN(entry, "showphotos"), "act");
				new $fade(photos, 100, 0, 200);
				if(util.isIE && util.browserVersion >= 8.0) {
					new $fade($EA(photos, "img"), 100, 0, 200);
				}
			}

			threesixty.innerHTML = "<div id='viewer-"+entry.id+"'></div>";
			var param = {
				width: 640,
				height: 480, //500,
				file: "/media/" + ad_productcatalog_db[entry.id].flash,
				usefullscreen: "true",
				backcolor: "0xFFFFFF",
				screencolor: "0xFFFFFF",
				shownavigation: "false",
				showdigits: "false",
				showvolume: "false",
				repeat: "true",
				autostart: "true"/*,
				bufferlength: "1.0"*/
			}//, viewer = "/typo3conf/ext/rgmediaimages/res/mediaplayer.swf";
			, viewer = "/media/base/flash/scanworx_viewer.swf";
			swfobject.embedSWF(viewer, "viewer-"+entry.id, param.width, param.height, "9.0.0", false, param, {menu:"false", quality:"high", /*scale:"noscale", salign:"tl",*/ allowscriptaccess:"always", allowfullscreen:"true"});

//			new $fade(photos, 0, 100, 300);
			$show.delay(200, threesixty);
			$addClass($CN(entry, "show360"), "act");
		} else {
//			new $fade(photos, 100, 0, 200);
			$hide(threesixty);
			$remClass($CN(entry, "show360"), "act");
		}
	},
	
	printHTML : function(db) {
		var _l = _lang[sl];
		var _i = _isos[sl];
		db.html = "<div class='entry'>";

		picklist.printOverviewHTML (db, db);

		db.html += "<div class='detailview' style='display:none'><div class='c1'>";
		db.html += db.street+' '+db.streetnr+"<br/>";
		db.html += db.postalcode+' '+db.city+"<br/>";
		if(db.surname1 && db.phone1) {
			db.html += "<br/>";
			db.html += "<b>"+_l.contactPerson+":</b><br/><br/>";
			db.html += db.name1+' '+db.surname1+"<br/>";
			db.html += "<br/><br/>";
			if(db.surname2) {
				db.html += db.name2+' '+db.surname2+"<br/>";
			}
		}
		db.html += "</div><div class='c2'>";
		db.html += _l.tel+' '+db.phone+"<br/>";
		db.html += _l.fax+' '+db.fax+"<br/>";
		if(db.surname1 && db.phone1) {
			db.html += "<br/>";
			db.html += "<br/><br/>";
			db.html += _l.tel+' '+db.phone1+"<br/>";
			db.html += $link(db.email1, db.email1, null, _l.sendMail)+"<br/><br/>";
			if(db.surname2 && db.phone2) {
				db.html += _l.tel+' '+db.phone2+"<br/>";
				db.html += $link(db.email2, db.email2, null, _l.sendMail)+"<br/>";
			}
		}
		db.html += "</div><div class='c3'>";
		db.html += ((db.url)?$link(db.url, db.url, "_blank", _l.gotoSite):'');
		db.html += "</div><div class='c12'>";
		var desc = db['desc'+_i];
		if (desc) {
			db.html += "<b>"+_l.shortDesc+":</b><br/><br/>";
			db.html += desc.replace(/\n/g,"<br/>");
		}
		db.html += "</div></div>";

		db.html += "<div class='buttons'>";
		db.html += $link(_l.email, db.email1 || db.email2, null, _l.sendMail);
		db.html += "<a href='/vcard/" + db.id + "/' class='vcard' title='"+_l.openVcard+"'>"+_l.vcard+"</a>";
		db.html += "<a href='#switchDetails' class='details last' onclick='picklist.switchDetails(this);return false' title='"+_l.openDetails+"' >"+_l.details+"</a>";
		db.html += "</div></div>";
	},
	
	geoCoder : null,

	switchDetails : function(el) {
		var _l = _lang[sl];
		var _i = _isos[sl];
		var entry = el.parentNode.parentNode,
			details = $CN(entry, "detailview"),
			overview = $CN(entry, "overview");
		if ($visible(details)) {
			$hide(details);
			$show(overview);
			el.innerHTML = _l.details;
			el.title = _l.openDetails;
			$remClass(el, "close");
		} else {
			$hide(overview);
			$show(details);
			el.innerHTML = _l.detailsClose;
			el.title = _l.closeDetails;
			$addClass(el, "close");

			var mapWrap = $CN(details, "map");
			if (!mapWrap && GBrowserIsCompatible()) {
				if (!picklist.geoCoder) {
					picklist.geoCoder = new GClientGeocoder();
				}
				mapWrap = $addClass($C("div"), "map");
				mapWrap = details.insertBefore(mapWrap, $CN(details, "c12"));
				var db = ad_picklist_db[entry.id];
				picklist.geoCoder.getLatLng(db.street+" "+db.streetnr+", "+db.postalcode+" "+db.city+", Germany", function(point){picklist.updateMap(point, mapWrap, db);});
			}
		}
	},

	updateMap : function(point, mapWrap, db) {
		var _l = _lang[sl];
		var _i = _isos[sl];
		var map = new GMap(mapWrap), marker = new GMarker(point, {title:_l.showMap});
		map.centerAndZoom(point, 4);
		map.addControl(new GSmallMapControl());
		map.setMapType(G_NORMAL_MAP);
		var address = db.street+" "+db.streetnr+", "+db.postalcode+" "+db.city+", Germany";
		GEvent.addListener(marker, "click", function(){window.open("http://maps.google.com/maps?q="+address.replace(/ /g,"+"),target='_blank')});
		map.addOverlay(marker);
//		var html = "<div class='map-overlay' style='width:50px;height:1em'>"+db.street+" "+db.streetnr+", "+db.postalcode+" "+db.city+"</div>";
//		marker.openInfoWindowHtml(html, {maxWidth:"50"});
	},
	
	switchSort : function(el) {
		picklist.sortAs = el.options[el.selectedIndex].value;
		picklist.update();
	}
};
util.onStart(picklist.init);


var partnav = {
	
	zindex : 1,
	fade : null,
	fadeId: 0,

	init : function() {
		partnav.initDiv(_$("beefNav"), 200, 208);
		partnav.initDiv(_$("porkNav"), 100, 108);
	},
	
	initDiv : function(div, from, to) {
		if((div = _$(div))) {
			var i, img = $EA(div, "img")[0],
				map = img.getAttribute("usemap"), width = img.width, height = img.height;
	
			img.id = "partnav_"+Math.floor(from/100);
	
			for (i=from; i <= to; ++i) {
				img = $C("img");
				img.id = "partnav_"+i;
				img.width = width;
				img.height = height;
				img.setAttribute("usemap", map);
				img.src = "/media/base/images/productcatalog/part_"+i+".gif";
				div.appendChild($show(img, true, 0));
			}
			
			$EA(map.replace('#', ''), "area").each(function(e){
				e._id = e.href.substring(e.href.indexOf('#')+2);
				$attachEvent(e, "mouseover", partnav.onOver);
				$attachEvent(e, "mouseout", partnav.onOut);
				$attachEvent(e, "click", partnav.onClick);
			});
		}
	},
	
	onOver : function(evt, target) {
		if (target._id != partnav.fadeId) {
			var part = _$("partnav_"+target._id);
			if (partnav.fade && partnav.fade.stop) {
				partnav.fade.stop();
			}
			partnav.fade = new $fade(part, 0, 100, 200, 0, partnav.zindex++);
			partnav.fadeId = target._id;
		}
	}.bindAsEventListener(),
	
	onOut : function(evt, target) {
//		if (target._id != partnav.sel) {
			var part = _$("partnav_"+Math.floor(target._id/100));
			if (partnav.fade && partnav.fade.stop) {
				partnav.fade.stop();
			}
			partnav.fade = new $fade(part, 0, 100, 200, 50, partnav.zindex++);
			partnav.fadeId = Math.floor(target._id/100);
//		}
	}.bindAsEventListener(),
	
	onClick : function(evt, target) {
		picklist.clearSel();
		picklist.handleSwitch(_$("switch"+target._id));
		return false;
	}.bindAsEventListener()

};
util.onStart(partnav.init);

var login = {
    init : function() {
        $attachEvent("user", "focus", login.onFocus);
        $attachEvent("user", "blur", login.onBlur);
        $attachEvent("pass", "focus", login.onFocus);
        $attachEvent("pass", "blur", login.onBlur);
    },
    onFocus : function(evt, target) {
        if (target.value == target.defaultValue) {
            target.value = '';
            if (target.id == "pass") {
                target.type = 'password';
            }
        }
    }.bindAsEventListener(),
        onBlur : function(evt, target) {
            if (target.value == '') {
                target.value = target.defaultValue;
                if (target.id == 'pass') {
                    target.type = 'text';
                }
            }
        }.bindAsEventListener()
    };
util.onStart(login.init); 

