/*
 * jQuery Nivo Slider v2.4
 * 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
 * 
 * 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)

 * @rev     	30/03/2011
 * @author		Igino Fucci
 * @copyright	Copyright (c) 2011 (Keepthinking Ltd.)
 * @link		http://keepthinking.it
 */

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