var isIE=document.all?true:false;
var isDOM=document.getElementById?true:false;
var isNS4=document.layers?true:false;

// Images austauschen auf MouseOver (für Navigation etc.)

function ai_swapImgRestore() { 
  var i,x,a=document.ai_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function ai_preloadImages() { 
  var d=document; if(d.images){ if(!d.ai_p) d.ai_p=new Array();
    var i,j=d.ai_p.length,a=ai_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.ai_p[j]=new Image; d.ai_p[j++].src=a[i];}}
}

function ai_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=ai_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function ai_swapImage() { 
  var i,j=0,x,a=ai_swapImage.arguments; document.ai_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=ai_findObj(a[i]))!=null){document.ai_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// _w : which ID (1) or (2) 
// _h : (h)ide or (s)how 


function toggleT(_w,_h) {
	if (isDOM)
		{
		if (_h=='s') document.getElementById(_w).style.display='block';
		if (_h=='h') document.getElementById(_w).style.display='none';
		}
	else if (isIE) {
		if (_h=='s') eval("document.all."+_w+".style.display='block';");
		if (_h=='h') eval("document.all."+_w+".style.display='none';");
		}
	else if(isNS4)
		{
		if (_h=='s') eval("document.layers['"+_w+"'].display='block';");
		if (_h=='h') eval("document.layers['"+_w+"'].display='none';");
		}
	}


function show_tips(tip_class)
{
if($$(tip_class).length > 0)
	{
		//store titles and text  
		$$(tip_class).each(function(element,index) {  
			if (element.get('title')) {
			var content = element.get('title').split('::');  
			element.store('tip:title', content[0]);  
			element.store('tip:text', content[1]);
			}
		}); 

		var tips = new Tips($$(tip_class))
 
		tips.addEvent('show', function(tip){
			tip.fade('in');
		});
		tips.addEvent('hide', function(tip){
			tip.fade('out');
		});
 
 
		$$(tip_class).each(function(el)	{
			var children = el.getChildren();
			children.each(function(tip_html){
				if (tip_html.hasClass('tip_title')) el.store('tip:title', tip_html.get('html'));
				if (tip_html.hasClass('tip_text')) el.store('tip:text', tip_html.get('html'));
			}); 
		});
	}
} 
window.addEvent('domready', function() {
	show_tips(".hilfe");
});

function ZumWarenkorb(){
	var winScroller = new Fx.Scroll(window);
	/*	scroll to the Warenkorb	*/
	winScroller.toElement('MeinWarenkorb');

	exampleFx = new Fx.Tween('MeinWarenkorb', {
		property: 'opacity',
		duration: 250, 
		transition: Fx.Transitions.Quart.easeInOut,
		link: 'chain'

	});
	exampleFx.start(1,0).start(0,1).start(1,0).start(0,1).start(1,0).start(0,1); /* 3x ein- und ausblenden*/
 }
function ZumDiv(id){
	var winScroller = new Fx.Scroll(window);
	winScroller.toElement(id);
}

function Zum99(){
	var winScroller = new Fx.Scroll(window);
	/*	scroll to the Warenkorb	*/
	winScroller.toElement('99');

	exampleFx = new Fx.Tween('99', {
		property: 'opacity',
		duration: 250, 
		transition: Fx.Transitions.Quart.easeInOut,
		link: 'chain'

	});
	exampleFx.start(1,0).start(0,1).start(1,0).start(0,1).start(1,0).start(0,1); /* 3x ein- und ausblenden*/
 }


// Ende: ToolTips (MooTools)


var tn_on_id=-1;
function tn_lo(id) {if (tn_on_id!=id) {tn_set(id,"lo");}}
function tn_hi(id) {if (tn_on_id!=id) {tn_set(id,"hi");}}
function tn_on(id) {tn_set(tn_on_id,"lo"); tn_on_id=id; tn_set(tn_on_id,"on");}
function tn_set(id,mode)
{
	var className="tn";
	var obj=null;
	if (mode=="hi") {className+="_hi";} else if (mode=="on") {className+="_on";}
	if (id>=0) {obj=document.getElementById('tn_'+id);}
	if (obj) {obj.className=className;}
}


// functions for window handling
var isopen=false;

function winClose(winname)
{ winname.close(); }

function lexilaunch(newURL, newName, newFeatures, orgName)
{ if( (isopen) && (!remote.closed) ){ winClose(remote); }
  var remote = window.open(newURL, newName, newFeatures);
  remote.window.opener.name = orgName;
}

// PopUp-Fenster

function popupWindow(url,titel,zusatz) {
		  newWindow = window.open(url,"titel",zusatz);
		  newWindow.focus();
		}
		
// PopUp-Fenster: ENDE

// Schriftgroessen anpassen

function FontSize(_size, _targets, _exceptions) {
	this.size = _size || 11;
	this.min = 9;
	this.max = 16;
	this.targets = _targets || ['fsTextbody','fsInfoBox','fsHeadnormal'];
	this.exceptions = _exceptions || 'haferbrei#hirsebrei#';
	this.lucky = this.checkBrowser();
}
FontSize.prototype = {
larger : function() {
	(this.size < this.max) ? ++this.size : this.size;
	if (this.lucky) this.scale();
},
smaller : function() {
	(this.size > this.min) ? --this.size : this.size + 'px';	 
	if (this.lucky) this.scale();
},
scale : function() {
	var oTarget = null;
	for (var k = 0; k < this.targets.length; k++) {
		oTarget = document.getElementById(this.targets[k]);
		if (oTarget) this.changeSize(oTarget);  
	}
},
changeSize : function(oo) {
	if (oo.style) {
		oo.style.fontSize = this.size + 'px';
		oo.style.lineHeight = '1.3em';
	}
	for (var k = 0; k < oo.childNodes.length; k++) if (this.exceptions.indexOf((oo.childNodes[k].id || '#') + '#') == -1) this.changeSize(oo.childNodes[k]);
},
checkBrowser : function() {
	if (document.all && document.getElementById) return true;
	if (navigator.userAgent.indexOf('Netscape6/') >= 0 || navigator.userAgent.indexOf('Gecko') >= 0) return true;
	return false;
},
inc : function(oo) {
	this.larger();
	if (oo) oo.blur();
	return false;	
},
dec : function(oo) {
	this.smaller();
	if (oo) oo.blur();
	return false;	
}
}
font_size = new FontSize();

// Schriftgroessen anpassen: ENDE

// PNG-Problemloesung im IE

function fixPNG(myImage) 
{
	try {
		if (window.ie6){
			myImage = $(myImage);
			var vis = myImage.getStyle('display') != 'none';
			if(!vis) myImage.setStyle('display','block');
			var width = $(myImage).offsetWidth;
			var height = $(myImage).offsetHeight;
			if(!vis) myImage.hide();
			var replacement = new Element('span', {
				id:(myImage.id)?myImage.id:'',
				'class':(myImage.className)?myImage.className:'',
				title:(myImage.title)?myImage.title:(myImage.alt)?myImage.alt:'',
				styles: {
					display: 'inline-block',
					width: width,
					height: height,
					filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='" 
						+ myImage.src + "', sizingMethod='scale');"
				},
				src: myImage.src
			});
			if(myImage.style.cssText) {
				try {
					var styles = {};
					var s = myImage.style.cssText.split(';');
					s.each(function(style){
						var n = style.split(':');
						styles[n[0]] = n[1];
					});
					replacement.setStyle(styles);
				} catch(e){ dbug.log('fixPNG1: ', e)}
			}
			if(replacement.cloneEvents) replacement.cloneEvents(myImage);
			myImage.replaceWith(replacement);
		}
	} catch(e) {dbug.log('fixPNG2: ', e)}
};
if(window.ie6) window.addEvent('domready', function(){$$('img.hilfe,img.fixPNG').each(function(png){fixPNG(png)});});

// ENDE: PNG-Problemloesung