var googlekey = 'ABQIAAAAy-MfgKvKUTrUdcDeLLAi0RTrwj2f8gGJzhVd88sfLN3bEnC5bxSzV0ogvV--3iCM0v6Fkd2j-4ueQw';
var showgooglemaps = false;
if (document.location.pathname.match(/\/anfahrt\//)) {
	showgooglemaps = true
	document.write('<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=' + googlekey + '" type="text/javascript"></script>');
}
var gdir;
var marker;
var dirlist;
var psl;
function initialize() {
	if (GBrowserIsCompatible()) {
		var point = new GPoint(11.2817206, 50.4709214);
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GMenuMapTypeControl());
		map.addControl(new GLargeMapControl());
		map.enableScrollWheelZoom();
		map.setCenter(new GLatLng(point.y, point.x), 6);
		marker = new GMarker(point);
		var txt = '<div class="ccontent">Ernst Roeser Siebdruckerei GmbH<br>Glash&uuml;ttenplatz 8-10<br>D-96355 Tettau/Ofr.<br><br>Tel.: +49 (0) 9269 984-0<br>Fax.: +49 (0) 9269 984-17<br>Email: <a href="&#109;&#97;&#105;&#108;&#116;&#111;:in%66%6f%40%65%72o%65s%65r%2e%64%65">&#105;&#110;&#102;&#111;&#64;er&#111;eser&#46;&#100;&#101;</a><br>Website: <a href="http://www.eroeser.com">www.eroeser.com</a></div>';
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(txt);
		});
		map.addOverlay(marker);
		gdir = new GDirections(map, dirlist.dom);
		GEvent.addListener(gdir, "addoverlay", function() {
			var fbg = Ext.get('framebg');
			var fr = Ext.get('frame');
			fbg.setHeight(fr.getHeight() + 50);
		});
	}
};
function setDirections(fromAddress) {
	gdir.load("from: " + fromAddress + " to: 96355 Tettau, Glashüttenplatz 8-10", {
		"locale" : "de"
	});
	marker.closeInfoWindow();
};
runOnLoad( function() {
	psl = Ext.get('bildslider');
	if (psl) {
		/*Ext.QuickTips.init();
		Ext.QuickTips.enable();*/
		var piccnt = Ext.get('piccontainer');
		var slidelinks = Ext.select('#piccontainer a.slidelink');
		var total = slidelinks.getCount();
		slidelinks.each( function(link) {
			piccount++;
			var w = link.down('img').getWidth();
			if (piccount == (total / 2) + 1) {
				flippos = ewidth;
			};
			ewidth += w;
			link.on('click', function(ev, el) {
				var teaser = el.parentNode.getAttribute('teaser');
				var title = el.parentNode.getAttribute('slidetitle');
				var box = Ext.get(el).getBox();
				var src = el.src.replace(/\/media\/med_/, '/org/med_');
				Ext.Msg.show( {
				    animEl : el,
				    msg : '<div style="width:400px;"><center><b>' + title + '</b><br><br><img id="prv" src="' + src + '"><br>' + teaser + '</center></div>'
				});
				//Ext.Msg.getDialog().setContentSize(box.width, box.height + 50);
				Ext.get('prv').on('load', function(e, i) {
					Ext.Msg.getDialog().setContentSize(i.width, i.height);
				});
				//Ext.Msg.getDialog().setContentSize(400, 400);
			});
		});
		var tw = Math.floor(ewidth / 2);
		var pw = psl.getWidth();
		if (tw < pw) {
			psl.setWidth(tw);
			var sw = Math.floor((pw - (ewidth / 2)) / 2);
			Ext.get('slideright').setWidth(sw);
			Ext.get('slideleft').setWidth(sw);
		}
	};
	if (showgooglemaps) {
		var mc = Ext.getDom('maincontent');
		Ext.DomHelper.append(mc, {
			tag : 'div',
			id : 'map',
			style : 'height:360px;'
		});
		Ext.DomHelper.append(mc, {
			tag : 'div',
			id : 'dirfrm',
			style : 'padding: 10px 0 10px 0; height:20px;',
			html : '<form action="#" onsubmit="setDirections(this.from.value); return false"><table><tbody><tr><td align="right">Anfahrt von:&nbsp;</td><td><input id="fromAddress" size="25" name="from" type="text" /></td><td><input type="submit" name="submit" value="Anzeigen" /></td></tr></tbody></table></form>'
		});
		dirlist = Ext.DomHelper.append(mc, {
			tag : 'div',
			id : 'dirlist'
		}, true);
		initialize();
	};
	var fbg = Ext.get('framebg');
	var fr = Ext.get('frame');
	var he = fr.getHeight();
	if (window.navigator.appVersion.match(/MSIE 6/)) {
		//he += psl.getHeight() + 20;
		he = Ext.get('bottommenu').getBox().y;
	};
	fbg.setHeight(he);
	fbg.setOpacity(.7);
	if (!document.location.pathname.match(/\/[^\/]+\//)) {
		var h = Ext.get('home');
		if (h) {
			h.dom.firstChild.className = 'topmenuactive';
		}
	};
});
var timer = false;
var stopslide = false;
var flippos = 0;
var acc = 1;
var offx = 0;
var piccount = 0;
var curdir = '';
var ewidth = 0;
var slide = function(dir) {
	if (!psl) return;
	curdir = dir;
	if (dir == "right") {
		offx -= acc;
	} else {
		offx += acc;
	};
	if (offx >= flippos) {
		offx = 0;
		psl.scrollTo('left', offx);
		return;
	};
	if (offx <= 0) {
		offx = flippos;
		psl.scrollTo('left', offx);
		return;
	};
	psl.scrollTo('left', offx);
};
var startslide = function(dir) {
	acc = 1;
	if (timer) {
		if (curdir != dir) {
			window.clearInterval(timer);
			timer = false;
			startslide(dir);
		};
		return;
	};
	timer = window.setInterval("slide('" + dir + "')", 10);
};
var stopslide = function() {
	window.clearInterval(timer);
	timer = false;
};
var playslideshow = function() {
	if (timer) return;
	acc = 0.3;
	timer = window.setInterval("slide('left')", 10);
};
