/*
 * jQuery Nivo Slider v2.6
 * http://nivo.dev7studios.com
 *
 * Copyright 2011, Gilbert Pellegrom
 * Free to use and abuse under the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * March 2010
 */
(function(e){var s=function(l,o){var f=e.extend({},e.fn.nivoSlider.defaults,o),d={currentSlide:0,currentImage:"",totalSlides:0,randAnim:"",running:!1,paused:!1,stop:!1},g=e(l);g.data("nivo:vars",d);g.css("position","relative");g.addClass("nivoSlider");var j=g.children();j.each(function(){var c=e(this),h="";c.is("img")||(c.is("a")&&(c.addClass("nivo-imageLink"),h=c),c=c.find("img:first"));var b=c.width();0==b&&(b=c.attr("width"));var k=c.height();0==k&&(k=c.attr("height"));b>g.width()&&g.width(b); k>g.height()&&g.height(k);""!=h&&h.css("display","none");c.css("display","none");d.totalSlides++});0<f.startSlide&&(f.startSlide>=d.totalSlides&&(f.startSlide=d.totalSlides-1),d.currentSlide=f.startSlide);d.currentImage=e(j[d.currentSlide]).is("img")?e(j[d.currentSlide]):e(j[d.currentSlide]).find("img:first");e(j[d.currentSlide]).is("a")&&e(j[d.currentSlide]).css("display","block");g.css("background",'url("'+d.currentImage.attr("src")+'") no-repeat');g.append(e('<div class="nivo-caption"><p></p></div>').css({display:"none", opacity:f.captionOpacity}));var t=function(c){var h=e(".nivo-caption",g);if(""!=d.currentImage.attr("title")&&void 0!=d.currentImage.attr("title")){var b=d.currentImage.attr("title");"#"==b.substr(0,1)&&(b=e(b).html());"block"==h.css("display")?h.find("p").fadeOut(c.animSpeed,function(){e(this).html(b);e(this).fadeIn(c.animSpeed)}):h.find("p").html(b);h.fadeIn(c.animSpeed)}else h.fadeOut(c.animSpeed)};t(f);var i=0;!f.manualAdvance&&1<j.length&&(i=setInterval(function(){m(g,j,f,!1)},f.pauseTime)); f.directionNav&&(g.append('<div class="nivo-directionNav"><a class="nivo-prevNav">'+f.prevText+'</a><a class="nivo-nextNav">'+f.nextText+"</a></div>"),f.directionNavHide&&(e(".nivo-directionNav",g).hide(),g.hover(function(){e(".nivo-directionNav",g).show()},function(){e(".nivo-directionNav",g).hide()})),e("a.nivo-prevNav",g).live("click",function(){if(d.running)return!1;clearInterval(i);i="";d.currentSlide-=2;m(g,j,f,"prev")}),e("a.nivo-nextNav",g).live("click",function(){if(d.running)return!1;clearInterval(i); i="";m(g,j,f,"next")}));if(f.controlNav){var r=e('<div class="nivo-controlNav"></div>');g.append(r);for(var n=0;n<j.length;n++)if(f.controlNavThumbs){var p=j.eq(n);p.is("img")||(p=p.find("img:first"));f.controlNavThumbsFromRel?r.append('<a class="nivo-control" rel="'+n+'"><img src="'+p.attr("rel")+'" alt="" /></a>'):r.append('<a class="nivo-control" rel="'+n+'"><img src="'+p.attr("src").replace(f.controlNavThumbsSearch,f.controlNavThumbsReplace)+'" alt="" /></a>')}else r.append('<a class="nivo-control" rel="'+ n+'">'+(n+1)+"</a>");e(".nivo-controlNav a:eq("+d.currentSlide+")",g).addClass("active");e(".nivo-controlNav a",g).live("click",function(){if(d.running||e(this).hasClass("active"))return!1;clearInterval(i);i="";g.css("background",'url("'+d.currentImage.attr("src")+'") no-repeat');d.currentSlide=e(this).attr("rel")-1;m(g,j,f,"control")})}f.keyboardNav&&e(window).keypress(function(c){if("37"==c.keyCode){if(d.running)return!1;clearInterval(i);i="";d.currentSlide-=2;m(g,j,f,"prev")}if("39"==c.keyCode){if(d.running)return!1; clearInterval(i);i="";m(g,j,f,"next")}});f.pauseOnHover&&g.hover(function(){d.paused=!0;clearInterval(i);i=""},function(){d.paused=!1;""==i&&!f.manualAdvance&&(i=setInterval(function(){m(g,j,f,!1)},f.pauseTime))});g.bind("nivo:animFinished",function(){d.running=!1;e(j).each(function(){e(this).is("a")&&e(this).css("display","none")});e(j[d.currentSlide]).is("a")&&e(j[d.currentSlide]).css("display","block");""==i&&!d.paused&&!f.manualAdvance&&(i=setInterval(function(){m(g,j,f,!1)},f.pauseTime));f.afterChange.call(this)}); var q=function(c,h,b){for(var k=0;k<h.slices;k++){var a=Math.round(c.width()/h.slices);k==h.slices-1?c.append(e('<div class="nivo-slice"></div>').css({left:a*k+"px",width:c.width()-a*k+"px",height:"0px",opacity:"0",background:'url("'+b.currentImage.attr("src")+'") no-repeat -'+(a+k*a-a)+"px 0%"})):c.append(e('<div class="nivo-slice"></div>').css({left:a*k+"px",width:a+"px",height:"0px",opacity:"0",background:'url("'+b.currentImage.attr("src")+'") no-repeat -'+(a+k*a-a)+"px 0%"}))}},u=function(c,h, b){for(var k=Math.round(c.width()/h.boxCols),a=Math.round(c.height()/h.boxRows),f=0;f<h.boxRows;f++)for(var d=0;d<h.boxCols;d++)d==h.boxCols-1?c.append(e('<div class="nivo-box"></div>').css({opacity:0,left:k*d+"px",top:a*f+"px",width:c.width()-k*d+"px",height:a+"px",background:'url("'+b.currentImage.attr("src")+'") no-repeat -'+(k+d*k-k)+"px -"+(a+f*a-a)+"px"})):c.append(e('<div class="nivo-box"></div>').css({opacity:0,left:k*d+"px",top:a*f+"px",width:k+"px",height:a+"px",background:'url("'+b.currentImage.attr("src")+ '") no-repeat -'+(k+d*k-k)+"px -"+(a+f*a-a)+"px"}))},m=function(c,h,b,f){var a=c.data("nivo:vars");a&&a.currentSlide==a.totalSlides-1&&b.lastSlide.call(this);if((!a||a.stop)&&!f)return!1;b.beforeChange.call(this);f?("prev"==f&&c.css("background",'url("'+a.currentImage.attr("src")+'") no-repeat'),"next"==f&&c.css("background",'url("'+a.currentImage.attr("src")+'") no-repeat')):c.css("background",'url("'+a.currentImage.attr("src")+'") no-repeat');a.currentSlide++;a.currentSlide==a.totalSlides&&(a.currentSlide= 0,b.slideshowEnd.call(this));0>a.currentSlide&&(a.currentSlide=a.totalSlides-1);a.currentImage=e(h[a.currentSlide]).is("img")?e(h[a.currentSlide]):e(h[a.currentSlide]).find("img:first");b.controlNav&&(e(".nivo-controlNav a",c).removeClass("active"),e(".nivo-controlNav a:eq("+a.currentSlide+")",c).addClass("active"));t(b);e(".nivo-slice",c).remove();e(".nivo-box",c).remove();"random"==b.effect&&(h="sliceDownRight,sliceDownLeft,sliceUpRight,sliceUpLeft,sliceUpDown,sliceUpDownLeft,fold,fade,boxRandom,boxRain,boxRainReverse,boxRainGrow,boxRainGrowReverse".split(","), a.randAnim=h[Math.floor(Math.random()*(h.length+1))],void 0==a.randAnim&&(a.randAnim="fade"));-1!=b.effect.indexOf(",")&&(h=b.effect.split(","),a.randAnim=h[Math.floor(Math.random()*h.length)],void 0==a.randAnim&&(a.randAnim="fade"));a.running=!0;if("sliceDown"==b.effect||"sliceDownRight"==b.effect||"sliceDownRight"==a.randAnim||"sliceDownLeft"==b.effect||"sliceDownLeft"==a.randAnim){q(c,b,a);var d=0,g=0,h=e(".nivo-slice",c);if("sliceDownLeft"==b.effect||"sliceDownLeft"==a.randAnim)h=e(".nivo-slice", c)._reverse();h.each(function(){var a=e(this);a.css({top:"0px"});g==b.slices-1?setTimeout(function(){a.animate({height:"100%",opacity:"1.0"},b.animSpeed,"",function(){c.trigger("nivo:animFinished")})},100+d):setTimeout(function(){a.animate({height:"100%",opacity:"1.0"},b.animSpeed)},100+d);d+=50;g++})}else if("sliceUp"==b.effect||"sliceUpRight"==b.effect||"sliceUpRight"==a.randAnim||"sliceUpLeft"==b.effect||"sliceUpLeft"==a.randAnim){q(c,b,a);g=d=0;h=e(".nivo-slice",c);if("sliceUpLeft"==b.effect|| "sliceUpLeft"==a.randAnim)h=e(".nivo-slice",c)._reverse();h.each(function(){var a=e(this);a.css({bottom:"0px"});g==b.slices-1?setTimeout(function(){a.animate({height:"100%",opacity:"1.0"},b.animSpeed,"",function(){c.trigger("nivo:animFinished")})},100+d):setTimeout(function(){a.animate({height:"100%",opacity:"1.0"},b.animSpeed)},100+d);d+=50;g++})}else if("sliceUpDown"==b.effect||"sliceUpDownRight"==b.effect||"sliceUpDown"==a.randAnim||"sliceUpDownLeft"==b.effect||"sliceUpDownLeft"==a.randAnim){q(c, b,a);var j=g=d=0,h=e(".nivo-slice",c);if("sliceUpDownLeft"==b.effect||"sliceUpDownLeft"==a.randAnim)h=e(".nivo-slice",c)._reverse();h.each(function(){var a=e(this);0==g?(a.css("top","0px"),g++):(a.css("bottom","0px"),g=0);j==b.slices-1?setTimeout(function(){a.animate({height:"100%",opacity:"1.0"},b.animSpeed,"",function(){c.trigger("nivo:animFinished")})},100+d):setTimeout(function(){a.animate({height:"100%",opacity:"1.0"},b.animSpeed)},100+d);d+=50;j++})}else if("fold"==b.effect||"fold"==a.randAnim)q(c, b,a),g=d=0,e(".nivo-slice",c).each(function(){var a=e(this),f=a.width();a.css({top:"0px",height:"100%",width:"0px"});g==b.slices-1?setTimeout(function(){a.animate({width:f,opacity:"1.0"},b.animSpeed,"",function(){c.trigger("nivo:animFinished")})},100+d):setTimeout(function(){a.animate({width:f,opacity:"1.0"},b.animSpeed)},100+d);d+=50;g++});else if("fade"==b.effect||"fade"==a.randAnim){q(c,b,a);var i=e(".nivo-slice:first",c);i.css({height:"100%",width:c.width()+"px"});i.animate({opacity:"1.0"},2* b.animSpeed,"",function(){c.trigger("nivo:animFinished")})}else if("slideInRight"==b.effect||"slideInRight"==a.randAnim)q(c,b,a),i=e(".nivo-slice:first",c),i.css({height:"100%",width:"0px",opacity:"1"}),i.animate({width:c.width()+"px"},2*b.animSpeed,"",function(){c.trigger("nivo:animFinished")});else if("slideInLeft"==b.effect||"slideInLeft"==a.randAnim)q(c,b,a),i=e(".nivo-slice:first",c),i.css({height:"100%",width:"0px",opacity:"1",left:"",right:"0px"}),i.animate({width:c.width()+"px"},2*b.animSpeed, "",function(){i.css({left:"0px",right:""});c.trigger("nivo:animFinished")});else if("boxRandom"==b.effect||"boxRandom"==a.randAnim){u(c,b,a);var m=b.boxCols*b.boxRows,d=g=0,h=s(e(".nivo-box",c));h.each(function(){var a=e(this);g==m-1?setTimeout(function(){a.animate({opacity:"1"},b.animSpeed,"",function(){c.trigger("nivo:animFinished")})},100+d):setTimeout(function(){a.animate({opacity:"1"},b.animSpeed)},100+d);d+=20;g++})}else if("boxRain"==b.effect||"boxRain"==a.randAnim||"boxRainReverse"==b.effect|| "boxRainReverse"==a.randAnim||"boxRainGrow"==b.effect||"boxRainGrow"==a.randAnim||"boxRainGrowReverse"==b.effect||"boxRainGrowReverse"==a.randAnim){u(c,b,a);var m=b.boxCols*b.boxRows,l=d=g=0,n=0,o=[];o[l]=[];h=e(".nivo-box",c);if("boxRainReverse"==b.effect||"boxRainReverse"==a.randAnim||"boxRainGrowReverse"==b.effect||"boxRainGrowReverse"==a.randAnim)h=e(".nivo-box",c)._reverse();h.each(function(){o[l][n]=e(this);n++;n==b.boxCols&&(l++,n=0,o[l]=[])});for(h=0;h<2*b.boxCols;h++){for(var f=h,p=0;p<b.boxRows;p++)0<= f&&f<b.boxCols&&(function(d,f,g,h,k){var i=e(o[d][f]),j=i.width(),l=i.height();("boxRainGrow"==b.effect||"boxRainGrow"==a.randAnim||"boxRainGrowReverse"==b.effect||"boxRainGrowReverse"==a.randAnim)&&i.width(0).height(0);h==k-1?setTimeout(function(){i.animate({opacity:"1",width:j,height:l},b.animSpeed/1.3,"",function(){c.trigger("nivo:animFinished")})},100+g):setTimeout(function(){i.animate({opacity:"1",width:j,height:l},b.animSpeed/1.3)},100+g)}(p,f,d,g,m),g++),f--;d+=100}}},s=function(c){for(var d, b,e=c.length;e;d=parseInt(Math.random()*e),b=c[--e],c[e]=c[d],c[d]=b);return c},v=function(c){this.console&&"undefined"!=typeof console.log&&console.log(c)};this.stop=function(){e(l).data("nivo:vars").stop||(e(l).data("nivo:vars").stop=!0,v("Stop Slider"))};this.start=function(){e(l).data("nivo:vars").stop&&(e(l).data("nivo:vars").stop=!1,v("Start Slider"))};f.afterLoad.call(this);return this};e.fn.nivoSlider=function(l){return this.each(function(){var o=e(this);if(o.data("nivoslider"))return o.data("nivoslider"); var f=new s(this,l);o.data("nivoslider",f)})};e.fn.nivoSlider.defaults={effect:"random",slices:15,boxCols:8,boxRows:4,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:0.8,prevText:"Prev",nextText:"Next",beforeChange:function(){},afterChange:function(){},slideshowEnd:function(){},lastSlide:function(){}, afterLoad:function(){}};e.fn._reverse=[].reverse})(jQuery);
