/*
 * 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(a){a.fn.nivoSlider=function(b){function d(b,c,d,e){var f=b.data("nivo:vars");if((!f||f.stop)&&!e)return!1;d.beforeChange.call(this),e?(e=="prev"&&b.css("background","url("+f.currentImage.attr("src")+") no-repeat"),e=="next"&&b.css("background","url("+f.currentImage.attr("src")+") no-repeat")):b.css("background","url("+f.currentImage.attr("src")+") no-repeat"),f.currentSlide++,f.currentSlide==f.totalSlides&&(f.currentSlide=0,d.slideshowEnd.call(this)),f.currentSlide<0&&(f.currentSlide=f.totalSlides-1),a(c[f.currentSlide]).is("img")?f.currentImage=a(c[f.currentSlide]):f.currentImage=a(c[f.currentSlide]).find("img:first"),d.controlNav&&(a(".nivo-controlNav a",b).removeClass("active"),a(".nivo-controlNav a:eq("+f.currentSlide+")",b).addClass("active")),f.currentImage.attr("title")!=""?(a(".nivo-caption",b).css("display")=="block"?a(".nivo-caption p",b).fadeOut(d.animSpeed,function(){a(this).html(f.currentImage.attr("title")),a(this).fadeIn(d.animSpeed)}):a(".nivo-caption p",b).html(f.currentImage.attr("title")),a(".nivo-caption",b).fadeIn(d.animSpeed)):a(".nivo-caption",b).fadeOut(d.animSpeed);var g=0;a(".nivo-slice",b).each(function(){var c=Math.round(b.width()/d.slices);a(this).css({height:"0px",opacity:"0",background:"url("+f.currentImage.attr("src")+") no-repeat -"+(c+g*c-c)+"px 0%"}),g++});if(d.effect=="random"){var h=["sliceDownRight","sliceDownLeft","sliceUpRight","sliceUpLeft","sliceUpDown","sliceUpDownLeft","fold","fade"];f.randAnim=h[Math.floor(Math.random()*(h.length+1))],f.randAnim==undefined&&(f.randAnim="fade")}if(d.effect.indexOf(",")!=-1){var h=d.effect.split(",");f.randAnim=a.trim(h[Math.floor(Math.random()*h.length)])}f.running=!0;if(d.effect=="sliceDown"||d.effect=="sliceDownRight"||f.randAnim=="sliceDownRight"||d.effect=="sliceDownLeft"||f.randAnim=="sliceDownLeft"){var i=0,g=0,j=a(".nivo-slice",b);if(d.effect=="sliceDownLeft"||f.randAnim=="sliceDownLeft")j=a(".nivo-slice",b).reverse();j.each(function(){var c=a(this);c.css("top","0px"),g==d.slices-1?setTimeout(function(){c.animate({height:"100%",opacity:"1.0"},d.animSpeed,"",function(){b.trigger("nivo:animFinished")})},100+i):setTimeout(function(){c.animate({height:"100%",opacity:"1.0"},d.animSpeed)},100+i),i+=50,g++})}else if(d.effect=="sliceUp"||d.effect=="sliceUpRight"||f.randAnim=="sliceUpRight"||d.effect=="sliceUpLeft"||f.randAnim=="sliceUpLeft"){var i=0,g=0,j=a(".nivo-slice",b);if(d.effect=="sliceUpLeft"||f.randAnim=="sliceUpLeft")j=a(".nivo-slice",b).reverse();j.each(function(){var c=a(this);c.css("bottom","0px"),g==d.slices-1?setTimeout(function(){c.animate({height:"100%",opacity:"1.0"},d.animSpeed,"",function(){b.trigger("nivo:animFinished")})},100+i):setTimeout(function(){c.animate({height:"100%",opacity:"1.0"},d.animSpeed)},100+i),i+=50,g++})}else if(d.effect=="sliceUpDown"||d.effect=="sliceUpDownRight"||f.randAnim=="sliceUpDown"||d.effect=="sliceUpDownLeft"||f.randAnim=="sliceUpDownLeft"){var i=0,g=0,k=0,j=a(".nivo-slice",b);if(d.effect=="sliceUpDownLeft"||f.randAnim=="sliceUpDownLeft")j=a(".nivo-slice",b).reverse();j.each(function(){var c=a(this);g==0?(c.css("top","0px"),g++):(c.css("bottom","0px"),g=0),k==d.slices-1?setTimeout(function(){c.animate({height:"100%",opacity:"1.0"},d.animSpeed,"",function(){b.trigger("nivo:animFinished")})},100+i):setTimeout(function(){c.animate({height:"100%",opacity:"1.0"},d.animSpeed)},100+i),i+=50,k++})}else if(d.effect=="fold"||f.randAnim=="fold"){var i=0,g=0;a(".nivo-slice",b).each(function(){var c=a(this),e=c.width();c.css({top:"0px",height:"100%",width:"0px"}),g==d.slices-1?setTimeout(function(){c.animate({width:e,opacity:"1.0"},d.animSpeed,"",function(){b.trigger("nivo:animFinished")})},100+i):setTimeout(function(){c.animate({width:e,opacity:"1.0"},d.animSpeed)},100+i),i+=50,g++})}else if(d.effect=="fade"||f.randAnim=="fade"){var g=0;a(".nivo-slice",b).each(function(){a(this).css("height","100%"),g==d.slices-1?a(this).animate({opacity:"1.0"},d.animSpeed*2,"",function(){b.trigger("nivo:animFinished")}):a(this).animate({opacity:"1.0"},d.animSpeed*2),g++})}}var c=a.extend({},a.fn.nivoSlider.defaults,b);return this.each(function(){var b={currentSlide:0,currentImage:"",totalSlides:0,randAnim:"",running:!1,paused:!1,stop:!1},e=a(this);e.data("nivo:vars",b),e.css("position","relative"),e.addClass("nivoSlider");var f=e.children();f.each(function(){var c=a(this),d="";c.is("img")||(c.is("a")&&(c.addClass("nivo-imageLink"),d=c),c=c.find("img:first"));var f=c.width();f==0&&(f=c.attr("width"));var g=c.height();g==0&&(g=c.attr("height")),f>e.width()&&e.width(f),g>e.height()&&e.height(g),d!=""&&d.css("display","none"),c.css("display","none"),b.totalSlides++}),c.startSlide>0&&(c.startSlide>=b.totalSlides&&(c.startSlide=b.totalSlides-1),b.currentSlide=c.startSlide),a(f[b.currentSlide]).is("img")?b.currentImage=a(f[b.currentSlide]):b.currentImage=a(f[b.currentSlide]).find("img:first"),a(f[b.currentSlide]).is("a")&&a(f[b.currentSlide]).css("display","block"),e.css("background","url("+b.currentImage.attr("src")+") no-repeat");for(var g=0;g<c.slices;g++){var h=Math.round(e.width()/c.slices);g==c.slices-1?e.append(a('<div class="nivo-slice"></div>').css({left:h*g+"px",width:e.width()-h*g+"px"})):e.append(a('<div class="nivo-slice"></div>').css({left:h*g+"px",width:h+"px"}))}e.append(a('<div class="nivo-caption"><p></p></div>').css({display:"none",opacity:c.captionOpacity})),b.currentImage.attr("title")!=""&&(a(".nivo-caption p",e).html(b.currentImage.attr("title")),a(".nivo-caption",e).fadeIn(c.animSpeed));var i=0;!c.manualAdvance&&f.length>1&&(i=setInterval(function(){d(e,f,c,!1)},c.pauseTime)),c.directionNav&&(e.append('<div class="nivo-directionNav"><a class="nivo-prevNav">Prev</a><a class="nivo-nextNav">Next</a></div>'),c.directionNavHide&&(a(".nivo-directionNav",e).hide(),e.hover(function(){a(".nivo-directionNav",e).show()},function(){a(".nivo-directionNav",e).hide()})),a("a.nivo-prevNav",e).live("click",function(){if(b.running)return!1;clearInterval(i),i="",b.currentSlide-=2,d(e,f,c,"prev")}),a("a.nivo-nextNav",e).live("click",function(){if(b.running)return!1;clearInterval(i),i="",d(e,f,c,"next")}));if(c.controlNav){var j=a('<div class="nivo-controlNav1"></div>');e.append(j);for(var g=0;g<f.length;g++)if(c.controlNavThumbs){var k=f.eq(g);k.is("img")||(k=k.find("img:first")),c.controlNavThumbsFromRel?j.append('<a class="nivo-control" rel="'+g+'"><img src="'+k.attr("rel")+'" alt="" /></a>'):j.append('<a class="nivo-control" rel="'+g+'"><img src="'+k.attr("src").replace(c.controlNavThumbsSearch,c.controlNavThumbsReplace)+'" alt="" /></a>')}else j.append('<a class="nivo-control" rel="'+g+'">'+g+"</a>");a(".nivo-controlNav a:eq("+b.currentSlide+")",e).addClass("active"),a(".nivo-controlNav a",e).live("click",function(){if(b.running)return!1;if(a(this).hasClass("active"))return!1;clearInterval(i),i="",e.css("background","url("+b.currentImage.attr("src")+") no-repeat"),b.currentSlide=a(this).attr("rel")-1,d(e,f,c,"control")})}c.keyboardNav&&a(window).keypress(function(a){if(a.keyCode=="37"){if(b.running)return!1;clearInterval(i),i="",b.currentSlide-=2,d(e,f,c,"prev")}if(a.keyCode=="39"){if(b.running)return!1;clearInterval(i),i="",d(e,f,c,"next")}}),c.pauseOnHover&&e.hover(function(){b.paused=!0,clearInterval(i),i=""},function(){b.paused=!1,i==""&&!c.manualAdvance&&(i=setInterval(function(){d(e,f,c,!1)},c.pauseTime))}),e.bind("nivo:animFinished",function(){b.running=!1,a(f).each(function(){a(this).is("a")&&a(this).css("display","none")}),a(f[b.currentSlide]).is("a")&&a(f[b.currentSlide]).css("display","block"),i==""&&!b.paused&&!c.manualAdvance&&(i=setInterval(function(){d(e,f,c,!1)},c.pauseTime)),c.afterChange.call(this)})})},a.fn.nivoSlider.defaults={effect:"random",slices:15,animSpeed:500,pauseTime:3e3,startSlide:0,directionNav:!0,directionNavHide:!0,controlNav:!0,controlNavThumbs:!1,controlNavThumbsFromRel:!1,controlNavThumbsSearch:".jpg",controlNavThumbsReplace:"_thumb.jpg",keyboardNav:!0,pauseOnHover:!0,manualAdvance:!1,captionOpacity:.8,beforeChange:function(){},afterChange:function(){},slideshowEnd:function(){}},a.fn.reverse=[].reverse})(jQuery)

