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