/**
 * @version $Id: mslider.js 64 2015-07-01 18:29:56Z szymon $
 * @package DJ-MediaTools
 * @subpackage DJ-MediaTools mslider layout
 * @copyright Copyright (C) 2012 DJ-Extensions.com, All rights reserved.
 * @license DJ-Extensions.com Proprietary Use License
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 * @developer Szymon Woronowski - szymon.woronowski@design-joomla.eu
 *
 */
(function($){this.DJImageMslider=new Class({Extends:DJImageSlideshow,options:{visible:3,lag:100},initialize:function(a,b){this.setOptions(b);this.visible=this.options.visible;var c=$(a).getElement('div');var d=this.getSize(c);this.offset=100*(this.options.width+this.options.spacing)/d.x;this.parent(a,b);this.last=this.slides.length-(this.slides.length%this.visible);if(this.last==this.slides.length)this.last-=this.visible},setEffectsOptions:function(){this.parent();switch(this.options.slider_type){case'up':case'down':if(this.options.lag)this.startEffect*=2;break;case'left':case'right':this.startEffect*=this.visible;if(this.options.lag)this.startEffect*=2}if(this.options.desc_effect){switch(this.options.desc_effect){case'left':case'right':this.desc_startEffect*=this.visible}}},loadFirstSlide:function(){this.slider.getElement('.dj-slides').fade('hide');for(var i=0;i<this.visible;i++){if(!this.exist(i))continue;var c=this.slides[i].getElement('img.dj-image');var d=function(a,b){if(a.length>1){b=a[1];a=a[0]}a.removeEvent('load',d);this.firstSlideLoaded(i)}.bind(this,[c,i]);c.addEvent('load',d);this.preloadImage(i,false)}},firstSlideLoaded:function(){if(!this.loading)return;for(var i=0;i<this.visible;i++){if(!this.slides[i].loaded)return}this.loader.fade('out');this.slider.getElement('.dj-slides').fade('in');this.autoPlay.delay(this.options.delay+500,this);for(var i=this.visible;i<2*this.visible;i++){if(this.exist(i))this.preloadImage(i,false)}this.loading=0},exist:function(a){return(a in this.slides)},setSlidesEffects:function(){for(var i=0;i<this.slides.length;i++){this.slides[i].set('tween',{property:this.property,link:'chain',transition:this.options.transition,duration:this.options.duration});if(i<this.current+this.visible)this.slides[this.current+i].get('tween').set(this.endEffect);else{if(this.options.slider_type=='fade'||this.options.slider_type=='ifade')this.slides[i].setStyle('visibility','hidden');this.slides[i].get('tween').set(this.startEffect)}this.slides[i].setStyle('margin-left',(this.offset*(i%this.visible))+'%')}if(this.options.slider_type=='ifade'){this.images=new Array(this.slides.length);for(var i=0;i<this.slides.length;i++){this.slides[i].set('tween',{duration:this.options.duration/2});this.images[i]=this.slides[i].getElement('.dj-image');if(this.images[i]){this.images[i].setStyle('max-width','none');this.images[i].set('tween',{property:'width',link:'chain',transition:this.options.transition,duration:this.options.duration/2})}}}if(this.options.desc_effect){var a=this.slider.getElement('div');var b=this.getSize(a);dwidth=100*this.options.dwidth/b.x;dpos=100*this.descriptions[0].getPosition(a).x/b.x;for(i=0;i<this.descriptions.length;i++){this.descriptions[i].set('tween',{property:this.desc_property,link:'chain',transition:Fx.Transitions.Expo.easeInOut,duration:this.options.duration/2});if(i<this.current+this.visible)this.descriptions[this.current+i].get('tween').set(this.desc_endEffect);else{if(this.options.desc_effect=='fade')this.descriptions[i].setStyle('visibility','hidden');this.descriptions[i].get('tween').set(this.desc_startEffect)}this.descriptions[i].setStyle('width',dwidth+'%');this.descriptions[i].setStyle('left',(dpos+(this.offset*(i%this.visible)))+'%')}}},setIndicators:function(){this.indicators=this.slider.getElements('.dj-indicators .dj-load-button');if(this.indicators.length){this.indicators.each(function(a,b){a.addEvent('click',this.loadSlide.bind(this,b*this.visible))}.bind(this))}},prevSlide:function(){if(this.current<this.visible){this.loadSlide(this.last)}else{this.loadSlide(this.current-this.visible)}},nextSlide:function(){if(this.current>=(this.last)){this.loadSlide(0)}else{this.loadSlide(this.current+this.visible)}},preloadImage:function(b,c){var d=this.slides[b].getElement('img.dj-image');if(this.slides[b].loaded)return;this.slides[b].loaded=true;if(c){this.loading++;this.loader.fade('in');var e=function(a,i){if(a.length>1){i=a[1];a=a[0]}this.loading--;this.loader.fade('out');if(!this.loading){i-=(i%this.visible);this.loadSlide(i)}a.removeEvent('load',e)}.bind(this,[d,b]);d.addEvent('load',e)}var f=d.getProperty('data-sizes'),srcset=d.getProperty('data-srcset'),src=d.getProperty('data-src');if(f){d.setProperty('sizes',f);d.removeProperty('data-sizes')}if(srcset){d.setProperty('srcset',srcset);d.removeProperty('data-srcset')}if(src){d.setProperty('src',src);d.removeProperty('data-src')}picturefill({elements:[d]})},loadSlide:function(a){if(this.current==a||this.loading)return;var b=true;for(var i=a;i<a+this.visible;i++){if(!this.exist(i))continue;var c=this.slides[i].getElement('img.dj-image');if(c&&!this.slides[i].loaded){this.preloadImage(i,true);b=false}}if(!b)return;for(var i=0;i<this.visible;i++){var d=this.current+i;this.slide.delay(i*this.options.lag,this,[d,a+i])}for(var i=a+this.visible;i<a+2*this.visible;i++){if(this.exist(i))this.preloadImage(i,false)}this.setCurrentSlide(a)},slide:function(b,d){if(this.options.slider_type=='fade'){this.loading++;if(this.exist(d))this.slides[d].setStyle('visibility','visible');if(this.exist(b))this.slides[b].get('tween').start(this.endEffect,this.startEffect);if(this.exist(d)){this.slides[d].get('tween').start(this.startEffect,this.endEffect).chain(function(c){this.loading--;if(this.exist(c))this.slides[c].setStyle('visibility','hidden')}.bind(this,b))}else(function(c){this.loading--;if(this.exist(c))this.slides[c].setStyle('visibility','hidden')}).delay(this.options.duration,this,b)}else if(this.options.slider_type=='ifade'){this.loading++;if(this.exist(b)&&!this.images[b].startWidth){this.images[b].startWidth=this.getSize(this.images[b]).x;this.images[b].sWidth=this.sliderWidth}if(this.exist(d)&&!this.images[d].startWidth){this.images[d].startWidth=this.getSize(this.images[d]).x;this.images[d].sWidth=this.sliderWidth}if(this.exist(b))this.images[b].get('tween').start(this.images[b].startWidth,this.options.ifade_multiplier*this.images[b].startWidth);if(this.exist(d))(function(n){this.images[n].get('tween').start(this.options.ifade_multiplier*this.images[n].startWidth,this.images[n].startWidth)}).delay(this.options.duration/2,this,d);if(this.exist(b))this.slides[b].get('tween').start(this.endEffect,this.startEffect);if(this.exist(d))(function(n,a){this.slides[n].setStyle('visibility','visible');this.slides[n].get('tween').start(this.startEffect,this.endEffect).chain(function(c){this.loading--;if(this.exist(c))this.slides[c].setStyle('visibility','hidden')}.bind(this,a))}).delay(this.options.duration/2,this,[d,b]);else(function(c){this.loading--;if(this.exist(c))this.slides[c].setStyle('visibility','hidden')}).delay(this.options.duration,this,b)}else{if((d>=b&&(d<this.last||(b-(b%this.visible))!=0))||(d-(d%this.visible)==0&&b>=this.last)){if(this.exist(b))this.slides[b].tween(this.endEffect,-1*this.startEffect);if(this.exist(d))this.slides[d].tween(this.startEffect,this.endEffect)}else{if(this.exist(b))this.slides[b].tween((this.endEffect,this.startEffect));if(this.exist(d))this.slides[d].tween(-1*this.startEffect,this.endEffect)}}if(this.options.desc_effect){if(this.exist(d)&&this.options.slider_type!='fade'&&this.options.slider_type!='ifade')this.loading++;if(this.exist(b)){this.descriptions[b].get('tween').start(this.desc_endEffect,this.desc_startEffect).chain(function(c){this.descriptions[c].setStyle('visibility','hidden')}.bind(this,b))}if(this.exist(d)){(function(n){this.descriptions[n].setStyle('visibility','visible');this.descriptions[n].get('tween').start(this.desc_startEffect,this.desc_endEffect).chain(function(){if(this.options.slider_type!='fade'&&this.options.slider_type!='ifade')this.loading--}.bind(this))}).delay(this.options.duration/2,this,d)}}},setCurrentSlide:function(a){if(this.indicators.length){this.indicators[Math.ceil(this.current/this.visible)].removeClass('dj-load-button-active');this.indicators[Math.ceil(a/this.visible)].addClass('dj-load-button-active')}if(this.playButton&&this.pauseButton){this.playButton.tween(0);this.pauseButton.tween(0)}this.current=a}})})(document.id);