/*
 * jQuery Nivo Slider v2.0
 * http://nivo.dev7studios.com
 *
 * Copyright 2010, Gilbert Pellegrom
 * Free to use and abuse under the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * May 2010 - Pick random effect from specified set of effects by toronegro
 * May 2010 - controlNavThumbsFromRel option added by nerd-sh
 * May 2010 - Do not start nivoRun timer if there is only 1 slide by msielski
 * April 2010 - controlNavThumbs option added by Jamie Thompson (http://jamiethompson.co.uk)
 * March 2010 - manualAdvance option added by HelloPablo (http://hellopablo.co.uk)
 */
(function(c){c.fn.nivoSlider=function(q){var i=c.extend({},c.fn.nivoSlider.defaults,q);return this.each(function(){var a={currentSlide:0,currentImage:'',totalSlides:0,randAnim:'',running:false,paused:false,stop:false};var f=c(this);f.data('nivo:vars',a);f.css('position','relative');f.addClass('nivoSlider');var b=f.children();b.each(function(){var d=c(this);var m='';if(!d.is('img')){if(d.is('a')){d.addClass('nivo-imageLink');m=d}d=d.find('img:first')}var e=d.width();if(e==0)e=d.attr('width');var k=d.height();if(k==0)k=d.attr('height');if(e>f.width()){f.width(e)}if(k>f.height()){f.height(k)}if(m!=''){m.css('display','none')}d.css('display','none');a.totalSlides++});if(i.startSlide>0){if(i.startSlide>=a.totalSlides)i.startSlide=a.totalSlides-1;a.currentSlide=i.startSlide}if(c(b[a.currentSlide]).is('img')){a.currentImage=c(b[a.currentSlide])}else{a.currentImage=c(b[a.currentSlide]).find('img:first')}if(c(b[a.currentSlide]).is('a')){c(b[a.currentSlide]).css('display','block')}f.css('background','url('+a.currentImage.attr('src')+') no-repeat');for(var g=0;g<i.slices;g++){var j=Math.round(f.width()/i.slices);if(g==i.slices-1){f.append(c('<div class="nivo-slice"></div>').css({left:(j*g)+'px',width:(f.width()-(j*g))+'px'}))}else{f.append(c('<div class="nivo-slice"></div>').css({left:(j*g)+'px',width:j+'px'}))}}f.append(c('<div class="nivo-caption"><p></p></div>').css({display:'none',opacity:i.captionOpacity}));if(a.currentImage.attr('title')!=''){c('.nivo-caption p',f).html(a.currentImage.attr('title'));c('.nivo-caption',f).fadeIn(i.animSpeed)}var h=0;if(!i.manualAdvance&&b.length>1){h=setInterval(function(){n(f,b,i,false)},i.pauseTime)}if(i.pauseOnHover){f.hover(function(){a.paused=true;clearInterval(h);h=''},function(){a.paused=false;if(h==''&&!i.manualAdvance){h=setInterval(function(){n(f,b,i,false)},i.pauseTime)}})}f.bind('nivo:animFinished',function(){a.running=false;c(b).each(function(){if(c(this).is('a')){c(this).css('display','none')}});if(c(b[a.currentSlide]).is('a')){c(b[a.currentSlide]).css('display','block')}if(h==''&&!a.paused&&!i.manualAdvance){h=setInterval(function(){n(f,b,i,false)},i.pauseTime)}i.afterChange.call(this)})});function n(e,k,a,f){var b=e.data('nivo:vars');if((!b||b.stop)&&!f)return false;a.beforeChange.call(this);if(!f){e.css('background','url('+b.currentImage.attr('src')+') no-repeat')}else{if(f=='prev'){e.css('background','url('+b.currentImage.attr('src')+') no-repeat')}if(f=='next'){e.css('background','url('+b.currentImage.attr('src')+') no-repeat')}}b.currentSlide++;if(b.currentSlide==b.totalSlides){b.currentSlide=0;a.slideshowEnd.call(this)}if(b.currentSlide<0)b.currentSlide=(b.totalSlides-1);if(c(k[b.currentSlide]).is('img')){b.currentImage=c(k[b.currentSlide])}else{b.currentImage=c(k[b.currentSlide]).find('img:first')}if(a.controlNav){c('.nivo-controlNav a',e).removeClass('active');c('.nivo-controlNav a:eq('+b.currentSlide+')',e).addClass('active')}if(b.currentImage.attr('title')!=''){if(c('.nivo-caption',e).css('display')=='block'){c('.nivo-caption p',e).fadeOut(a.animSpeed,function(){c(this).html(b.currentImage.attr('title'));c(this).fadeIn(a.animSpeed)})}else{c('.nivo-caption p',e).html(b.currentImage.attr('title'))}c('.nivo-caption',e).fadeIn(a.animSpeed)}else{c('.nivo-caption',e).fadeOut(a.animSpeed)}var g=0;c('.nivo-slice',e).each(function(){var d=Math.round(e.width()/a.slices);c(this).css({height:'0px',opacity:'0',background:'url('+b.currentImage.attr('src')+') no-repeat -'+((d+(g*d))-d)+'px 0%'});g++});if(a.effect=='random'){var j=new Array("sliceDownRight","sliceDownLeft","sliceUpRight","sliceUpLeft","sliceUpDown","sliceUpDownLeft","fold","fade");b.randAnim=j[Math.floor(Math.random()*(j.length+1))];if(b.randAnim==undefined)b.randAnim='fade'}if(a.effect.indexOf(',')!=-1){var j=a.effect.split(',');b.randAnim=c.trim(j[Math.floor(Math.random()*j.length)])}b.running=true;if(a.effect=='sliceDown'||a.effect=='sliceDownRight'||b.randAnim=='sliceDownRight'||a.effect=='sliceDownLeft'||b.randAnim=='sliceDownLeft'){var h=0;var g=0;var l=c('.nivo-slice',e);if(a.effect=='sliceDownLeft'||b.randAnim=='sliceDownLeft')l=c('.nivo-slice',e).reverse();l.each(function(){var d=c(this);d.css('top','0px');if(g==a.slices-1){setTimeout(function(){d.animate({height:'100%',opacity:'1.0'},a.animSpeed,'',function(){e.trigger('nivo:animFinished')})},(100+h))}else{setTimeout(function(){d.animate({height:'100%',opacity:'1.0'},a.animSpeed)},(100+h))}h+=50;g++})}else if(a.effect=='sliceUp'||a.effect=='sliceUpRight'||b.randAnim=='sliceUpRight'||a.effect=='sliceUpLeft'||b.randAnim=='sliceUpLeft'){var h=0;var g=0;var l=c('.nivo-slice',e);if(a.effect=='sliceUpLeft'||b.randAnim=='sliceUpLeft')l=c('.nivo-slice',e).reverse();l.each(function(){var d=c(this);d.css('bottom','0px');if(g==a.slices-1){setTimeout(function(){d.animate({height:'100%',opacity:'1.0'},a.animSpeed,'',function(){e.trigger('nivo:animFinished')})},(100+h))}else{setTimeout(function(){d.animate({height:'100%',opacity:'1.0'},a.animSpeed)},(100+h))}h+=50;g++})}else if(a.effect=='sliceUpDown'||a.effect=='sliceUpDownRight'||b.randAnim=='sliceUpDown'||a.effect=='sliceUpDownLeft'||b.randAnim=='sliceUpDownLeft'){var h=0;var g=0;var p=0;var l=c('.nivo-slice',e);if(a.effect=='sliceUpDownLeft'||b.randAnim=='sliceUpDownLeft')l=c('.nivo-slice',e).reverse();l.each(function(){var d=c(this);if(g==0){d.css('top','0px');g++}else{d.css('bottom','0px');g=0}if(p==a.slices-1){setTimeout(function(){d.animate({height:'100%',opacity:'1.0'},a.animSpeed,'',function(){e.trigger('nivo:animFinished')})},(100+h))}else{setTimeout(function(){d.animate({height:'100%',opacity:'1.0'},a.animSpeed)},(100+h))}h+=50;p++})}else if(a.effect=='fold'||b.randAnim=='fold'){var h=0;var g=0;c('.nivo-slice',e).each(function(){var d=c(this);var m=d.width();d.css({top:'0px',height:'100%',width:'0px'});if(g==a.slices-1){setTimeout(function(){d.animate({width:m,opacity:'1.0'},a.animSpeed,'',function(){e.trigger('nivo:animFinished')})},(100+h))}else{setTimeout(function(){d.animate({width:m,opacity:'1.0'},a.animSpeed)},(100+h))}h+=50;g++})}else if(a.effect=='fade'||b.randAnim=='fade'){var g=0;c('.nivo-slice',e).each(function(){c(this).css('height','100%');if(g==a.slices-1){c(this).animate({opacity:'1.0'},(a.animSpeed*2),'',function(){e.trigger('nivo:animFinished')})}else{c(this).animate({opacity:'1.0'},(a.animSpeed*2))}g++})}var o=b.currentImage.height();if(o==0)o=b.currentImage.attr('height');e.height(o)}};c.fn.nivoSlider.defaults={effect:'random',slices:15,animSpeed:500,pauseTime:3000,startSlide:0,directionNav:true,directionNavHide:true,controlNav:true,controlNavThumbs:false,controlNavThumbsFromRel:false,controlNavThumbsSearch:'.jpg',controlNavThumbsReplace:'_0.jpg',keyboardNav:true,pauseOnHover:true,manualAdvance:false,captionOpacity:0.8,beforeChange:function(){},afterChange:function(){},slideshowEnd:function(){}};c.fn.reverse=[].reverse})(jQuery);
