//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License.

MooTools.More={version:"1.2.5.1",build:"254884f2b83651bf95260eed5c6cceb838e22d8e"};Element.implement({measure:function(e){var g=function(h){return !!(!h||h.offsetHeight||h.offsetWidth);
};if(g(this)){return e.apply(this);}var d=this.getParent(),f=[],b=[];while(!g(d)&&d!=document.body){b.push(d.expose());d=d.getParent();}var c=this.expose();
var a=e.apply(this);c();b.each(function(h){h();});return a;},expose:function(){if(this.getStyle("display")!="none"){return $empty;}var a=this.style.cssText;
this.setStyles({display:"block",position:"absolute",visibility:"hidden"});return function(){this.style.cssText=a;}.bind(this);},getDimensions:function(a){a=$merge({computeSize:false},a);
var f={};var d=function(g,e){return(e.computeSize)?g.getComputedSize(e):g.getSize();};var b=this.getParent("body");if(b&&this.getStyle("display")=="none"){f=this.measure(function(){return d(this,a);
});}else{if(b){try{f=d(this,a);}catch(c){}}else{f={x:0,y:0};}}return $chk(f.x)?$extend(f,{width:f.x,height:f.y}):$extend(f,{x:f.width,y:f.height});},getComputedSize:function(a){if(a&&a.plains){a.planes=a.plains;
}a=$merge({styles:["padding","border"],planes:{height:["top","bottom"],width:["left","right"]},mode:"both"},a);var c={width:0,height:0};switch(a.mode){case"vertical":delete c.width;
delete a.planes.width;break;case"horizontal":delete c.height;delete a.planes.height;break;}var b=[];$each(a.planes,function(f,g){f.each(function(h){a.styles.each(function(i){b.push((i=="border")?i+"-"+h+"-width":i+"-"+h);
});});});var e={};b.each(function(f){e[f]=this.getComputedStyle(f);},this);var d=[];$each(a.planes,function(f,g){var h=g.capitalize();c["total"+h]=c["computed"+h]=0;
f.each(function(i){c["computed"+i.capitalize()]=0;b.each(function(k,j){if(k.test(i)){e[k]=e[k].toInt()||0;c["total"+h]=c["total"+h]+e[k];c["computed"+i.capitalize()]=c["computed"+i.capitalize()]+e[k];
}if(k.test(i)&&g!=k&&(k.test("border")||k.test("padding"))&&!d.contains(k)){d.push(k);c["computed"+h]=c["computed"+h]-e[k];}});});});["Width","Height"].each(function(g){var f=g.toLowerCase();
if(!$chk(c[f])){return;}c[f]=c[f]+this["offset"+g]+c["computed"+g];c["total"+g]=c[f]+c["total"+g];delete c["computed"+g];},this);return $extend(e,c);}});
Element.implement({isDisplayed:function(){return this.getStyle("display")!="none";},isVisible:function(){var a=this.offsetWidth,b=this.offsetHeight;return(a==0&&b==0)?false:(a>0&&b>0)?true:this.style.display!="none";
},toggle:function(){return this[this.isDisplayed()?"hide":"show"]();},hide:function(){var b;try{b=this.getStyle("display");}catch(a){}if(b=="none"){return this;
}return this.store("element:_originalDisplay",b||"").setStyle("display","none");},show:function(a){if(!a&&this.isDisplayed()){return this;}a=a||this.retrieve("element:_originalDisplay")||"block";
return this.setStyle("display",(a=="none")?"block":a);},swapClass:function(a,b){return this.removeClass(a).addClass(b);}});Document.implement({clearSelection:function(){if(document.selection&&document.selection.empty){document.selection.empty();
}else{if(window.getSelection){var a=window.getSelection();if(a&&a.removeAllRanges){a.removeAllRanges();}}}}});Fx.Elements=new Class({Extends:Fx.CSS,initialize:function(b,a){this.elements=this.subject=$$(b);
this.parent(a);},compute:function(g,h,j){var c={};for(var d in g){var a=g[d],e=h[d],f=c[d]={};for(var b in a){f[b]=this.parent(a[b],e[b],j);}}return c;
},set:function(b){for(var c in b){if(!this.elements[c]){continue;}var a=b[c];for(var d in a){this.render(this.elements[c],d,a[d],this.options.unit);}}return this;
},start:function(c){if(!this.check(c)){return this;}var h={},j={};for(var d in c){if(!this.elements[d]){continue;}var f=c[d],a=h[d]={},g=j[d]={};for(var b in f){var e=this.prepare(this.elements[d],b,f[b]);
a[b]=e.from;g[b]=e.to;}}return this.parent(h,j);}});Fx.Accordion=new Class({Extends:Fx.Elements,options:{fixedHeight:false,fixedWidth:false,display:0,show:false,height:true,width:false,opacity:true,alwaysHide:false,trigger:"click",initialDisplayFx:true,returnHeightToAuto:true},initialize:function(){var c=Array.link(arguments,{container:Element.type,options:Object.type,togglers:$defined,elements:$defined});
this.parent(c.elements,c.options);this.togglers=$$(c.togglers);this.previous=-1;this.internalChain=new Chain();if(this.options.alwaysHide){this.options.wait=true;
}if($chk(this.options.show)){this.options.display=false;this.previous=this.options.show;}if(this.options.start){this.options.display=false;this.options.show=false;
}this.effects={};if(this.options.opacity){this.effects.opacity="fullOpacity";}if(this.options.width){this.effects.width=this.options.fixedWidth?"fullWidth":"offsetWidth";
}if(this.options.height){this.effects.height=this.options.fixedHeight?"fullHeight":"scrollHeight";}for(var b=0,a=this.togglers.length;b<a;b++){this.addSection(this.togglers[b],this.elements[b]);
}this.elements.each(function(e,d){if(this.options.show===d){this.fireEvent("active",[this.togglers[d],e]);}else{for(var f in this.effects){e.setStyle(f,0);
}}},this);if($chk(this.options.display)||this.options.initialDisplayFx===false){this.display(this.options.display,this.options.initialDisplayFx);}if(this.options.fixedHeight!==false){this.options.returnHeightToAuto=false;
}this.addEvent("complete",this.internalChain.callChain.bind(this.internalChain));},addSection:function(e,c){e=document.id(e);c=document.id(c);var f=this.togglers.contains(e);
this.togglers.include(e);this.elements.include(c);var a=this.togglers.indexOf(e);var b=this.display.bind(this,a);e.store("accordion:display",b);e.addEvent(this.options.trigger,b);
if(this.options.height){c.setStyles({"padding-top":0,"border-top":"none","padding-bottom":0,"border-bottom":"none"});}if(this.options.width){c.setStyles({"padding-left":0,"border-left":"none","padding-right":0,"border-right":"none"});
}c.fullOpacity=1;if(this.options.fixedWidth){c.fullWidth=this.options.fixedWidth;}if(this.options.fixedHeight){c.fullHeight=this.options.fixedHeight;}c.setStyle("overflow","hidden");
if(!f){for(var d in this.effects){c.setStyle(d,0);}}return this;},removeSection:function(e,b){var a=this.togglers.indexOf(e);var c=this.elements[a];var d=function(){this.togglers.erase(e);
this.elements.erase(c);this.detach(e);}.bind(this);if(this.now==a||b!=undefined){this.display($pick(b,a-1>=0?a-1:0)).chain(d);}else{d();}return this;},detach:function(b){var a=function(c){c.removeEvent(this.options.trigger,c.retrieve("accordion:display"));
}.bind(this);if(!b){this.togglers.each(a);}else{a(b);}return this;},display:function(a,b){if(!this.check(a,b)){return this;}b=$pick(b,true);a=($type(a)=="element")?this.elements.indexOf(a):a;
if(a==this.previous&&!this.options.alwaysHide){return this;}if(this.options.returnHeightToAuto){var d=this.elements[this.previous];if(d&&!this.selfHidden){for(var c in this.effects){d.setStyle(c,d[this.effects[c]]);
}}}if((this.timer&&this.options.wait)||(a===this.previous&&!this.options.alwaysHide)){return this;}this.previous=a;var e={};this.elements.each(function(h,g){e[g]={};
var f;if(g!=a){f=true;}else{if(this.options.alwaysHide&&((h.offsetHeight>0&&this.options.height)||h.offsetWidth>0&&this.options.width)){f=true;this.selfHidden=true;
}}this.fireEvent(f?"background":"active",[this.togglers[g],h]);for(var j in this.effects){e[g][j]=f?0:h[this.effects[j]];}},this);this.internalChain.clearChain();
this.internalChain.chain(function(){if(this.options.returnHeightToAuto&&!this.selfHidden){var f=this.elements[a];if(f){f.setStyle("height","auto");}}}.bind(this));
return b?this.start(e):this.set(e);}});var Accordion=new Class({Extends:Fx.Accordion,initialize:function(){this.parent.apply(this,arguments);var a=Array.link(arguments,{container:Element.type});
this.container=a.container;},addSection:function(c,b,e){c=document.id(c);b=document.id(b);var d=this.togglers.contains(c);var a=this.togglers.length;if(a&&(!d||e)){e=$pick(e,a-1);
c.inject(this.togglers[e],"before");b.inject(c,"after");}else{if(this.container&&!d){c.inject(this.container);b.inject(this.container);}}return this.parent.apply(this,arguments);
}});

/* sbCarousel2 v1.3, Copyright Sitebuilders Finland Oy 2011,  http://www.sitebuilders.fi  */
var sbCarousel2 = new Class({
	Implements: [Options],
	options: {
		createControls	: true,
		controlContainer:	'',
		time			: 5500,
		duration		: 600,
		intialDelay		: 800,
		firstImage		: 1,
		preLoad			: false,  // Assets 
		mode			: 'right', // left, right, fade
		autoPlay		: true,
		stopOnHover		: true,
		zoomable		: true,
		container		: '',
		controlsContainer: '',
		createFirstLast	: false,
		createNumbers	: true,
		createStopPlay	: false,
		injectNumbers	: false,
		createCount		: false,
		elementType		: 'images', // images, links, 
		elements		: 'img'  // img, links, tai esim. div.class, li tms.
	},
	initialize: function(el, options) {
		this.setOptions(options);
		this.container = document.id(el);
		if (this.container){
			this.items = this.container.getElements(this.options.elements);
			this.controlContainer = this.options.controlContainer || this.container;
			this.no = 0;
			this.queue = {};
			this.size = this.container.addClass('js').getCoordinates();
			if (this.items.length > 1) {
				this.getItems(this.container);
				if(this.options.createCount)this.createCount();
			}
			else if (this.items.length == 1){
				this.items.setStyle('visibility','visible');
			}
		}
	},
	getItems: function() {
		if (this.options.elementType == 'links'){
			var Links = this.items.get('href');
			this.items = [];
			Links.each(function(e, i){
				var n = new Element('img', {'src': e}).setStyles({'height':this.size.height,'width':this.size.width});
				this.items.include(n);
			}.bind(this));
		}
		var self = this;
		this.Current = this.items[0].addClass('current');
		this.items.each(function(e, i){
			e.no = i;
		});
		this.items.current = this.items[0].addClass('current');
		if (this.items.length > 1 && this.options.createControls != false)this.createControls();
		//this.Max = this.items.length;
		if (this.options.autoPlay) {
			this.startTimer();
			if (this.options.stopOnHover){
				this.container.addEvents({
					mouseenter: function(){
						self.stopTimer();
					},
					mouseleave: function(){
						self.startTimer();
					}
				})
			}
		}
	},
	createCount: function(){
		this.count = new Element('div', {
			'class'	: 'count',
			'text'	: '1 / '+this.items.length
		}).inject(this.controlContainer);
	},
	createControls: function(el) {
		var self = this;
		if (this.options.controlsContainer == '') this.options.controlsContainer = this.Container;
		//var controlsContainer = (this.options.controlsContainer != '')?$(this.options.controlsContainer):this.Container;
		this.controlList = new Element('ul', {
			'class': 'controlContainer'
		}).inject(this.controlContainer, 'bottom');
		this.Previous = new Element('li', {
			'class': 'previous nonActive',
			'events': {
				'click': function(){
					self.goTo('previous');
				}
			},
			'text'	: ' '
		}).inject(this.controlList);
		if (this.options.createStopPlay){
			this.Play = new Element('li', {
			'class': 'play',
			'events': {
				'click': function(){
					self.startTimer();
				}
			},
			'text'	: ' '
			}).inject(this.controlList);
			this.Stop = new Element('li', {
				'class': 'stop',
				'events': {
					'click': function(){
						self.stopTimer();
					}
				},
				'text'	: ' '
			}).inject(this.controlList);
		}
		if (this.options.createNumbers){
			this.items.each(function(e, i){
				var movieInfo = new Element('li', {
					'class'	: 'movieInfo',
					'events': {
						'click': function(){
							if (!this.hasClass('current')) {
								self.goTo(i+1);
							}
						},
						'mouseenter': function(){
						},
						'mouseleave': function(){
						}
					}
				}).inject(this.controlList);
				movieInfo.setProperty('text', i+1);
				e.store('myList', movieInfo);
				if (i == (this.options.firstImage-1)){
					self.currentLiItem = movieInfo;
					movieInfo.addClass('current');
				}
			}.bind(this));
		};
		
		this.Next = new Element('li', {
			'class': 'next',
			'events': {
				'click': function(){
					self.goTo('next');
				}
			},
			'text'	: ' '
		}).inject(this.controlList);
		
		if(this.options.createFirstLast) {
			this.First = new Element('li', {
				'class': 'first',
				'events': {
					'click': function(){
						self.goTo('first')
					}
				},
				'text': ' '
			}).inject(this.controlList, 'top');
			this.Last = new Element('li', {
				'class': 'last',
				'events': {
					'click': function(){
						self.goTo('last')
					}
				},
				'text': ' '
			}).inject(this.controlList, 'bottom');
		}
	},
	showNext: function(el) {
		if (this.options.preLoad == true && this.options.elementType == 'images'){
			new Asset.image(el.src, {
				onload: this.showThis.bind(this, el)
			})
		}
		else {
			this.showThis(el)
		};
	},
	showThis: function(el) {
		if (this.container.hasChild(el) != true){
			this.addImage(el);
		}
		el.addClass('newCurrent');
		this.main = this.container.getCoordinates();
		switch(this.options.mode) {
		case 'right':
			el.setStyles({
				'left' : this.main.width
			});
			vars = ['left', this.main.width, 0];
			break;
		case 'fade':
			el.setStyles({
				'left' 		: 0,
				'opacity'	: 0
			});
			vars = ['opacity', 0, 1];
			break;
		case 'left':
			el.setStyles({
				'left' 		: -this.main.width
			});
			vars = ['left', -this.main.width, 0];
			break;
		}
		this.showMe(el, vars);
	},
	showMe: function(el, vars) {
		var it = [el, this.Current];
		var whenComplete = function() {
			el.removeClass('newCurrent');
			this.Current.removeClass('current');
			this.Current = el.addClass('current');
			this.preloadNext(this.items[this.no+1]);
			this.currentLiItem = el.retrieve('myList');
			this.moving = 0;
			if (this.queue.el != undefined) {
				var ne = this.queue.el;
				this.queue.el = undefined;
				this.goTo(ne);
			}
			if (this.count) this.count.set('text', this.Current.no+1+' / '+this.items.length);
		}.bind(this);
		var whenStart = function() {
			//console.log(el);
			this.moving = 1;
			var jep = el.retrieve('myList');
			if (this.no == this.items.length-1){
				this.Next.addClass('nonActive').removeClass('Active');
				if(this.Last) this.Last.addClass('nonActive').removeClass('Active');
			}
			if (this.no != this.items.length-1){
				this.Next.addClass('Active').removeClass('nonActive');
				if(this.Last) this.Last.addClass('Active').removeClass('nonActive');
			}
			if (this.no == 0){
				this.Previous.addClass('nonActive').removeClass('Active');
				if(this.First) this.First.addClass('nonActive').removeClass('Active');
			}
			if (this.no != 0){
				this.Previous.addClass('Active').removeClass('nonActive');
				if(this.First) this.First.addClass('Active').removeClass('nonActive');
			}
			if (jep != null) {
				jep.addClass('current');
				this.currentLiItem.removeClass('current');
			}
		}.bind(this);
		var moveImage = new Fx.Tween(el, {
			duration: this.options.duration,
			onStart: function(el) {
				whenStart();
			},
			onComplete: function(el) {
				whenComplete();
			}
		});
		var moveImages = new Fx.Elements(it, {
			duration: this.options.duration,
			onStart: function(el) {
				whenStart();
			},
			onComplete: function(){
				whenComplete();
			}
		});
		var l = el.getStyle('left').toInt();
		if (this.options.mode == 'fade'){
			moveImage.start('opacity', 1);
		}
		else {
			moveImages.start({
				'0': {
					'left': [l, 0]
				},
				'1': {
					'left': [0, -l]
				}
			});
		}
	},
	goTo: function(el, vars) {
		if (this.moving) {
			this.queue.el = el;
		}
		if (!this.moving) {
			var el = el || 'next';

			if (el == 'next'){
				if(this.no < this.items.length-1){
					this.no++;
		//			this.options.mode = 'right';
				}
				else {
					this.no = 0;
				}
			}
			if (el == 'previous') {	
				if (this.no > 0){
					this.no--;
			//		this.options.mode = 'left';
				}
				else {
					this.no = this.items.length-1;
				}
			}
			if (el == 'last') {	
			//	this.options.mode = 'right';
				if (this.no != this.items.length-1){
					this.no = this.items.length-1;
				}
			}
			if (el == 'first') {	
			//	this.options.mode = 'left';
				if (this.no != 0){
					this.no = 0;
				}
			}
			if ($type(el) == 'number') {
			//	this.options.mode = (el > this.no)?'right':'left'; // tsekkaa minne suuntaan skrollataan
				this.no = el-1;
			}
			if (this.options.mode != 'fade'){
				this.options.mode = (this.Current.no < this.no)?'right':'left'; // tsekkaa minne suuntaan skrollataan
			}
			if (this.options.autoPlay) this.clearTimer();
			this.showNext(this.items[this.no]);
		}
	},
	preloadNext: function(el) {
		var self = this;
		if (this.no != this.items.length-1){
			if (this.options.preLoad == true && el){
				new Asset.image(el.src, {
					onload:function(el) {
						self.addImage.bind(this, el);
						//console.log('valmis');
					}
				});
			}
		}
	},
	preloadImage:  function(el) {

	},
	addImage:  function(el) {
		el.inject(this.Container);
	},
	myTimer: function() {
		this.timer = this.goTo.periodical(this.options.time, this);
	},
	startTimer: function(){
		this.myTimer();
	},
	stopTimer: function(){
        $clear(this.timer);
	},
	clearTimer: function(){
        $clear(this.timer);
        this.myTimer();
	}
});

window.addEvent('domready', function() {
	new sbCarousel2(document.id('newsScroller'), {
		elements:'.NewsSummary',
		mode:'fade',
		createNumbers: false,
		createStopPlay: true,
		createCount: true,
		stopOnHover:false,
		controlContainer: document.id('controls')
	});
	//new sbCarousel2(document.id('newsScroller'), {elements:'.NewsSummary'});
});
