/*
- Slideshow
- Mailmask
*/


/*#######################################################################################################
Program written by Dominik Kressler
Project Name: 	simpleSlide
Version: 		1.0
Date: 			2010-07-19
#########################################################################################################
#########################################################################################################
REQUIREMTENS:
	Libraries:
		Prototype: 		1.6.0.2
		Scriptaculous: 	1.8.1
#########################################################################################################
########################################################################################CONFIGURATION: */

var container = "slideshow";//The parent Object. e.g. an undefined list.
var slideDuration = 2;// Duration of each effect in seconds
var delayTime = 5;// Delay of effect-initializing in seconds
var useTitle = false;// Use the image title attribute to display an overlayed description
var animateTitle = false;
var randomize = true;
/*# CONFIGURATION END ###########*/

//INTERNAL VARIABLES
var i = 0;
var c = 0;
var n = 0;
var imageArray = Array();
var started = false;
var title = String;
var titleHeight = Number;
Event.observe(window, 'load', function() 
{ 
	$('totop').observe('click', function(event)
	{
		Event.stop(event); 
		Effect.ScrollTo('branding');
	});

	if(randomize)
	{
		myArray = $(container).childElements();
		myArray.each(function(elm){
			elm.remove();  
		});
		shuffle(myArray);
		myArray.each(function(elm, indexOf){
			$(container).insert(elm, { position: content })
		});	
	}

	$(container).childElements().each(function(image) {
		if(i != 0) image.setStyle({display:'none'});
		imageArray[imageArray.length] = image;
		if(useTitle)
		{
			title = image.descendants();
			title = $(title[0]).readAttribute('title')
			image.insert(new Element("span", { id: "title"+parseInt(i+1) }));
			$("title"+parseInt(i+1)).innerHTML = title;
			titleHeight = $("title"+parseInt(i+1)).getHeight();
			if(i > 0)$("title"+parseInt(i+1)).setStyle({top:-titleHeight+"px"});
		}
		i++;
	});
	if(i == imageArray.length) slideshow1 = new slideshow();
});
var slideshow = Class.create({
	initialize:function() 
	{		
		realDelay = (!started) ? delayTime : delayTime + slideDuration ;
		new PeriodicalExecuter(function() {						
			if(c == imageArray.length) c = 0;
			n = (c == imageArray.length - 1) ? 0 : c + 1 ;
			new Effect.Parallel([
				new Effect.Appear(imageArray[n], 
				{ 
					sync: true,
					beforeStart: showTitle(imageArray[n])
				}),
				new Effect.Fade(imageArray[c], 
				{ 
					sync: true,
					beforeStart: hideTitle(imageArray[c])
				})
			], { 
				duration: slideDuration
			});
			started = true;
			c++;
		}, realDelay);
	}
});

var hideTitle=function(current)
{
	if(useTitle && animateTitle)
	{
		cTitle = current.childElements();
		titleHeight = cTitle[1].getHeight();
		cTitle = cTitle[1].readAttribute('id');
		new Effect.Move(cTitle, { y: -titleHeight, mode: 'absolute' });
	}
}
var showTitle=function(current)
{
	if(useTitle && animateTitle)
	{
		cTitle = current.childElements();
		cTitle = cTitle[1].readAttribute('id');
		new Effect.Move(cTitle, { y: 0, mode: 'absolute' });
	}
}

var shuffle=function(o){
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};


//MAILMASK
function noSpam(){if(document.getElementById){var at="@";var links=document.getElementsByTagName('a');for(var i=0;i<links.length;i++){var linkElem=links[i];if(linkElem.className=='escape'){var mail=linkElem.firstChild;var domain=linkElem.lastChild;mail.nextSibling.firstChild.innerHTML=at;linkElem.href="mailto:"+mail.data+at+domain.data;}}}}window.addEventListener?window.addEventListener('load',noSpam,false):window.attachEvent('onload',noSpam);
