var AJAX=ROOT+'/'+CONTROLLER+'/ajax/';
counter=0;

Carousel=new Class({
	Implements:Options,
	options:{
		cssProperty:'opacity',
		cssPropertyStart:1,
		cssPropertyFinish:0,
		transitionDuration:1000,
		transitionDelay:5000
	},
	initialize:function(elements, options){
		this.setOptions(options);
		this.elements=elements;
		this.numSlides=elements.length;
		this.reorder();
		return this;
	},
	start:function(){
		this.step.delay(this.options.transitionDelay, this);
	},
	reorder:function(){
		for(var i=0; i<this.elements.length; i++){
			el=this.elements[i];
			el.setStyle('z-index', this.numSlides-i);
			el.setStyle(this.options.cssProperty, this.options.cssPropertyStart);
		}
	},
	step:function(){
		this.reorder();
		new Fx.Tween(this.elements[0], {
				carousel:this,
				duration:this.options.transitionDuration,
				onComplete:function(){
					var c=this.options.carousel;
					var deadElement=c.elements.shift();
					//console.log("remove "+deadElement.id+" and push to bottom");
					c.elements.push(deadElement);
					//console.log("bottom element is now "+c.elements[c.elements.length-1].id+", top element is "+c.elements[0].id);
					c.step.delay(c.options.transitionDelay, c);
				}
			}).start(this.options.cssProperty, [this.options.cssPropertyStart, this.options.cssPropertyFinish]);
	}
});


window.addEvent('domready', function(){
	$$('ul#main-menu ul, ul#get-involved-menu ul').each(function(el){
		el.setStyle('opacity', 0);
	});
	$$('ul#main-menu li, ul#get-involved-menu li').each(function(el){
		el.addEvent('mouseenter', function(){
			if(subMenu=this.getElement('ul')){
				subMenu.fade(.8);
			}
		});
		el.addEvent('mouseleave', function(){
			if(subMenu=this.getElement('ul')){
				subMenu.fade(0);
			}
		});
	});
	$$('div.home-slide').each(function(el, index){
		el.setStyle('opacity', 0);
	});

	if($(document.body).hasClass('home')){
		$('home-body').setStyles({
			backgroundImage:'url(/static/images/framework/loader.gif)',
			backgroundPosition:'center',
			backgroundRepeat:'no-repeat'
		});
		allImages=new Asset.images(homeImages, {
			onProgress:function(counter, index, source){
				//console.log('loaded '+counter+' images');
			},
			onComplete:function(){
				slides=$$('div.home-slide');
				slides.each(function(el, index){
					allImages[index].inject(el, 'top');
					el.setStyle('opacity', 1);
				});
				homeTransitions=new Carousel(slides);
				homeTransitions.start();
			}
		});
		


		/*
		$$('ul#work-links li a').each(function(el, index){
			el.setStyle('opacity', '.6');
			el.store('linkFader', new Fx.Tween(el, {link:'cancel'}));
			var h1=el.getSiblings('h1')[0];
			h1.setStyle('opacity', 0);
			var slide=$(h1.get('text').toLowerCase()+'-slide');
			slide.setStyle('zIndex', 5-index);
			activeSlide=slide;
			//console.log(slide.id);
			slide.store('fader', new Fx.Tween(slide, {link:'cancel'}));
			el.store('slide', slide);
			el.store('titleFader', new Fx.Tween(h1, {link:'cancel'}));
			el.addEvent('mouseover', function(){
				$(this).retrieve('linkFader').start('opacity', .9);
				$(this).retrieve('titleFader').start('opacity', 1);
				bringToFront($(this).retrieve('slide'));
			});
			el.addEvent('mouseout', function(){
				$(this).retrieve('linkFader').start('opacity', .6);
				$(this).retrieve('titleFader').start('opacity', 0);
			});
		});
		*/
	} else {
		$$('ul#work-menu li a').each(function(el, index){
			if(!el.hasClass('active')){
				el.setStyle('opacity', .5);
				el.store('linkFader', new Fx.Morph(el, {link:'cancel'}));
				var h1=el.getSiblings('h1')[0];
				h1.setStyle('opacity', .4);
				el.store('titleFader', new Fx.Tween(h1, {link:'cancel'}));
				el.addEvent('mouseover', function(){
					$(this).retrieve('linkFader').start({opacity: .9, color:'#FFFFFF'});
					$(this).retrieve('titleFader').start('opacity', 1);
				});
				el.addEvent('mouseout', function(){
					$(this).retrieve('linkFader').start({opacity: .5, color:'#000000'});
					$(this).retrieve('titleFader').start('opacity', .5);
				});
			}
		});
	}
	bubbs=$$('#sda-bubble ul li a');
	if(bubbs.length>0){
		bubbs[0].focus();
	}
});

/*function bringToFront(slide){
	if(slide.getStyle('z-index')!=5){
		activeSlide.setStyles({
			opacity:1,
			zIndex:5
		});
		slide.setStyles({
			opacity:1,
			zIndex:4
		});
		$$('div.home-slide').each(function(el){
			if(el!=slide && el!=activeSlide){
				el.setStyle('z-index', 1);
			}
		});
		activeSlide.retrieve('fader').start('opacity', 0);
		activeSlide=slide;
	} else {
		slide.retrieve('fader').start('opacity', 1);
		activeSlide=slide;
	}
}
*/
function showComment(com){
	comments=['This is my favourite module. I really like the variety, knowledge and expertise of the different speakers.',
	'I was able to develop my personal skills and self confidence as well as make useful contacts and build up a work related network.',
	'I enjoying working with a group of like-minded people towards a common goal, especially as it addresses a real community need.'];
	$('sda-comment-text').set('html', '"'+comments[com]+'"');
}
