/*
 * 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.html
 * 
 * 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 false;d.beforeChange.call(this);if(!e){b.css("background","url("+f.currentImage.attr("src")+") no-repeat")}else{if(e=="prev"){b.css("background","url("+f.currentImage.attr("src")+") no-repeat")}if(e=="next"){b.css("background","url("+f.currentImage.attr("src")+") no-repeat")}}f.currentSlide++;if(f.currentSlide==f.totalSlides){f.currentSlide=0;d.slideshowEnd.call(this)}if(f.currentSlide<0)f.currentSlide=f.totalSlides-1;if(a(c[f.currentSlide]).is("img")){f.currentImage=a(c[f.currentSlide])}else{f.currentImage=a(c[f.currentSlide]).find("img:first")}if(d.controlNav){a(".nivo-controlNav a",b).removeClass("active");a(".nivo-controlNav a:eq("+f.currentSlide+")",b).addClass("active")}if(f.currentImage.attr("title")!=""){if(a(".nivo-caption",b).css("display")=="block"){a(".nivo-caption p",b).slideUp(d.animSpeed,function(){a(this).html(f.currentImage.attr("title"));a(this).slideDown(d.animSpeed)});a(".nivo-caption a",b).slideUp(d.animSpeed,function(){a(this).attr("href",f.currentImage.attr("longdesc"));a(this).slideDown(d.animSpeed)})}else{a(".nivo-caption p",b).html(f.currentImage.attr("title"))}a(".nivo-caption",b).slideDown(d.animSpeed)}else{a(".nivo-caption",b).slideUp(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=new Array("sliceDownRight","sliceDownLeft","sliceUpRight","sliceUpLeft","sliceUpDown","sliceUpDownLeft","fold","fade");f.randAnim=h[Math.floor(Math.random()*(h.length+1))];if(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=true;if(d.effect=="sliceDown"||d.effect=="sliceDownRight"||f.randAnim=="sliceDownRight"||d.effect=="sliceDownLeft"||f.randAnim=="sliceDownLeft"){var i=0;var g=0;var 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");if(g==d.slices-1){setTimeout(function(){c.animate({height:"100%",opacity:"1.0"},d.animSpeed,"",function(){b.trigger("nivo:animFinished")})},100+i)}else{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;var g=0;var 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");if(g==d.slices-1){setTimeout(function(){c.animate({height:"100%",opacity:"1.0"},d.animSpeed,"",function(){b.trigger("nivo:animFinished")})},100+i)}else{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;var g=0;var k=0;var 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);if(g==0){c.css("top","0px");g++}else{c.css("bottom","0px");g=0}if(k==d.slices-1){setTimeout(function(){c.animate({height:"100%",opacity:"1.0"},d.animSpeed,"",function(){b.trigger("nivo:animFinished")})},100+i)}else{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;var g=0;a(".nivo-slice",b).each(function(){var c=a(this);var e=c.width();c.css({top:"0px",height:"100%",width:"0px"});if(g==d.slices-1){setTimeout(function(){c.animate({width:e,opacity:"1.0"},d.animSpeed,"",function(){b.trigger("nivo:animFinished")})},100+i)}else{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%");if(g==d.slices-1){a(this).animate({opacity:"1.0"},d.animSpeed*2,"",function(){b.trigger("nivo:animFinished")})}else{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:false,paused:false,stop:false};var 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);var d="";if(!c.is("img")){if(c.is("a")){c.addClass("nivo-imageLink");d=c}c=c.find("img:first")}var f=c.width();if(f==0)f=c.attr("width");var g=c.height();if(g==0)g=c.attr("height");if(f>e.width()){e.width(f)}if(g>e.height()){e.height(g)}if(d!=""){d.css("display","none")}c.css("display","none");b.totalSlides++});if(c.startSlide>0){if(c.startSlide>=b.totalSlides)c.startSlide=b.totalSlides-1;b.currentSlide=c.startSlide}if(a(f[b.currentSlide]).is("img")){b.currentImage=a(f[b.currentSlide])}else{b.currentImage=a(f[b.currentSlide]).find("img:first")}if(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);if(g==c.slices-1){e.append(a('<div class="nivo-slice"></div>').css({left:h*g+"px",width:e.width()-h*g+"px"}))}else{e.append(a('<div class="nivo-slice"></div>').css({left:h*g+"px",width:h+"px"}))}}e.append(a('<div class="nivo-caption text cufon-avenb"><p></p><a href="#" class="attachment-normal-slider wp-post-image continue_button">Learn More</a></div>').css({display:"none",opacity:c.captionOpacity}));if(b.currentImage.attr("title")!=""){a(".nivo-caption p",e).html(b.currentImage.attr("title"));a(".nivo-caption a",e).attr("href",b.currentImage.attr("longdesc"));a(".nivo-caption",e).slideDown(c.animSpeed)}var i=0;if(!c.manualAdvance&&f.length>1){i=setInterval(function(){d(e,f,c,false)},c.pauseTime)}if(c.directionNav){e.append('<div class="nivo-directionNav"><a class="nivo-prevNav">Prev</a><a class="nivo-nextNav">Next</a></div>');if(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 false;clearInterval(i);i="";b.currentSlide-=2;d(e,f,c,"prev")});a("a.nivo-nextNav",e).live("click",function(){if(b.running)return false;clearInterval(i);i="";d(e,f,c,"next")})}if(c.controlNav){var j=a('<div class="nivo-controlNav"></div>');e.append(j);for(var g=0;g<f.length;g++){if(c.controlNavThumbs){var k=f.eq(g);if(!k.is("img")){k=k.find("img:first")}if(c.controlNavThumbsFromRel){j.append('<a class="nivo-control" rel="'+g+'"><img src="'+k.attr("rel")+'" alt="" /></a>')}else{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 false;if(a(this).hasClass("active"))return false;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")})}if(c.keyboardNav){a(window).keypress(function(a){if(a.keyCode=="37"){if(b.running)return false;clearInterval(i);i="";b.currentSlide-=2;d(e,f,c,"prev")}if(a.keyCode=="39"){if(b.running)return false;clearInterval(i);i="";d(e,f,c,"next")}})}if(c.pauseOnHover){e.hover(function(){b.paused=true;clearInterval(i);i=""},function(){b.paused=false;if(i==""&&!c.manualAdvance){i=setInterval(function(){d(e,f,c,false)},c.pauseTime)}})}e.bind("nivo:animFinished",function(){b.running=false;a(f).each(function(){if(a(this).is("a")){a(this).css("display","none")}});if(a(f[b.currentSlide]).is("a")){a(f[b.currentSlide]).css("display","block")}if(i==""&&!b.paused&&!c.manualAdvance){i=setInterval(function(){d(e,f,c,false)},c.pauseTime)}c.afterChange.call(this)})})};a.fn.nivoSlider.defaults={effect:"random",slices:15,animSpeed:500,pauseTime:3e3,startSlide:0,directionNav:true,directionNavHide:true,controlNav:true,controlNavThumbs:false,controlNavThumbsFromRel:false,controlNavThumbsSearch:".jpg",controlNavThumbsReplace:"_thumb.jpg",keyboardNav:true,pauseOnHover:true,manualAdvance:false,captionOpacity:.8,beforeChange:function(){},afterChange:function(){},slideshowEnd:function(){}};a.fn.reverse=[].reverse})(jQuery)
