function open_teaser(elementid)
{
	element = document.getElementById(elementid);
	if(element)
	{
		if (dhtmlTeasers.functions.hasClass('closed', element.className))
		{
			var index = dhtmlTeasers.getIndexByTeaser(element);
			dhtmlTeasers.toggleTeaser(element);
			dhtmlTeasers.animateTeaser(index, dhtmlTeasers.teaserHeights[index], true, null);
		}
	}
}

function Ausrichten (wie) {
  document.getElementById("unentschlossen").align = wie;
}


function dhtml_teasers()
{
	var app = this;
	app.functions = new main_functions();
	app.classname = null;
	app.teaserHeights = Array();
	app.teaserMinHeight = 29;
	app.motionInterval = 40;
	app.motionDiff = 20;

	app.setEventHandlers = function(classname)
	{
		var teasers;
		var i, k = 0;

		if(typeof classname != 'undefined')
		{
			if(document.getElementsByTagName)
			{
				app.classname = classname;
				teasers = document.getElementsByTagName('DIV');
				if(teasers)
				{
					for(i = 0; i < teasers.length; i++)
					{
						if(app.functions.hasClass(app.classname, teasers[i].className))
						{
							var h3s = app.functions.filterChildNodesRecursive(teasers[i], 'H3');
							if (h3s.length > 0)
							{
								app.teaserHeights[k] = teasers[i].offsetHeight;
								app.teaserHeights[k] = app.getHeight(teasers[i]);

								app.functions.addEvent(h3s[0], 'click', function()
															{
																var teaserElem = this.parentNode;

																// ?ffnen
																if (app.functions.hasClass('closed', this.className))
																{
																	var index = app.getIndexByTeaser(teaserElem);
																	app.toggleTeaser(teaserElem);
																	app.animateTeaser(index, app.teaserHeights[index], true, null);
																}

																// Schlie?en
																else
																{
																	window.setTimeout(function()
																									{
																										var index = app.getIndexByTeaser(teaserElem);
																										app.animateTeaser(index, app.teaserMinHeight, false, function() { app.toggleTeaser(teaserElem); } );
																									}, app.motionInterval);
																}
															} );

								app.toggleTeaser(teasers[i]);
							}
							k++;
						}
					}
				}
			}
		}
	}

	app.getTeaserByIndex = function(index)
	{
		var i, k = 0;
		var teasers;

		if (document.getElementsByTagName)
		{
			teasers = document.getElementsByTagName('DIV');
			if(teasers)
			{
				for(i = 0; i < teasers.length; i++)
				{
					if(app.functions.hasClass(app.classname, teasers[i].className))
					{
						if (k == index) return(teasers[i]);
						k++;
					}
				}
			}
		}
	}

	app.getIndexByTeaser = function(teaser)
	{
		var i, k = 0;
		var teasers;

		if (document.getElementsByTagName)
		{
			teasers = document.getElementsByTagName('DIV');
			if(teasers)
			{
				for(i = 0; i < teasers.length; i++)
				{
					if(app.functions.hasClass(app.classname, teasers[i].className))
					{
						if (teasers[i] == teaser) return(k);
						k++;
					}
				}
			}
		}
	}

	app.animateTeaser = function(index, limit, direction, callback)
	{
		var teaser = app.getTeaserByIndex(index);
		
		if (teaser)
		{
			if ((direction == true && parseInt(teaser.style['height']) < limit)
						|| (direction == false && parseInt(teaser.style['height']) > limit))
			{
				var newHeight = parseInt(teaser.style['height']);
				newHeight = (direction) ? newHeight + app.motionDiff : newHeight - app.motionDiff;
				if (direction == true && newHeight > limit) newHeight = limit;
				if (direction == false && newHeight < limit) newHeight = limit;

				teaser.style['height'] = String(newHeight) + 'px';
				app.aniTimer = window.setTimeout(function()
															{
																app.animateTeaser(index, limit, direction, callback);
															}, app.motionInterval);
			}
			else
			{
				if (callback != null) callback();
			}
		}
	}

	app.toggleTeaser = function(teaser)
	{
		if(app.functions.hasClass('closed', teaser.className))
		{
			for(i = 0; i < teaser.childNodes.length; i++)
			{
				if(teaser.childNodes[i].nodeType == 1)
				{
					teaser.childNodes[i].className = app.functions.removeClass(teaser.childNodes[i].className, 'closed');
				}
			}
			teaser.className = app.functions.removeClass(teaser.className, 'closed');
		}
		else
		{
			for(i = 0; i < teaser.childNodes.length; i++)
			{
				if(teaser.childNodes[i].nodeType == 1)
				{
					teaser.childNodes[i].className = app.functions.addClass(teaser.childNodes[i].className, 'closed');
				}
			}
			teaser.className = app.functions.addClass(teaser.className, 'closed');
			teaser.style['height'] = String(app.teaserMinHeight) + 'px';
		}
	}

	app.getHeight = function(teaser)
	{
		var detectedHeight = teaser.offsetHeight;
		//detectedHeight -= 8;
		return(detectedHeight);
	}
}

var Pos = window.location.href.indexOf('/contenido/');
if (Pos == -1)
{
	var dhtmlTeasers = new dhtml_teasers();
	dhtmlTeasers.functions.addEvent(window, 'load', function() { dhtmlTeasers.setEventHandlers('teaser'); } );
}


function toggleextra(control)
{
	var elem = document.getElementById(control);
	if(elem.style.display == "block")
	{
		elem.style.display = "none";
	}
	else
	{
		elem.style.display = "block";
	}
}

