/*
	IOSPIRIT Gallery Script
	(C) 2009 by IOSPIRIT GmbH, Felix Schwarz
	All rights reserved.
	
	DO NOT COPY THIS SCRIPT OR USE IT ON YOUR WEBSITE.	
	THIS SCRIPT MAY NOT BE USED AT ANY WEBSITE OTHER THAN THE IOSPIRIT WEBSITE.
*/

/*
	Documentation:

	<!-- ######## the gallery object's size determines width and height of the total gallery.
		      Adding orientation="horizontalleft" presents thumbs on the left.
		      If startWithCaption is set (value currently ignored), the caption is displayed right from the start, otherwise only on mouseover.
		      If captionHideIntervalSeconds is set, captions are automatically hidden after captionHideIntervalSeconds seconds. Default value: 3 seconds.
 	-->
	<div class="gallery" style="width:600px; height: 460px; margin-top: 20px;" startWithCaption="true" captionHideIntervalSeconds="3.0">
		<div class="showroom">
			<div class="contentDiv"></div>
			<div class="contentDiv"></div>
		</div>
		<div class="controls">
			<div class="label">Images:</div>
			<!-- ######## Images are displayed as background-images. Right now gif, png, jpg and jpeg recognized as images -->
			<!-- ######## Anything you specify as title argument to the link will be shown as caption text inside the viewer -->
			<a href="downloadBoxBackground.png" class="button" title="This is displayed as caption text"></a>
			<!-- ######## thumbnailhref can point to a thumbnail that differs from href - the gallery script will automatically display it inside the button -->
			<a href="remoteBuddyLogo.png" thumbnailhref="remoteBuddyLogoMini.png" class="button"></a>
			<div class="label">QuickTime:</div>
			<!-- ######## Quicktime movies can be displayed as well. Right now mov, mp4 recognized as quicktime movies -->
			<a href="demo.mp4" thumbnailhref="demoVideoStillMini.png" class="button"></a>	
			<!-- ######## YouTube movies can be displayed as well. The controls are permanently visible. -->
			<div class="label">YouTube:</div>
			<a href="http://www.youtube.com/watch?v=abcdefghi" thumbnailhref="youtubevideomini.png" class="button"></a>
			<!-- ######## Vimeo movies can be displayed as well. The controls are only temporarily visible. -->
			<div class="label">Vimeo:</div>
			<a href="http://vimeo.com/1234567" thumbnailhref="vimeovideomini.png" class="button"></a>
		</div>
	</div>

*/


function setupGallery()
{
	var divs, i;
	
	divs = document.getElementsByTagName("div");
	
	for (i=0;i<divs.length;i++)
	{
		if (divs[i].className == "gallery")
		{
			var newGallery;
			
			newGallery = new Gallery(divs[i]);
		}
	}
}

function Gallery(galleryDivObj)
{
	var i, thisGallery = this;
	var anchorName; 

	// Store main gallery div obj
	this._galleryDivObj = galleryDivObj;

	// Initialize other vars
	this._transitionStartTime = 0;
	this._transitionTimer = 0;

	this._startWithoutCaption = true;
	this._alwaysDisplayCaptionOnImageChange = false;
	this._captionIsVisible = false;
	this._captionHideTimeIntervalInMilliseconds = 3000;
	
	this._initialAutoPlay = true;
	
	// Get caption options
	if (galleryDivObj.getAttribute('startWithCaption'))
	{
		this._startWithoutCaption = false;
		this._alwaysDisplayCaptionOnImageChange = true;
	}

	if (galleryDivObj.getAttribute('captionHideIntervalSeconds'))
	{
		this._captionHideTimeIntervalInMilliseconds = parseFloat(galleryDivObj.getAttribute('captionHideIntervalSeconds')) * 1000;
	}
	
	if (galleryDivObj.getAttribute("noInitialAutoPlay"))
	{
		this._initialAutoPlay = false;
	}
	
	// Find child divs
	for (i=0; i<this._galleryDivObj.childNodes.length; i++)
	{
		var childObj="", className="";
		
		try
		{
			childObj = this._galleryDivObj.childNodes[i];
			className = childObj.className;

			if (className)
			{
				if (className == "showroom")
				{
					this._showroomObj = childObj;
					this._containerWidth  = this._showroomObj.offsetWidth-2;
					this._containerHeight = this._showroomObj.offsetHeight-2;
				}

				if (className == "controls")
				{
					this._controlsObj = childObj;
				}
			}
		}
		catch(e)
		{
		}
	}
	
	if (this._showroomObj)
	{
		var divCnt=0;
	
		for (i=0; i<this._showroomObj.childNodes.length; i++)
		{
			var childObj="", className="";
			
			try
			{
				childObj = this._showroomObj.childNodes[i];
	
				if (childObj.className == "contentDiv")
				{
					if (divCnt == 0)
					{
						this._contentObj1 = childObj;
					}
					else
					{
						this._contentObj2 = childObj;
					}
				
					divCnt++;
				}
			}
			catch(e)
			{
			}
		}
	}

	// Install onclick handlers
	this._onclickHandler = function(event) { return (thisGallery.handleOnClick(this, event)); }

	this._activeContentObj = 0;
	this._activeButtonObj = 0;

	this._anchorNameObjectMap = new Object;

	if (this._controlsObj)
	{
		var divCnt=0, firstButton=0, fallbackButton=0;
		var hashName = 0;
		
		if (document.location.hash)
		{
			hashName = unescape(document.location.hash.substring(1));
		}
	
		for (i=0; i<this._controlsObj.childNodes.length; i++)
		{
			var childNode = this._controlsObj.childNodes[i];
			
			if (childNode.className == "button")
			{
				var thumbnailHref, nodeName;
			
				if (!fallbackButton)
				{
					fallbackButton = childNode;
				}

				if (anchorName = childNode.getAttribute("anchorname"))
				{
					this._anchorNameObjectMap[anchorName.toLowerCase()] = childNode;
				}
				
				if (!firstButton)
				{
					if (hashName)
					{
						if (anchorName)
						{
							if (anchorName == hashName)
							{
								firstButton = childNode; 
							}
						}
					}
					else
					{
						firstButton = childNode; 
					}
				}
				
				if (childNode.innerHTML.length == 0)
				{
					if (thumbnailHref = childNode.getAttribute("thumbnailhref"))
					{
						childNode.style.backgroundImage = "url('" + thumbnailHref + "')";
					}
					else
					{
						if (!childNode.style.backgroundImage)
						{
							childNode.style.backgroundImage = "url('" + childNode.href + "')";
						}
					}
				}
				
				childNode.onclick = this._onclickHandler;
			}
		}
		
		if (!firstButton)
		{
			firstButton = fallbackButton;
		}
		
		if (firstButton)
		{
			this.handleClickOnButton(firstButton, false);
		}
	}
	
	// Install "anchor click" handlers
	if (window.addEventListener)
	{
		document.addEventListener("click", function(event) { return (thisGallery.handleOnClick(thisGallery.findParentNodeWithTagName(event.target, "a"), event)); }, false);
	}
	else
	{
		document.attachEvent("onclick", function() { return (thisGallery.handleOnClick(thisGallery.findParentNodeWithTagName(event.srcElement, "a"), event)); });
	}
}

Gallery.prototype._galleryDivObj;
Gallery.prototype._showroomObj;
Gallery.prototype._contentObj1;
Gallery.prototype._contentObj2;
Gallery.prototype._controlsObj;
Gallery.prototype._onclickHandler;
Gallery.prototype._activeContentObj;
Gallery.prototype._activeButtonObj;
Gallery.prototype._initialAutoPlay;

Gallery.prototype._anchorNameObjectMap;

Gallery.prototype._containerWidth;
Gallery.prototype._containerHeight;

Gallery.prototype._transitionTimer;
Gallery.prototype._transitionStartTime;

Gallery.prototype._startWithoutCaption;
Gallery.prototype._alwaysDisplayCaptionOnImageChange;
Gallery.prototype._captionIsVisible;

Gallery.prototype._captionHideTimeIntervalInMilliseconds;

Gallery.prototype.findParentNodeWithTagName = function(inspectObj, tagName)
{
	while (inspectObj && (inspectObj.tagName != tagName.toUpperCase()))
	{
		inspectObj = inspectObj.parentNode;
	}
	
	return (inspectObj);
}

Gallery.prototype.handleOnClick = function(thisObj, event)
{
	if (thisObj)
	{
		if (thisObj.className == "button")
		{
			this.handleClickOnButton(thisObj, true);
			return (false);
		}
		else
		{
			if (thisObj = this.getButtonForAnchor(thisObj))
			{
				return (this.handleOnClick(thisObj, true));
			}
		}
	}
		
	return (true);
}

Gallery.prototype.handleClickOnButton = function(buttonObj, transition)
{
	var thisGallery = this;
	var targetSuffix = "", targetSuffixOffset = -1;
	var targetDivName = "", targetDivNameOffset = -1, targetDivObj = 0;
	var newHTMLCode = "", newCSSBackgroundCode="", newCaption = "";
	var loadFunction = 0;
	var autoPlay = true;
	
	// Change active state
	if (this._activeButtonObj)
	{
		if (this._activeButtonObj != buttonObj)
		{
			this._activeButtonObj.removeAttribute("selected");
		}
		else
		{
			return;
		}
	}

	this._activeButtonObj = buttonObj;
	buttonObj.setAttribute("selected", "yes");
	
	if (transition)
	{
		try
		{
			if (buttonObj.getAttribute("anchorname"))
			{
				document.location.hash = "#" + buttonObj.getAttribute("anchorname");
			}
		}
		catch(e)
		{
		}
	}
	else
	{
		autoPlay = this._initialAutoPlay;
	}
	
	if (autoPlay)
	{
		try
		{
			if (buttonObj.getAttribute("noautoplay"))
			{
				autoPlay = false;
			}
		}
		catch(e)
		{
		}
	}
	
	// Find out the file type and link type
	targetSuffixOffset = buttonObj.href.lastIndexOf(".");
	
	if (targetSuffixOffset != -1)
	{
		targetSuffix = buttonObj.href.substring(targetSuffixOffset+1, buttonObj.href.length);

		switch (targetSuffix.toLowerCase())
		{
			case "png":
			case "jpg":
			case "jpeg":
			case "gif":
				// newHTMLCode = '<img src="' + buttonObj.href + '">';
				
				if (buttonObj.title)
				{
					newCaption = buttonObj.title;
				}
				
				newCSSBackgroundCode = "url('"+ buttonObj.href +"')";
				
				loadFunction = 	function()
					       	{
					       		var newImage;
					       		
					       		newImage = new Image();
					       		newImage.onload = function()
					       				  {
										thisGallery.showNewContent(newCSSBackgroundCode, newHTMLCode, newCaption, transition);
					       				  }
					       		newImage.src = buttonObj.href;
					       	}
			break;
			
			case "mp4":
			case "mov":
				newHTMLCode = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="' + this._containerWidth + '" height="' + this._containerHeight + '"><param name="movie" value="' + buttonObj.href + '"><param name="src" value="' + buttonObj.href + '">' + (autoPlay ? '<param name="autoplay" value="true">' : '') + '<param name="controller" value="true"><param name="scale" value="tofit"> <embed width="' + this._containerWidth + '" height="' + this._containerHeight + '" src="' + buttonObj.href + '" pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" controller="true" ' + (autoPlay ? 'autoplay="true" ' : '') + 'scale="tofit"></object>';
			break;
			
			default:
				targetDivNameOffset = buttonObj.href.lastIndexOf("#");
				
				if (targetDivNameOffset != -1)
				{
					targetDivName = buttonObj.href.substring(targetDivNameOffset+1, buttonObj.href.length);
					
					if (targetDivObj  = document.getElementById(targetDivName))
					{
						newCSSBackgroundCode = targetDivObj.style.backgroundImage;
						newHTMLCode = targetDivObj.innerHTML;
					}
				}
			break;
		}
	}
	
	if (!newHTMLCode.length && !newCSSBackgroundCode.length)
	{
		// Youtube
		if (buttonObj.href.indexOf("youtube.com") != -1)
		{
			var youTubeId, ytIDstartOffset, ytIDendOffset;
			
			ytIDstartOffset = buttonObj.href.indexOf("v=");
			
			if (ytIDstartOffset != -1)
			{
				ytIDstartOffset += 2;

				ytIDendOffset = buttonObj.href.indexOf("&", ytIDstartOffset);
				
				if (ytIDendOffset == -1)
				{
					ytIDendOffset = buttonObj.href.length;
				}
				
				youTubeId = buttonObj.href.substring(ytIDstartOffset, ytIDendOffset);
				
				newHTMLCode = '<object width="' + this._containerWidth + '" height="' + this._containerHeight + '"><param name="movie" value="http://www.youtube.com/v/' + youTubeId + '&fs=1&ap=%2526fmt%3D18' + (autoPlay ? '&autoplay=1' : '') + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + youTubeId + '&fs=1&ap=%2526fmt%3D18' + (autoPlay ? '&autoplay=1' : '') + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + this._containerWidth + '" height="' + this._containerHeight + '"></embed></object>';
			}
		}
	}
	
	if (!newHTMLCode.length && !newCSSBackgroundCode.length)
	{
		// Vimeo
		if (buttonObj.href.indexOf("vimeo.com") != -1)
		{
			var vimeoId, vmIDStartOffset;
			
			vmIDStartOffset = buttonObj.href.indexOf(".com/");
			
			if (vmIDStartOffset != -1)
			{
				vmIDStartOffset += 5;
				
				vimeoId = buttonObj.href.substring(vmIDStartOffset, buttonObj.href.length);
				
				newHTMLCode = '<object width="' + this._containerWidth + '" height="' + this._containerHeight + '"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' + vimeoId + '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1' + (autoPlay ? '&amp;autoplay=1' : '') + '" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=' + vimeoId + '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1' + (autoPlay ? '&amp;autoplay=1' : '') + '" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="' + this._containerWidth + '" height="' + this._containerHeight + '"></embed></object>';	
				
			}
		}
	}
	
	if (!loadFunction)
	{
		this.showNewContent(newCSSBackgroundCode, newHTMLCode, newCaption, transition);
	}
	else
	{
		loadFunction();
	}
}

Gallery.prototype.showNewContent = function(newCSSBackgroundCode, newHTMLCode, newCaption, transition)
{
	var newContentObj, hideContentObj, newCaptionObj=0, hideCaptionObj=0;
	var thisGallery = this;
	var i;
	
	if (this._transitionTimer)
	{
		window.clearInterval(this._transitionTimer);
		this._transitionTimer = 0;
	}

	if (this._activeContentObj == this._contentObj1)
	{
		newContentObj  = this._contentObj2;
		hideContentObj = this._contentObj1;
	}
	else
	{
		newContentObj = this._contentObj1;
		hideContentObj = this._contentObj2;
	}

	newContentObj.style.opacity = "0";
	newContentObj.style.backgroundImage = newCSSBackgroundCode;
	newContentObj.innerHTML = newHTMLCode;
	newContentObj.style.display = "block";
	newContentObj.style.zIndex = 10;
	
	if (newCaption)
	{
		var newCaptionObj;
		
		newCaptionObj = document.createElement('div');
		newCaptionObj.setAttribute("class", "caption");
		newCaptionObj.setAttribute("id", "caption");
		newCaptionObj.innerHTML = newCaption;
		
		newContentObj.appendChild(newCaptionObj);
	}

	newContentObj.style.width = this._containerWidth + "px";
	newContentObj.style.height = this._containerHeight + "px";
	newContentObj.onmouseover = null;
	newContentObj.onmouseout = null;

	hideContentObj.style.zIndex = 0;
	hideContentObj.onmouseover = null;
	hideContentObj.onmouseout = null;
	
	/*
	for (i=0; i<newContentObj.childNodes.length; i++)
	{
		if (newContentObj.childNodes[i].id == "caption")
		{
			newCaptionObj = hideContentObj.childNodes[i];
		}
	}
	*/

	for (i=0; i<hideContentObj.childNodes.length; i++)
	{
		if (hideContentObj.childNodes[i].id == "caption")
		{
			hideCaptionObj = hideContentObj.childNodes[i];
		}
	}
	
	if (newCaptionObj)
	{
		if (this._startWithoutCaption)
		{
			newCaptionObj.style.opacity = "0";
			this._startWithoutCaption = false;
		}

		if (!this._captionIsVisible && !this._alwaysDisplayCaptionOnImageChange)
		{
			newCaptionObj.style.opacity = "0";
		}
		else
		{
			this._captionIsVisible = true;
		}
	}
	else
	{
		this._captionIsVisible = false;
	}

	if (transition)
	{
		this._transitionStartTime = new Date();
		this._transitionTimer = window.setInterval(function()
							   {
							   	var nowTime = new Date();
							   	var elapsedTime, opacityValue, animationEnded = false;
							   	
							   	elapsedTime = nowTime - thisGallery._transitionStartTime;
							   	
							   	opacityValue = elapsedTime / 250;
							   	
							   	if (opacityValue < 1.0)
							   	{
									newContentObj.style.opacity = opacityValue;
							   	}
							   	else
							   	{
									newContentObj.style.opacity = "1";
									
									hideContentObj.style.display = "none";
									hideContentObj.style.backgroundImage = "";
									hideContentObj.innerHTML = "";

									window.clearInterval(thisGallery._transitionTimer);
									thisGallery._transitionTimer = 0;
									
									if (newCaptionObj)
									{
										thisGallery.startCaptionTimer(newCaptionObj, true, thisGallery._captionHideTimeIntervalInMilliseconds);
									}
							   	}
							   }, 5);
	}
	else
	{
		newContentObj.style.opacity = "1";
		
		hideContentObj.style.display = "none";
		hideContentObj.style.backgroundImage = "";
		hideContentObj.innerHTML = "";
		
		if (newCaptionObj)
		{
			this.startCaptionTimer(newCaptionObj, true, thisGallery._captionHideTimeIntervalInMilliseconds);
		}
	}
	
	this._activeContentObj = newContentObj;
}

Gallery.prototype.startCaptionTimer = function(newCaptionObj, fadeOut, fadeOutBeginTime)
{
	var thisGallery = this, comingFromMouseOver = true;
	
	if (!fadeOut)
	{
		if (newCaptionObj.parentNode.onmouseover)
		{
			comingFromMouseOver = true;
		}
	
		newCaptionObj.parentNode.onmouseover = null;
		newCaptionObj.parentNode.onmouseout = null;
	}
	else
	{
		newCaptionObj.parentNode.onmouseover = null;
		newCaptionObj.parentNode.onmouseout = null;
	}

	if (thisGallery._transitionTimer)
	{
		window.clearInterval(thisGallery._transitionTimer);
		thisGallery._transitionTimer = 0;
	}

	if (newCaptionObj)
	{
		this._transitionStartTime = new Date();

		this._transitionTimer = window.setInterval(function()
							   {
								var nowTime = new Date();
								var elapsedTime, opacityValue, animationEnded = false;
									
								elapsedTime = nowTime - thisGallery._transitionStartTime;
								
								if (fadeOut)
								{
									if (parseFloat(newCaptionObj.style.opacity) != 0)
									{
										if (elapsedTime > fadeOutBeginTime)
										{
											opacityValue = 1.0 - ((elapsedTime - fadeOutBeginTime) / 500);
												
											if (opacityValue > 0)
											{
												newCaptionObj.style.opacity = opacityValue;
											}
											else
											{
												animationEnded = true;
											}
										}
									}
									else
									{
										animationEnded = true;
									}
									
									if (animationEnded)
									{
										newCaptionObj.style.opacity = "0";
										
										window.clearInterval(thisGallery._transitionTimer);
										thisGallery._transitionTimer = 0;
										
										newCaptionObj.parentNode.onmouseover = 	function()
															{
																thisGallery.startCaptionTimer(newCaptionObj, false, 0);
															};

										thisGallery._captionIsVisible = false;
									}
								}
								else
								{
									opacityValue = elapsedTime / 200;

									if (parseFloat(newCaptionObj.style.opacity) != 1)
									{
										if (opacityValue < 1.0)
										{
											newCaptionObj.style.opacity = opacityValue;
										}
										else
										{
											animationEnded = true;
										}
									}
									else
									{
										animationEnded = true;
									}
									
									if (animationEnded)
									{
										newCaptionObj.style.opacity = "1";

										window.clearInterval(thisGallery._transitionTimer);
										thisGallery._transitionTimer = 0;
										
										if (!comingFromMouseOver)
										{
											thisGallery.startCaptionTimer(newCaptionObj, true, thisGallery._captionHideTimeIntervalInMilliseconds);
										}
										else
										{
											newCaptionObj.parentNode.onmouseout  = function() { thisGallery.startCaptionTimer(newCaptionObj, true, (thisGallery._captionHideTimeIntervalInMilliseconds / 2.0));  }
										}

										thisGallery._captionIsVisible = true;
									}
								}
							     }, 5);
	}
}

Gallery.prototype.getButtonForAnchor = function (anchorObject)
{
	if (anchorObject.tagName == "A")
	{
		if (anchorObject.href)
		{
			var targetAnchorNameOffset, targetAnchorName;
		
			targetAnchorNameOffset = anchorObject.href.lastIndexOf("#");
			
			if (targetAnchorNameOffset != -1)
			{
				targetAnchorName = anchorObject.href.substring(targetAnchorNameOffset+1, anchorObject.href.length);

				try
				{
					if (this._anchorNameObjectMap[targetAnchorName])
					{
						return (this._anchorNameObjectMap[targetAnchorName]);
					}
				}
				catch(e)
				{
				}
			}
		}
	}
	
	return (0);
}

/*

Gallery.prototype.isMouseOverObject = function(object)
{
	if (object.getAttribute("mouseIsOverObject"))
	{
		return (object.getAttribute("mouseIsOverObject"));
	}

	return (false);
}

Gallery.prototype.handleMouseOverOut = function(object, isMouseOver)
{
	var callbackFunction;

	object.setAttribute("mouseIsOverObject", isMouseOver);

	if (isMouseOver)
	{
		if (callbackFunction = object.getAttribute("executeOnMouseOver"))
		{
			callbackFunction(object);
		}
	}
	else
	{
		if (callbackFunction = object.getAttribute("executeOnMouseOut"))
		{
			callbackFunction(object);
		}
	}
}
*/

/*
	IOSPIRIT Tools
	(C) 2009 by IOSPIRIT GmbH, Felix Schwarz
	All rights reserved.
	
	DO NOT COPY THIS SCRIPT OR USE IT ON YOUR WEBSITE.	
	THIS SCRIPT MAY NOT BE USED AT ANY WEBSITE OTHER THAN THE IOSPIRIT WEBSITE.
*/

function FilterBoxChange(obj, newValue, matchWithAttributeOfName)
{
	var i, liNodes, filterNodes, filterValue, adaptNodeAttributeName, nodeVisibilityAttributeName;

	adaptNodeAttributeName 	    = 'adaptnode';
	nodeVisibilityAttributeName = 'ismatching';

	if (typeof(matchWithAttributeOfName) == 'undefined')
	{
		matchWithAttributeOfName = "matchfilterkeywords";
	}

	liNodes = obj.parentNode.parentNode.childNodes;
	
	if (liNodes.length)
	{
		for (i=0; i<liNodes.length; i++)
		{
			if (liNodes[i].childNodes.length != 0)
			{
				liNodes[i].childNodes[0].className = "";
			}
		}
	}
	
	obj.className = "selected";
	obj.parentNode.parentNode.setAttribute("filterValue", newValue);
	
	// Compile keyword list
	filterKeywords = new Array();

	if (filterNodes = obj.parentNode.parentNode.parentNode.childNodes)
	{
		for (i=0; i<filterNodes.length; i++)
		{
			if (filterNodes[i].tagName == "OL")
			{
				if (filterValue = filterNodes[i].getAttribute("filterValue"))
				{
					if (filterValue != "all")
					{
						filterKeywords.push(filterValue);
					}
				}
			}
		}
	}
	
	// Perform filtering
	filterDivs = document.getElementsByTagName('div');
	
	for (i=0;i<filterDivs.length;i++)
	{
		if (filterDivs[i].getAttribute(matchWithAttributeOfName))
		{
			var matches=0, matchFilterKeywordsString, controlNodeWithId, controlNodeObj;
			
			if (matchFilterKeywordsString = filterDivs[i].getAttribute(matchWithAttributeOfName))
			{
				var filterIterator, matchIterator, matchFilterKeywords;
			
				matchFilterKeywords = matchFilterKeywordsString.split(",");
			
				for (filterIterator=0; filterIterator<filterKeywords.length; filterIterator++)
				{
					for (matchIterator=0; matchIterator<matchFilterKeywords.length; matchIterator++)
					{
						if (matchFilterKeywords[matchIterator] == filterKeywords[filterIterator])
						{
							matches++;
							break;
						}
					}
				}
			}
			
			controlNodeObj = 0;

			if (controlNodeWithId = filterDivs[i].getAttribute(adaptNodeAttributeName))
			{
				controlNodeObj = document.getElementById(controlNodeWithId);
			}
			
			if (matches == filterKeywords.length)
			{
				filterDivs[i].style.display = "block";
				if (controlNodeObj)
				{
					controlNodeObj.setAttribute(nodeVisibilityAttributeName, "yes");
				}
			}
			else
			{
				filterDivs[i].style.display = "none";
				if (controlNodeObj)
				{
					controlNodeObj.setAttribute(nodeVisibilityAttributeName, "no");
				}
			}
		}
	}
	
	return (false);
}

/*
	IOSPIRIT EffectGallery
	(C) 2009 by IOSPIRIT GmbH, Felix Schwarz
	All rights reserved.
	
	DO NOT COPY THIS SCRIPT OR USE IT ON YOUR WEBSITE.	
	THIS SCRIPT MAY NOT BE USED AT ANY WEBSITE OTHER THAN THE IOSPIRIT WEBSITE.
*/

function EffectGallery(containerDiv)
{
	containerDiv.style.position = "relative";
	containerDiv.style.overflow = "hidden"; 

	this._elements = new Array();
	this._tagIndexMap = new Array();
	this._containerDiv = containerDiv;
	this._currentIndex = -1;
	this._lastCurrentIndex = -1;

	this._curveFunction = function (progress) { return ((1-Math.sin((Math.PI/2)+(progress*Math.PI)))/2); }
	this._transitionDuration = 500; // in ms, one second == 1000 milliseconds
	
	this._transitionEffect = "none";
	this._transitionCompletionCallback = 0;
	this._transitionTimer = 0;
}

EffectGallery.prototype._containerDiv;
EffectGallery.prototype._currentIndex;
EffectGallery.prototype._lastCurrentIndex;
EffectGallery.prototype._tagIndexMap;
EffectGallery.prototype._elements;

EffectGallery.prototype._transitionEffect;
EffectGallery.prototype._transitionDuration;

EffectGallery.prototype._transitionStartDate;
EffectGallery.prototype._transitionTimer;
EffectGallery.prototype._transitionCompletionCallback;

EffectGallery.prototype.addElement = function(elementDiv, nameTag)
{
	var newIndex = this._elements.length;
	
	this._elements[newIndex] = elementDiv;
	
	elementDiv.style.display = "none";
	elementDiv.style.position = "absolute"; 
	this._containerDiv.appendChild (elementDiv);
	
	this._tagIndexMap[newIndex] = nameTag;

	return (newIndex);
}

EffectGallery.prototype.removeElementAtIndex = function(removeItemAtIndex)
{
	if ((this._elements.length > removeItemAtIndex) && (removeItemAtIndex >= 0))
	{
		this._containerDiv.removeChild (this._elements[removeItemAtIndex]);
	
		this._elements.splice(removeItemAtIndex, 1);
		this._tagIndexMap.splice(removeItemAtIndex, 1);
		
		if (this._currentIndex > removeItemAtIndex)
		{
			this._currentIndex--;
		}

		if (this._lastCurrentIndex > removeItemAtIndex)
		{
			this._lastCurrentIndex--;
		}
	}
}

EffectGallery.prototype.indexOfElementWithNameTag = function(nameTag)
{
	var i;
	
	for (i=0; i<this._tagIndexMap.length; i++)
	{
		if (this._tagIndexMap[i] == nameTag)
		{
			return (i);
		}
	}
	
	return (-1);
}

EffectGallery.prototype.currentIndex = function()
{
	return (this._currentIndex);
}

EffectGallery.prototype.showIndex = function(index, effect, completionCallback)
{
	var thisEffectGallery = this;

	if (index < 0) 			    { index = 0; }
	if (index >= this._elements.length) { index = this._elements.length-1; }

	if (index != this._currentIndex)
	{
		if (!this._transitionTimer)
		{
			this._transitionStartDate = new Date();
			this._transitionEffect = effect;
			this._transitionCompletionCallback = completionCallback;
	
			this._lastCurrentIndex = this._currentIndex;
			this._currentIndex = index;
			
			this._transitionTimer = window.setInterval(function() { thisEffectGallery._calculateTransition(); }, 1);
		}
	}
}

EffectGallery.prototype._calculateTransition = function()
{
	var curTime = new Date(), progress;

	progress = (curTime.getTime() - this._transitionStartDate.getTime()) / this._transitionDuration;
	
	if (progress < 1)
	{
		progress = this._curveFunction(progress);
	
		this.renderElements(this._lastCurrentIndex - ((this._lastCurrentIndex - this._currentIndex) * progress), progress);
	}
	else
	{
		this.renderElements(this._currentIndex, 1);
		
		window.clearInterval(this._transitionTimer);
		this._transitionTimer = 0;
		
		if (this._transitionCompletionCallback)
		{
			this._transitionCompletionCallback(this, this._currentIndex, this._lastCurrentIndex);
		}
	}
}

EffectGallery.prototype.renderElements = function(elementOffset, optionalProgress)
{
	var i, containerWidth, containerHeight, elementDiv;
	
	containerWidth = parseInt(this._containerDiv.offsetWidth);
	containerHeight = parseInt(this._containerDiv.offsetHeight);

	for (i=0; i<this._elements.length; i++)
	{
		var xOffset, yOffset, elementWidth, elementHeight, display=true;
	
		elementDiv = this._elements[i];

		switch (this._transitionEffect)
		{
			case "fade":
				if ((this._currentIndex != i) && (this._lastCurrentIndex != i))
				{
					display = false;
				}
			break;
			
			case "none":
				elementDiv.style.opacity = "1";
				
				if (i != this._currentIndex)
				{
					display = false;
				}
			break;
		}
		
		if (!display)
		{
			elementDiv.style.display = "none";
		}
		else
		{
			elementDiv.style.display = "block";
	
			elementWidth  = parseInt(elementDiv.offsetWidth);
			elementHeight = parseInt(elementDiv.offsetHeight);
			
			switch (this._transitionEffect)
			{
				case "vertical":
					xOffset = 0;
					yOffset = (i * containerHeight) - (elementOffset * containerHeight);
				break;
	
				case "horizontal":
					xOffset = (i * containerWidth) - (elementOffset * containerWidth);
					yOffset = 0;
				break;
				
				default:
					xOffset = yOffset = 0;
				break;
			}
			
			xOffset += ((containerWidth - elementWidth) / 2);
			yOffset += ((containerHeight - elementHeight) / 2);
			
			elementDiv.style.left = xOffset + "px";
			elementDiv.style.top  = yOffset + "px";
	
			switch (this._transitionEffect)
			{
				case "vertical":
					elementDiv.style.opacity = "1";

					if (!(((yOffset >= 0) && (yOffset <= containerHeight)) || (((yOffset+elementHeight) >= 0) && ((yOffset+elementHeight) <= containerHeight))))
					{
						elementDiv.style.display = "none";
					}
				break;

				case "horizontal":
					elementDiv.style.opacity = "1";

					if (!(((xOffset >= 0) && (xOffset <= containerWidth)) || (((xOffset+elementWidth) >= 0) && ((xOffset+elementWidth) <= containerWidth))))
					{
						elementDiv.style.display = "none";
					}
				break;
				
				case "fade":
					if (this._lastCurrentIndex == i)
					{
						elementDiv.style.opacity = 1-optionalProgress;
						
						if (optionalProgress == 1)
						{
							elementDiv.style.display = "none";
						}
					}

					if (this._currentIndex == i)
					{
						elementDiv.style.opacity = optionalProgress;
					}
				break;
			}
		}
	}
}


/*
	IOSPIRIT TwitterStream
	(C) 2009 by IOSPIRIT GmbH, Felix Schwarz
	All rights reserved.
	
	DO NOT COPY THIS SCRIPT OR USE IT ON YOUR WEBSITE.	
	THIS SCRIPT MAY NOT BE USED AT ANY WEBSITE OTHER THAN THE IOSPIRIT WEBSITE.
*/

// Global context
var TwitterStreamCallbackFunctions;

TwitterStreamCallbackFunctions = new Array();

// TwitterStream class
function TwitterStream(userName, maxTweets)
{
	this._userName = userName;
	this._maxTweets = maxTweets;
	this._rawTweets = 0;
	this._rawSingleTweets = new Object();
}

TwitterStream.prototype._userName;
TwitterStream.prototype._maxTweets;
TwitterStream.prototype._rawTweets;
TwitterStream.prototype._rawSingleTweets;

TwitterStream.prototype.loadJSON = function(url, callbackFunction)
{
	var scriptElem, headElem, newCallbackID;
	
	newCallbackID = TwitterStreamCallbackFunctions.length;
	TwitterStreamCallbackFunctions[newCallbackID] = callbackFunction;
	
	scriptElem = document.createElement("script");
	scriptElem.setAttribute("src",  url + "&callback=TwitterStreamCallbackFunctions[" + newCallbackID +"]");
	scriptElem.setAttribute("type", "text/javascript");

	headElem = document.getElementsByTagName("head")[0];
	headElem.appendChild(scriptElem);
}

TwitterStream.prototype.convertTimeStringToText = function(timeString)
{
	var currentDate, tweetDate, elapsedMinutes, humanReadableTime;
	var monthNames = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

	currentDate = new Date();
	currentDate = currentDate.getTime();

	tweetDate = new Date(timeString);

	elapsedMinutes = Math.floor((currentDate - tweetDate.getTime()) / 60000);

	if (isNaN(elapsedMinutes))
	{
		humanReadableTime = "View tweet";
	}
	else
	{
		if (elapsedMinutes > 1440)
		{
			if (elapsedMinutes > 2880)
			{
				humanReadableTime = Math.floor(elapsedMinutes / 1440) + " days ago";
			}
			else
			{
				humanReadableTime = Math.floor(elapsedMinutes / 1440) + " day ago";
			}

			if (elapsedMinutes > 14400)
			{
				humanReadableTime = monthNames[tweetDate.getMonth()] + " " + tweetDate.getDay() + ", " + (tweetDate.getYear() + 1900); // " (" + ((tweetDate.getHours() > 10)?tweetDate.getHours():"0"+tweetDate.getHours()) + ":" + ((tweetDate.getMinutes() > 10)?tweetDate.getMinutes():"0"+tweetDate.getMinutes()) + ")";
			}
		}
		else
		{
			if (elapsedMinutes > 60)
			{
				if (elapsedMinutes > 120)
				{
					humanReadableTime = Math.floor(elapsedMinutes / 60) + " hours ago";
				}
				else
				{
					humanReadableTime = Math.floor(elapsedMinutes / 60) + " hour ago";
				}
			}
			else
			{
				if (elapsedMinutes > 1)
				{
					humanReadableTime = Math.floor(elapsedMinutes) + " minutes ago";
				}
				else
				{
					if (elapsedMinutes == 1)
					{
						humanReadableTime = Math.floor(elapsedMinutes) + " minute ago";
					}
					else
					{
						humanReadableTime = Math.floor((currentDate - tweetDate.getTime()) / 1000) + " seconds ago";
					}
				}
			}
		}
	}
	
	return (humanReadableTime);
}

TwitterStream.prototype.linkifyText = function(inText, linkifyURLs, linkifyUserNames, linkifyHashTags, linkTarget)
{
	outText = inText;
	
	if (linkifyURLs)
	{
		outText = outText.replace(/((https?:\/\/|www\.)[^\s ]+)/g, "<a href=\"$1\"" + (linkTarget ? " target=\"" + linkTarget + "\"" : "")+ ">$1</a>");
	}
	
	if (linkifyUserNames)
	{
		var userNameRegExp = new RegExp("(^|\\s)@(\\w+)");
		userNameRegExp.global = true;
		userNameRegExp.ignoreCase = true;

		outText = outText.replace(userNameRegExp, "$1<a href=\"http://www.twitter.com/$2\"" + (linkTarget ? " target=\"" + linkTarget + "\"" : "")+ " rel=\"nofollow\">@$2</a>");
	}
	
	if (linkifyHashTags)
	{
		var hashTagsRegExp = new RegExp("(^|\\s)#(\\w+)");
		hashTagsRegExp.global = true;
		hashTagsRegExp.ignoreCase = true;

		outText = outText.replace(hashTagsRegExp, "$1<a href=\"http://search.twitter.com/search?q=%23$2\"" + (linkTarget ? " target=\"" + linkTarget + "\"" : "")+ " rel=\"nofollow\">#$2</a>");
	}
	
	return (outText);
}

TwitterStream.prototype.loadTweets = function(callbackFunction)
{
	var thisStream = this;

	this.loadJSON("http://twitter.com/statuses/user_timeline.json?screen_name=" + this._userName + "&count=" + this._maxTweets,
		      function(tweetResult) { thisStream._tweetsLoaded(tweetResult, callbackFunction); });
}

TwitterStream.prototype.loadFavoredTweets = function(callbackFunction)
{
	var thisStream = this;

	this.loadJSON("http://twitter.com/favorites/" + this._userName + ".json?",
		      function(tweetResult) { thisStream._tweetsLoaded(tweetResult, callbackFunction); });
}

TwitterStream.prototype.loadTweet = function(tweetId, callbackFunction)
{
	var thisStream = this;
	
	if (this._rawTweets)
	{
		callbackFunction(this);
	}
	else
	{
		this.loadJSON("http://twitter.com/statuses/show/" + tweetId + ".json?",
			      function(tweetResult) { thisStream._tweetLoaded(tweetId, tweetResult, callbackFunction); });
	}
}

TwitterStream.prototype._tweetsLoaded = function(tweetResult, callbackFunction)
{
	this._rawTweets = tweetResult;
	
	if (callbackFunction)
	{
		callbackFunction(this);
	}
}

TwitterStream.prototype._tweetLoaded = function(tweetId, tweetResult, callbackFunction)
{
	this._tweets = tweetResult;
	
	this._rawSingleTweets[tweetId] = tweetResult;
	
	if (callbackFunction)
	{
		callbackFunction(this, tweetId);
	}
}

TwitterStream.prototype.getRawTweets = function()
{
	return (this._rawTweets);
}

TwitterStream.prototype.getTweets = function()
{
	var i, resultArr = new Array();

	for (i=0;i<this._rawTweets.length;i++)
	{
		resultArr[i] = this.parseTweet(this._rawTweets[i]);
	}

	return (resultArr);
}

TwitterStream.prototype.getRawTweet = function(tweetId)
{
	return (this._rawSingleTweets[tweetId]);
}

TwitterStream.prototype.parseTweet = function(tweetData)
{
	var parsedTweet = new Object();
	
	parsedTweet['date']		= this.convertTimeStringToText(tweetData['created_at']);
	parsedTweet['userName']		= tweetData['user']['screen_name'];
	parsedTweet['avatarImageURL']	= tweetData['user']['profile_image_url'];
	parsedTweet['message']		= tweetData['text'];
	parsedTweet['messageLinkified']	= this.linkifyText(tweetData['text'], true, true, true, "_blank");
	parsedTweet['tweetLink']	= "http://twitter.com/" + tweetData['user']['screen_name'] + "/status/" + tweetData['id'];
	parsedTweet['userLink']		= "http://twitter.com/" + tweetData['user']['screen_name'];

	return (parsedTweet);
}

/*
	IOSPIRIT TwitterFeedList
	(C) 2009 by IOSPIRIT GmbH, Felix Schwarz
	All rights reserved.
	
	DO NOT COPY THIS SCRIPT OR USE IT ON YOUR WEBSITE.	
	THIS SCRIPT MAY NOT BE USED AT ANY WEBSITE OTHER THAN THE IOSPIRIT WEBSITE.
*/

// Global context
if (window.addEventListener)
{
	window.addEventListener("load", setupTwitterFeedLists, false);
}
else
{
	window.attachEvent("onload", setupTwitterFeedLists);
}

function setupTwitterFeedLists()
{
	var twitterFeedContainers, i;

	twitterFeedContainers = document.getElementsByClassName("twitterfeed");

	for (i=0; i<twitterFeedContainers.length; i++)
	{
		var twitterFeed;
		
		twitterFeed = new TwitterFeedList(twitterFeedContainers[i]);
	}
}

// TwitterFeedList class
function TwitterFeedList(feedContainer)
{
	var scriptElem, headElem;
	var thisFeed = this;

	this._feedContainer = feedContainer;
	this._userName = feedContainer.getAttribute('twitterUserName');
	this._itemCount = 5;
	this._followUsText = "";
	this._showAvatar = 0;
	this._showTinyTwitterIcon = "http://twitter-badges.s3.amazonaws.com/t_small-b.png";
	this._loadFavoredTweets = 0;
	
	if (feedContainer.getAttribute('twitterItemCount'))
	{
		this._itemCount = parseInt(feedContainer.getAttribute('twitterItemCount'));
	}

	if (feedContainer.getAttribute('twitterFollowUsText'))
	{
		this._followUsText = feedContainer.getAttribute('twitterFollowUsText'); 
	}

	if (feedContainer.getAttribute('twitterShowAvatar'))
	{
		this._showAvatar = parseInt(feedContainer.getAttribute('twitterShowAvatar'));
	}

	if (feedContainer.getAttribute('twitterShowTwitterIcon'))
	{
		this._showTinyTwitterIcon = feedContainer.getAttribute('twitterShowTinyTwitterIcon'); 
	}

	if (feedContainer.getAttribute('twitterLoadFavoredTweets'))
	{
		this._loadFavoredTweets = parseInt(feedContainer.getAttribute('twitterLoadFavoredTweets'));
	}
	
	this._twitterStream = new TwitterStream(this._userName, ((this._itemCount<10)?10:this._itemCount));
	
	if (this._loadFavoredTweets)
	{
		this._twitterStream.loadFavoredTweets(function(stream) { thisFeed.displayTweetsFromStream(stream); } );
	}
	else
	{
		this._twitterStream.loadTweets(function(stream) { thisFeed.displayTweetsFromStream(stream); } );
	}
}

TwitterFeedList.prototype._twitterStream;

TwitterFeedList.prototype._feedContainer;
TwitterFeedList.prototype._itemCount;
TwitterFeedList.prototype._userName;
TwitterFeedList.prototype._followUsText;
TwitterFeedList.prototype._showAvatar;
TwitterFeedList.prototype._showTinyTwitterIcon;
TwitterFeedList.prototype._loadFavoredTweets;

TwitterFeedList.prototype.displayTweetsFromStream = function(stream)
{
	var compiledHTML, tweets, i, maxTweetCount, tweetCount;

	compiledHTML = "";
	maxTweetCount = this._itemCount;
	tweetCount = 0;

	tweets = stream.getTweets();
	
	if (maxTweetCount > tweets.length)
	{
		maxTweetCount = tweets.length;
	}
	
	for (i=0; ((i<tweets.length) && (tweetCount < maxTweetCount)); i++)
	{
		if (tweets[i]['message'].substring(0,1) != "@")
		{
			compiledHTML = compiledHTML + "<li><a href=\"" + tweets[i]['userLink'] + "\" target=\"_blank\">" + (this._showAvatar ? ("<img src=\"" + tweets[i]['avatarImageURL'] + "\" class=\"avatar\">") : (this._showTinyTwitterIcon ? ("<img src=\"" + this._showTinyTwitterIcon + "\" class=\"symbol\">") : "")) + tweets[i]['userName'] + "</a>: " + tweets[i]['messageLinkified'] + " <i><a href=\"" + tweets[i]['tweetLink'] + "\" target=\"_blank\">" + tweets[i]['date'] + "</a></i></li>";
			tweetCount++;
		}
	}

	if (this._followUsText)
	{
		compiledHTML = compiledHTML + "<li class=\"twitterfeedfollowus\"><a href=\"http://twitter.com/" + this._userName + "\">" + this._followUsText + "</a></li>";
	}
	
	if (compiledHTML.length)
	{
		compiledHTML = "<ul>" + compiledHTML + "</ul>";
	}
	

	this._feedContainer.innerHTML = compiledHTML;
}

/*
	IOSPIRIT TweetGallery
	(C) 2009 by IOSPIRIT GmbH, Felix Schwarz
	All rights reserved.
	
	DO NOT COPY THIS SCRIPT OR USE IT ON YOUR WEBSITE.	
	THIS SCRIPT MAY NOT BE USED AT ANY WEBSITE OTHER THAN THE IOSPIRIT WEBSITE.
*/

// Global context
if (window.addEventListener)
{
	window.addEventListener("load", setupTweetGalleries, false);
}
else
{
	window.attachEvent("onload", setupTweetGalleries);
}

function setupTweetGalleries()
{
	var tweetGalleryContainers, i;

	tweetGalleryContainers = document.getElementsByClassName("tweetgallery");

	for (i=0; i<tweetGalleryContainers.length; i++)
	{
		var twitterFeed;
		
		twitterFeed = new TweetGallery(tweetGalleryContainers[i]);
	}
}

// TweetGallery class
function TweetGallery(galleryContainer)
{
	var loadingElement, thisTweetGallery = this;
	
	this._galleryContainer = galleryContainer;

	// Setup EffectGallery
	loadingElement = document.createElement("div");
	loadingElement.setAttribute("class", "loading");
	
	this._effectGallery = new EffectGallery(this._galleryContainer);
	this._effectGallery.addElement(loadingElement,"loading");
	this._effectGallery.showIndex(0, "fade", 0);

	this._transitionDelay = 10000;
	if (galleryContainer.getAttribute('tweetGalleryItemShowTime'))
	{
		this._transitionDelay = parseInt(galleryContainer.getAttribute('tweetGalleryItemShowTime'));
	}

	// Setup TwitterStream
	this._twitterItemCount = 100;
	if (galleryContainer.getAttribute('twitterItemCount'))
	{
		this._twitterItemCount = parseInt(galleryContainer.getAttribute('twitterItemCount'));
	}

	this._twitterLoadFavoredTweets = 0;
	if (galleryContainer.getAttribute('twitterLoadFavoredTweets'))
	{
		this._twitterLoadFavoredTweets = parseInt(galleryContainer.getAttribute('twitterLoadFavoredTweets'));
	}

	this._twitterUserName = galleryContainer.getAttribute('twitterUserName');
	this._twitterStream = new TwitterStream(this._twitterUserName, this._twitterItemCount);

	if (this._twitterLoadFavoredTweets)
	{
		this._twitterStream.loadFavoredTweets(function(stream) { thisTweetGallery.tweetsLoaded(); } );
	}
	else
	{
		this._twitterStream.loadTweets(function(stream) { thisTweetGallery.tweetsLoaded(); } );
	}
	
	this._changeTimer = 0;
	this._transitionEffect = "vertical";
	if (galleryContainer.getAttribute('tweetGalleryTransitionEffect'))
	{
		this._transitionEffect = parseInt(galleryContainer.getAttribute('tweetGalleryTransitionEffect'));
	}
}

TweetGallery.prototype._galleryContainer;
TweetGallery.prototype._effectGallery;
TweetGallery.prototype._transitionDelay;
TweetGallery.prototype._twitterUserName;
TweetGallery.prototype._twitterItemCount;
TweetGallery.prototype._twitterStream;
TweetGallery.prototype._twitterLoadFavoredTweets;
TweetGallery.prototype._tweets;
TweetGallery.prototype._tweetOffset;
TweetGallery.prototype._transitionEffect;
TweetGallery.prototype._changeTimer;

TweetGallery.prototype.tweetsLoaded = function()
{
	var i, tweets, thisTweetGallery = this;

	this._tweets = tweets = this._twitterStream.getTweets();
	this._tweetOffset = 0;
	
	for (i=0;i<tweets.length;i++)
	{
		var tweetElement;

		tweetElement = document.createElement("div");
		tweetElement.setAttribute("class", "tweet");
		tweetElement.innerHTML = "<a href=\"" + tweets[i]['userLink'] + "\" target=\"_blank\"><img src=\"" + tweets[i]['avatarImageURL'] + "\" class=\"avatar\"></a><div class=\"message\">" + tweets[i]['messageLinkified'] + "<i>- <a href=\"" + tweets[i]['userLink'] + "\" target=\"_blank\">" + tweets[i]['userName'] + "</a> (<a href=\"" + tweets[i]['tweetLink'] + "\" target=\"_blank\">" + tweets[i]['date'] + "</a>)</i>" + "</div>";

		this._effectGallery.addElement(tweetElement, "tweet" + i);
	}
	
	this._effectGallery.showIndex(1, "fade", 0);
	
	this._changeTimer = window.setInterval(function() { thisTweetGallery.showNextTweet(); }, this._transitionDelay);
}

TweetGallery.prototype.showNextTweet = function()
{
	var effect = this._transitionEffect;

	this._tweetOffset++;
	
	if (this._tweetOffset >= this._tweets.length)
	{
		this._tweetOffset = 0;
		effect = "fade";
	}
	
	this._effectGallery.showIndex(this._tweetOffset + 1, effect, 0);
}

/*
	IOSPIRIT MiniGallery
	(C) 2009 by IOSPIRIT GmbH, Felix Schwarz
	All rights reserved.
	
	DO NOT COPY THIS SCRIPT OR USE IT ON YOUR WEBSITE.	
	THIS SCRIPT MAY NOT BE USED AT ANY WEBSITE OTHER THAN THE IOSPIRIT WEBSITE.
*/

// Global context
if (window.addEventListener)
{
	window.addEventListener("load", setupMiniGalleries, false);
}
else
{
	window.attachEvent("onload", setupMiniGalleries);
}

function setupMiniGalleries()
{
	var miniGalleryContainers, i;

	miniGalleryContainers = document.getElementsByClassName("minigallery");

	for (i=0; i<miniGalleryContainers.length; i++)
	{
		var miniGallery;
		
		miniGallery = new MiniGallery(miniGalleryContainers[i]);
	}
}

// MiniGallery class 
function MiniGallery(enclosingDiv)
{
	var i, cnt=0, thisMiniGallery = this, showRoomContainer;

	showRoomContainer = document.createElement("div");
	showRoomContainer.setAttribute("class", "showroom");
	enclosingDiv.appendChild(showRoomContainer);

	this._containerDiv = document.createElement("div");
	this._containerDiv.setAttribute("class", "content");
	showRoomContainer.appendChild(this._containerDiv);
	
	this._navigationDiv = document.createElement("div");
	this._navigationDiv.setAttribute("class", "navigation");
	enclosingDiv.appendChild(this._navigationDiv);
	
	if (enclosingDiv.getAttribute('nodeContainerID'))
	{
		this._nodeContainerDiv = document.getElementById(enclosingDiv.getAttribute('nodeContainerID'));
	}
	else
	{
		for (i=0; i<enclosingDiv.childNodes.length; i++)
		{
			try
			{
				if (enclosingDiv.childNodes[i].className == "nodecontainer")
				{
					this._nodeContainerDiv = enclosingDiv.childNodes[i];
				}
			}
			catch(e)
			{
			}
		}
	}
	
	this._effectGallery = new EffectGallery(this._containerDiv);
	this._transitionDelay = 5000;
	this._transitionEffect = "fade";
	
	this._onclickHandler = function(event) { return (thisMiniGallery.handleOnClick(this, event)); };
	
	this._divs = new Array();
	
	for (i=0;i<this._nodeContainerDiv.childNodes.length;i++)
	{
		try
		{
			if (this._nodeContainerDiv.childNodes[i].nodeName.toLowerCase() == "div")
			{
				this._divs.push(this._nodeContainerDiv.childNodes[i]);
			}
		}
		catch(e)
		{
		}
	}

	for (i=0;i<this._divs.length;i++)
	{
		this._effectGallery.addElement(this._divs[i], "mg" + i);
	}

	thisMiniGallery.showIndex(0);

	this._changeTimer = window.setInterval(function(){ thisMiniGallery.showNext(); }, this._transitionDelay);
}

MiniGallery.prototype._containerDiv;
MiniGallery.prototype._nodeContainerDiv;
MiniGallery.prototype._navigationDiv;

MiniGallery.prototype._divs;

MiniGallery.prototype._effectGallery;
MiniGallery.prototype._transitionDelay;
MiniGallery.prototype._transitionEffect;
MiniGallery.prototype._changeTimer;

MiniGallery.prototype._onclickHandler;

MiniGallery.prototype.showNext = function()
{
	var newIndex = this._effectGallery.currentIndex() + 1;

	if (newIndex < 0)
	{
		newIndex = 0;
	}

	if (newIndex >= this._divs.length)
	{
		newIndex = 0;
	}
	
	this.showIndex(newIndex);
}

MiniGallery.prototype.showIndex = function(index)
{
	var thisMiniGallery = this;

	if (this._effectGallery.currentIndex() != index)
	{
		if ((index >= 0) && (index < this._divs.length))
		{
			this._effectGallery.showIndex(index, this._transitionEffect, function(){ thisMiniGallery._renderNavigation(); });
		}
	}
}

MiniGallery.prototype.handleOnClick = function(thisObj, event)
{
	var galleryOffset;

	if (thisObj)
	{
		if (galleryOffset = thisObj.getAttribute("miniGalleryOffset"))
		{
			if (this._changeTimer)
			{
				window.clearInterval(this._changeTimer);
				this._changeTimer = 0;
			}
		
			this.showIndex(galleryOffset);
		}
		
		return (false);
	}
		
	return (true);
}

MiniGallery.prototype._renderNavigation = function()
{
	var thisMiniGallery = this, i, currentIndex = this._effectGallery.currentIndex();

	while (this._navigationDiv.childNodes.length)
	{
		this._navigationDiv.removeChild(this._navigationDiv.childNodes[0]);
	};

	for (i=0;i<this._divs.length;i++)
	{
		var navAElement;
		
		navAElement = document.createElement("a");
		if (i==currentIndex)
		{
			navAElement.setAttribute("class", "selected");
		}
		navAElement.setAttribute("miniGallery", this);
		navAElement.setAttribute("miniGalleryOffset", i);
		
		navAElement.onclick = this._onclickHandler;
		
		this._navigationDiv.appendChild(navAElement);
	}
}

//
// Callisto tools.js
//
// (C) 2004-2007 by IOSPIRIT GmbH. All rights reserved. Distribution and reuse without permission strictly prohibited.
//

function cal_viewfullpic (img_src, img_width, img_height) 
{
	var window_width = img_width; 
	var window_height = img_height;
	var window_scrollbar = "no";
	
	if (window_width  > screen.width)
	{ 
		window_width  = screen.width;  
		window_scrollbar = "yes"; 
	}
	
	if (window_height > screen.height) 
	{ 
		window_height = screen.height; 
		window_scrollbar = "yes"; 
	}

	var window_left = (screen.width  - window_width)  / 2;
	var window_top  = (screen.height - window_height) / 2;

	var winAttribs = 'directories=no,toolbar=no,status=no,menubar=no,resizable=no,dependent=yes'
		+ ',scrollbars=' + window_scrollbar 
		+ ',width=' 	 + window_width 
		+ ',height=' 	 + window_height 
		+ ',top=' 	 + window_top 
		+ ',left=' 	 + window_left;
	
	var ourWindow = window.open('', '_blank', winAttribs);
	var htmlContent =
		'<html><head><title>' + img_src + '</title><body leftmargin="0" topmargin="0" rightmargin="0" marginwidth="0" marginheight="0"><img src="' + img_src + '" onClick="self.close();"></body></html>';

	ourWindow.document.open();
	ourWindow.document.write(htmlContent);
	ourWindow.document.close();
	ourWindow.focus();
}

function cal_setupSizesAndOffsets()
{
	// The code of this function bases on code taken from Lightwindow. Lightwindow has this license:

	// lightWindow.js v1.1
	//
	// Copyright (c) 2007 Einstein Industries
	// Author: Kevin P Miller | http://www.stickmanlabs.com
	// 
	// LightWindow is freely distributable under the terms of an MIT-style license.

	if (window.innerHeight && window.scrollMaxY)
	{	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else
	{
		if (document.body.scrollHeight > document.body.offsetHeight)
		{
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		}
		else
		{ 
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
	}

	if (window.innerHeight)
	{
		windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
	}
	else
	{
		if (document.documentElement && document.documentElement.clientHeight)
		{
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		}
		else
		{
			if (document.body)
			{
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
		}
	}

	if (yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else
	{ 
		pageHeight = yScroll;
	}

	if (xScroll < windowWidth)
	{	
		pageWidth = windowWidth;
	}
	else
	{
		pageWidth = xScroll;
	}
}


function cal_showModalBox(showElement)
{
	var fullOverlay = document.getElementById('cal_fulloverlay');
	
	cal_setupSizesAndOffsets();
	
	// Show backdrop
	fullOverlay.style.display 	= 'block';
	fullOverlay.style.width		= pageWidth + "px";
	fullOverlay.style.height	= pageHeight + "px";
	
	// Center and show element
	showElement.style.display	= 'block';
	showElement.style.left		= ((windowWidth - showElement.offsetWidth) / 2) + 'px';
	showElement.style.top		= yScroll - windowHeight + ((windowHeight - showElement.offsetHeight) / 2) + 'px';
	
	return (true);
}

function cal_toolSortedString(inString)
{
	var charArr = new Array();
	var i, retStr, sub;
	
	for (i=0; i<inString.length; i++)
	{
		sub = inString.substr(i,1);
	
		charArr.push(sub);
	}
	
	charArr.sort();
	
	retStr = "";
	
	for (i=0; i<charArr.length; i++)
	{
		retStr += charArr[i];
	}
	
	return (retStr);
}

