/*
 Yond Slider para jQuery versão 1.0
 Copyright (c) 2011 Felipe Rohde
 http://felipeRohde.deviantart.com
 http://yond.com.br/

 up: da versão 0.6 até a 0.8 foi implementado suporte para jQuery Easing, então use a vontade :)
 up: 0.9 suporte ao jQuery Mouse Whell
 up: 1.0 todos os bugs (no scroll, botoes, etc) corrigidos
 
 OBS: alguns Eases do jQuery Easing podem não funcionar adequadamente no evento MOUSEOVER pelo fato de que o posicionamento dos elementos é dinâmico, exemplo: easeInElastic e afins

 -------------------------------
 Licensed under the MIT license:
 http://www.opensource.org/licenses/mit-license.php

 Any and all use of this script must be accompanied by this copyright/license notice in its present form.

 -------------------------------
 Licenciado sob a licença MIT:
 http://www.opensource.org/licenses/mit-license.php

 Toda e qualquer utilização deste script deve ser acompanhada por este aviso de copyright / licença na sua forma actual.
 -------------------------------

 */
 
(function($){$.fn.YondSlider=function(options){var defaults={event:'click',easing:'easeInOutCirc',easingInner:'easeOutExpo',hubVertical:false,hubVerticalInner:false,scroll:true,keyboard:false,pagerOver:true,caption:true,pin:true,defaultYond:null,defaultYondInner:1,spacing:1,duration:400,durationInner:800,pager:true,animation:true,rand:'[all]',randtime:4000,display:1,controls:true,innerSlider:'.slider',outSlider:this,iListMarker:'dt',callback:null,callbackInner:null};var o=$.extend(defaults,options);var CoA=(o.hubVertical?'height':'width');var EoT=(o.hubVertical?'top':'left');function randIncs(arr,obj){for(var i=0;i<arr.length;i++){if(arr[i]==obj){return true}}}$.fn.Ystart=function(){$(o.innerSlider,o.outSlider).data('ynd').start()};$.fn.Ystop=function(){$(o.innerSlider,o.outSlider).data('ynd').stop()};$.fn.Ymove=function(iNum){$(o.innerSlider,o.outSlider).data('ynd').move(iNum-1,true)};$(o.outSlider).find('.pagenum').click(function(){var ehActive=$(this).parent().parent().parent();if(!$(ehActive).hasClass('active')){$(ehActive).trigger(o.event)}return false});$('.buttons',o.outSlider).click(function(){$(this).parent().trigger(o.event)});o.outSlider.each(function(){box=$(this);var beyond=box.children('div');var normCoA=beyond.eq(0).css(CoA).replace(/px/,'');if(!o.max){o.max=(normCoA*beyond.size())-(o.min*(beyond.size()-1))}else{o.min=((normCoA*beyond.size())-o.max)/(beyond.size()-1)}if(o.hubVertical){box.css({width:beyond.eq(0).css('width'),height:(normCoA*beyond.size())+(o.spacing*(beyond.size()-1))+'px'})}else{box.css({width:(normCoA*beyond.size())+(o.spacing*(beyond.size()-1))+'px',height:beyond.eq(0).css('height')})}var preCalcEoTs=[];for(i=0;i<beyond.size();i++){preCalcEoTs[i]=[];for(j=1;j<beyond.size()-1;j++){if(i==j){preCalcEoTs[i][j]=o.hubVertical?j*o.min+(j*o.spacing):j*o.min+(j*o.spacing)}else{preCalcEoTs[i][j]=(j<=i?(j*o.min):(j-1)*o.min+o.max)+(j*o.spacing)}}}beyond.each(function(i){if(randIncs(o.rand,$(this).index()+1)||o.rand=='all'||o.rand=='[all]'||o.rand==true){$(this).find('.door').addClass('Yrand');}var theBeyond=$(this);if(i===0){theBeyond.css(EoT,'0px')}else if(i==beyond.size()-1){theBeyond.css(o.hubVertical?'bottom':'right','0px')}else{theBeyond.css(EoT,(i*normCoA)+(i*o.spacing));if(o.defaultYond!=null){theBeyond.css(EoT,preCalcEoTs[(o.defaultYond)-1][i])}else{theBeyond.css(EoT,(i*normCoA)+(i*o.spacing))}}if(o.defaultYond!=null){if(o.defaultYond-1==i){theBeyond.css(CoA,o.max+'px');theBeyond.addClass('active')}else{theBeyond.css(CoA,o.min+'px');theBeyond.removeClass('active')}}theBeyond.css({margin:0,position:'absolute'});theBeyond.bind(o.event,function(event){var prevCoAs=[];var prevEoTs=[];beyond.stop().removeClass('active');beyond.find('.verticalTitle').removeClass('activeTitle');theBeyond.find('.buttons').css('display','none');for(j=0;j<beyond.size();j++){prevCoAs[j]=beyond.eq(j).css(CoA).replace(/px/,'');prevEoTs[j]=beyond.eq(j).css(EoT).replace(/px/,'')}var aniObj={};aniObj[CoA]=o.max;var maxDif=o.max-prevCoAs[i];var prevCoAsMaxDifRatio=prevCoAs[i]/maxDif;$('.buttons').fadeOut();theBeyond.find('.buttons').css('display','block');$(this).find('.verticalTitle').addClass('activeTitle');theBeyond.find('.view').focus();theBeyond.addClass('active').animate(aniObj,{step:function(now){var percentage=maxDif!=0?now/maxDif-prevCoAsMaxDifRatio:1;beyond.each(function(j){if(j!=i){beyond.eq(j).css(CoA,prevCoAs[j]-((prevCoAs[j]-o.min)*percentage)+'px')}if(j>0&&j<beyond.size()-1){beyond.eq(j).css(EoT,prevEoTs[j]-((prevEoTs[j]-preCalcEoTs[i][j])*percentage)+'px')}})},duration:o.animation?o.duration:0,easing:o.easing,complete:function(){if(typeof o.callback=='function')o.callback.call(this)}});})});if(o.pin==false){box.bind("mouseleave",function(){var prevCoAs=[];var prevEoTs=[];beyond.removeClass('active').stop();for(i=0;i<beyond.size();i++){prevCoAs[i]=beyond.eq(i).css(CoA).replace(/px/,'');prevEoTs[i]=beyond.eq(i).css(EoT).replace(/px/,'')}var aniObj={};aniObj[CoA]=normCoA;var normDif=normCoA-prevCoAs[0];beyond.eq(0).animate(aniObj,{step:function(now){var percentage=normDif!=0?(now-prevCoAs[0])/normDif:1;for(i=1;i<beyond.size();i++){beyond.eq(i).css(CoA,prevCoAs[i]-((prevCoAs[i]-normCoA)*percentage)+'px');if(i<beyond.size()-1){beyond.eq(i).css(EoT,prevEoTs[i]-((prevEoTs[i]-((i*normCoA)+(i*o.spacing)))*percentage)+'px')}}},duration:o.animation?o.duration:0,easing:o.easing,})})}});$(o.innerSlider).each(function(){if($(this).find('.pager')&&o.pagerOver){$(this).hover(function(){$(this).find('.pager').stop().animate({opacity:1},'fast');},function(){$(this).find('.pager').stop().animate({opacity:0},1500);})}if($(this).find(o.iListMarker).size()>1){$(this).data('ynd',new YondCaroucel($(this),o));}else{if(o.scroll){$(this).mousewheel(function(objEvent,intDelta){$(this).trigger(o.event);if(!$(this).parent().hasClass('active')){if(!$(this).parent().hasClass('scrolled')){}}else{if(intDelta>0){$(this).parent().prev().trigger(o.event);}if(intDelta<0){$(this).parent().next().trigger(o.event);}}return false})}}});function YondCaroucel(root,o){var oSelf=this;var oViewport=$('.door',root).first();var oContent=$('.view',root).first();var oPages=oContent.children();var oBtnNext=$('.next',root).first();var oBtnPrev=$('.prev',root).first();var oPager=$('.pager',root).first();var iPageSize,iSteps,iCurrent,oTimer,bPause,bForward=true,bhubVerticalInner=o.hubVerticalInner==false;var countElens=$(oContent).find(o.iListMarker).size()-1;var intOverallDelta=countElens;function ini(){iPageSize=bhubVerticalInner?$(oPages[0]).outerWidth(true):$(oPages[0]).outerHeight(true);var iLeftover=Math.ceil(((bhubVerticalInner?oViewport.outerWidth():oViewport.outerHeight())/(iPageSize*o.display))-1);iSteps=Math.max(1,Math.ceil(oPages.length/o.display)-iLeftover);iCurrent=Math.min(iSteps,Math.max(1,o.defaultYondInner))-2;oContent.css(bhubVerticalInner?'width':'height',(iPageSize*oPages.length));oSelf.move(1);setEvents();return oSelf};function setEvents(){if(o.controls&&oBtnPrev.length>0&&oBtnNext.length>0){if(o.defaultYondInner>1){intOverallDelta=intOverallDelta+1-(o.defaultYondInner)}if(o.keyboard==true){$(document).bind('keydown',function(e){if($(e.target).parents().index(o.innerSlider)==-1){}});$(document).keydown(function(e){if(e.keyCode==39){if(intOverallDelta>0){intOverallDelta--;oSelf.move(1);return false}else{$(this).parent().parent().next().trigger(o.event)}}if(e.keyCode==37){if(intOverallDelta>=0&&intOverallDelta<(countElens)){intOverallDelta++;oSelf.move(-1);return false}else{$(this).parent().parent().prev().trigger(o.event)}}})}if(o.scroll){$(oViewport).mousewheel(function(objEvent,intDelta){$(this).trigger(o.event);if(intDelta>0){if(intOverallDelta>=0&&intOverallDelta<(countElens)){intOverallDelta++;oSelf.move(-1);return false}else{$(this).parent().parent().prev().trigger(o.event)}}else if(intDelta<0){if(intOverallDelta>0){intOverallDelta--;oSelf.move(1);return false}else{$(this).parent().parent().next().trigger(o.event)}}})}oBtnPrev.click(function(){intOverallDelta++;oSelf.move(-1);return false});oBtnNext.click(function(){intOverallDelta--;oSelf.move(1);return false})}if(o.rand!=null&&o.rand!=false){$(o.innerSlider).hover(oSelf.stop,oSelf.start)}if(o.pager&&oPager.length>0){$('a',oPager).click(setPager);}};function setButtons(){if(o.controls){oBtnPrev.toggleClass('disable',!(iCurrent>0));oBtnNext.toggleClass('disable',!(iCurrent+1<iSteps))}if(o.pager){var oNumbers=$('.pagenum',oPager);oNumbers.removeClass('activeslide');$(oNumbers[iCurrent]).addClass('activeslide')}};function setPager(oEvent){if($(this).hasClass('pagenum')){intOverallDelta=countElens-parseInt(this.rel);oSelf.move(parseInt(this.rel),true);}return false};function setTimer(){if((o.rand&&!bPause&&$(oViewport).hasClass('Yrand'))){$(oSelf).eq(0).css('display','none');clearTimeout(oTimer);oTimer=setTimeout(function(){iCurrent=iCurrent+1==iSteps?-1:iCurrent;bForward=iCurrent+1==iSteps?false:iCurrent==0?true:bForward;oSelf.move(bForward?1:-1);intOverallDelta=countElens-iCurrent},(o.randtime+(Math.random()*30)))}};this.stop=function(){clearTimeout(oTimer);bPause=true};this.start=function(){bPause=false;setTimer()};this.move=function(iDirection,bPublic){if($(o.iListMarker,this).find('.Ycaption')&&o.caption){$('.Ycaption').stop().delay(o.durationInner+120).css({'opacity':0}).animate({marginTop:+10,opacity:1},{duration:200}).animate({marginTop:0,opacity:1},{duration:200})}iCurrent=bPublic?iDirection:iCurrent+=iDirection;if(iCurrent>-1&&iCurrent<iSteps){var oPosition={};oPosition[bhubVerticalInner?'left':'top']=-(iCurrent*(iPageSize*o.display));oContent.animate(oPosition,{queue:false,easing:o.easingInner,duration:o.animation?o.durationInner:0,complete:function(){if(typeof o.callbackInner=='function')o.callbackInner.call(this,oPages[iCurrent],iCurrent)}});setButtons();setTimer();}};return ini();}}})(jQuery);
