/*!
 * 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(e){var f=a.extend({},a.fn.nivoSlider.defaults,e);var g=false;var b="";this.each(function(){b+="#"+this.id+" a {display: block;}"});a("style","head").each(function(){if(a(this).text().match(/\.nivoSlider/i)){g=true;a(this).append(b);return false}});if(!g){var d=".nivoSlider{position:relative;}.nivoSlider img{position:absolute;top:0;left:0;}.nivoSlider a.nivo-imageLink{position:absolute;top:0;left:0;width:100%;height:100%;border:0;padding:0;margin:0;z-index:60;display:none;}.nivo-slice{display:block;position:absolute;z-index:50;height:100%;}.nivo-caption{position:absolute;left:0;bottom:0;background:#000;color:#fff;opacity:0.8;width:100%;z-index:89;}.nivo-caption p {padding:5px;margin:0;}";a('<style type="text/css">'+d+b+"</style>").appendTo("head")}return this.each(function(){var q={currentSlide:0,currentImage:"",totalSlides:0,randAnim:"",running:false,paused:false,stop:false};var k=a(this);k.data("nivo:vars",q);k.css("position","relative");k.addClass("nivoSlider");var l=k.children();l.each(function(){var u=a(this);var t="";if(!u.is("img")){if(u.is("a")){u.addClass("nivo-imageLink");t=u}u=u.find("img:first")}var s=u.width();if(s==0){s=u.attr("width")}var i=u.height();if(i==0){i=u.attr("height")}if(s>k.width()){k.width(s)}if(i>k.height()){k.height(i)}if(t!=""){t.css("display","none")}u.css("display","none");q.totalSlides++});if(f.startSlide>0){if(f.startSlide>=q.totalSlides){f.startSlide=q.totalSlides-1}q.currentSlide=f.startSlide}if(a(l[q.currentSlide]).is("img")){q.currentImage=a(l[q.currentSlide])}else{q.currentImage=a(l[q.currentSlide]).find("img:first")}if(a(l[q.currentSlide]).is("a")){a(l[q.currentSlide]).css("display","block")}k.css("background","url("+encodeURI(q.currentImage.attr("src"))+") no-repeat");for(var o=0;o<f.slices;o++){var r=Math.round(k.width()/f.slices);if(o==f.slices-1){k.append(a('<div class="nivo-slice"></div>').css({left:(r*o)+"px",width:(k.width()-(r*o))+"px"}))}else{k.append(a('<div class="nivo-slice"></div>').css({left:(r*o)+"px",width:r+"px"}))}}k.append(a('<div class="nivo-caption"><p></p></div>').css({display:"none",opacity:f.captionOpacity,"font-family":f.captionFontFamily,"font-size":f.captionFontSize,color:f.captionTextColor,"background-color":f.captionBackground,"line-height":"100%"}));a(".nivo-caption p",k).css("padding",f.captionPadding);if(f.showCaption&&q.currentImage.attr("alt")!=""){a(".nivo-caption p",k).html(q.currentImage.attr("alt"));a(".nivo-caption",k).fadeIn(f.animSpeed)}var j=0;if(!f.manualAdvance&&l.length>1){j=setInterval(function(){c(k,l,f,false)},f.pauseTime)}if(f.directionNav){var n=a("#"+f.prevId).css("cursor","pointer");var h=a("#"+f.nextId).css("cursor","pointer");n.live("click",function(){if(q.running){return false}clearInterval(j);j="";q.currentSlide-=2;c(k,l,f,"prev")});h.live("click",function(){if(q.running){return false}clearInterval(j);j="";c(k,l,f,"next")})}if(f.controlNav){var p=a('<div class="nivo-controlNav"></div>');k.append(p);for(var o=0;o<l.length;o++){if(f.controlNavThumbs){var m=l.eq(o);if(!m.is("img")){m=m.find("img:first")}if(f.controlNavThumbsFromRel){p.append('<a class="nivo-control" rel="'+o+'"><img src="'+m.attr("rel")+'" alt="" /></a>')}else{p.append('<a class="nivo-control" rel="'+o+'"><img src="'+m.attr("src").replace(f.controlNavThumbsSearch,f.controlNavThumbsReplace)+'" alt="" /></a>')}}else{p.append('<a class="nivo-control" rel="'+o+'">'+o+"</a>")}}a(".nivo-controlNav a:eq("+q.currentSlide+")",k).addClass("active");a(".nivo-controlNav a",k).live("click",function(){if(q.running){return false}if(a(this).hasClass("active")){return false}clearInterval(j);j="";k.css("background","url("+encodeURI(q.currentImage.attr("src"))+") no-repeat");q.currentSlide=a(this).attr("rel")-1;c(k,l,f,"control")})}if(f.keyboardNav){a(window).keypress(function(i){if(i.keyCode=="37"){if(q.running){return false}clearInterval(j);j="";q.currentSlide-=2;c(k,l,f,"prev")}if(i.keyCode=="39"){if(q.running){return false}clearInterval(j);j="";c(k,l,f,"next")}})}if(f.pauseOnHover){k.hover(function(){q.paused=true;clearInterval(j);j=""},function(){q.paused=false;if(j==""&&!f.manualAdvance){j=setInterval(function(){c(k,l,f,false)},f.pauseTime)}})}k.bind("nivo:animFinished",function(){q.running=false;a(l).each(function(){if(a(this).is("a")){a(this).css("display","none")}});if(a(l[q.currentSlide]).is("a")){a(l[q.currentSlide]).css("display","block")}if(j==""&&!q.paused&&!f.manualAdvance){j=setInterval(function(){c(k,l,f,false)},f.pauseTime)}f.afterChange.call(this)})});function c(h,j,l,n){var o=h.data("nivo:vars");if((!o||o.stop)&&!n){return false}l.beforeChange.call(this);if(!n){h.css("background","url("+encodeURI(o.currentImage.attr("src"))+") no-repeat")}else{if(n=="prev"){h.css("background","url("+encodeURI(o.currentImage.attr("src"))+") no-repeat")}if(n=="next"){h.css("background","url("+encodeURI(o.currentImage.attr("src"))+") no-repeat")}}o.currentSlide++;if(o.currentSlide==o.totalSlides){o.currentSlide=0;l.slideshowEnd.call(this)}if(o.currentSlide<0){o.currentSlide=(o.totalSlides-1)}if(a(j[o.currentSlide]).is("img")){o.currentImage=a(j[o.currentSlide])}else{o.currentImage=a(j[o.currentSlide]).find("img:first")}if(l.controlNav){a(".nivo-controlNav a",h).removeClass("active");a(".nivo-controlNav a:eq("+o.currentSlide+")",h).addClass("active")}if(l.showCaption&&o.currentImage.attr("alt")!=""){if(a(".nivo-caption",h).css("display")=="block"){a(".nivo-caption p",h).fadeOut(l.animSpeed,function(){a(this).html(o.currentImage.attr("alt"));a(this).fadeIn(l.animSpeed)})}else{a(".nivo-caption p",h).html(o.currentImage.attr("alt"))}a(".nivo-caption",h).fadeIn(l.animSpeed)}else{a(".nivo-caption",h).fadeOut(l.animSpeed)}var m=0;a(".nivo-slice",h).each(function(){var i=Math.round(h.width()/l.slices);a(this).css({height:"0px",opacity:"0",background:"url("+encodeURI(o.currentImage.attr("src"))+") no-repeat -"+((i+(m*i))-i)+"px 0%"});m++});if(l.effect=="random"){var p=new Array("sliceDownRight","sliceDownLeft","sliceUpRight","sliceUpLeft","sliceUpDown","sliceUpDownLeft","fold","fade");o.randAnim=p[Math.floor(Math.random()*(p.length+1))];if(o.randAnim==undefined){o.randAnim="fade"}}if(l.effect.indexOf(",")!=-1){var p=l.effect.split(",");o.randAnim=a.trim(p[Math.floor(Math.random()*p.length)])}o.running=true;if(l.effect=="sliceDown"||l.effect=="sliceDownRight"||o.randAnim=="sliceDownRight"||l.effect=="sliceDownLeft"||o.randAnim=="sliceDownLeft"){var k=0;var m=0;var r=a(".nivo-slice",h);if(l.effect=="sliceDownLeft"||o.randAnim=="sliceDownLeft"){r=a(".nivo-slice",h).reverse()}r.each(function(){var i=a(this);i.css("top","0px");if(m==l.slices-1){setTimeout(function(){i.animate({height:"100%",opacity:"1.0"},l.animSpeed,"",function(){h.trigger("nivo:animFinished")})},(100+k))}else{setTimeout(function(){i.animate({height:"100%",opacity:"1.0"},l.animSpeed)},(100+k))}k+=50;m++})}else{if(l.effect=="sliceUp"||l.effect=="sliceUpRight"||o.randAnim=="sliceUpRight"||l.effect=="sliceUpLeft"||o.randAnim=="sliceUpLeft"){var k=0;var m=0;var r=a(".nivo-slice",h);if(l.effect=="sliceUpLeft"||o.randAnim=="sliceUpLeft"){r=a(".nivo-slice",h).reverse()}r.each(function(){var i=a(this);i.css("bottom","0px");if(m==l.slices-1){setTimeout(function(){i.animate({height:"100%",opacity:"1.0"},l.animSpeed,"",function(){h.trigger("nivo:animFinished")})},(100+k))}else{setTimeout(function(){i.animate({height:"100%",opacity:"1.0"},l.animSpeed)},(100+k))}k+=50;m++})}else{if(l.effect=="sliceUpDown"||l.effect=="sliceUpDownRight"||o.randAnim=="sliceUpDown"||l.effect=="sliceUpDownLeft"||o.randAnim=="sliceUpDownLeft"){var k=0;var m=0;var q=0;var r=a(".nivo-slice",h);if(l.effect=="sliceUpDownLeft"||o.randAnim=="sliceUpDownLeft"){r=a(".nivo-slice",h).reverse()}r.each(function(){var i=a(this);if(m==0){i.css("top","0px");m++}else{i.css("bottom","0px");m=0}if(q==l.slices-1){setTimeout(function(){i.animate({height:"100%",opacity:"1.0"},l.animSpeed,"",function(){h.trigger("nivo:animFinished")})},(100+k))}else{setTimeout(function(){i.animate({height:"100%",opacity:"1.0"},l.animSpeed)},(100+k))}k+=50;q++})}else{if(l.effect=="fold"||o.randAnim=="fold"){var k=0;var m=0;a(".nivo-slice",h).each(function(){var i=a(this);var s=i.width();i.css({top:"0px",height:"100%",width:"0px"});if(m==l.slices-1){setTimeout(function(){i.animate({width:s,opacity:"1.0"},l.animSpeed,"",function(){h.trigger("nivo:animFinished")})},(100+k))}else{setTimeout(function(){i.animate({width:s,opacity:"1.0"},l.animSpeed)},(100+k))}k+=50;m++})}else{if(l.effect=="fade"||o.randAnim=="fade"){var m=0;a(".nivo-slice",h).each(function(){a(this).css("height","100%");if(m==l.slices-1){a(this).animate({opacity:"1.0"},(l.animSpeed*2),"",function(){h.trigger("nivo:animFinished")})}else{a(this).animate({opacity:"1.0"},(l.animSpeed*2))}m++})}}}}}}};a.fn.nivoSlider.defaults={effect:"random",slices:15,animSpeed:500,pauseTime:3000,startSlide:0,directionNav:true,directionNavHide:true,controlNav:false,controlNavThumbs:false,controlNavThumbsFromRel:false,controlNavThumbsSearch:".jpg",controlNavThumbsReplace:"_thumb.jpg",keyboardNav:true,pauseOnHover:true,manualAdvance:false,showCaption:false,captionFontFamily:"",captionFontSize:"",captionBackground:"#000",captionTextColor:"#fff",captionOpacity:0.8,captionPadding:"5px",beforeChange:function(){},afterChange:function(){},slideshowEnd:function(){}};a.fn.reverse=[].reverse})(jQuery);
