// jquery Billboard v0.2
// 2011-05-29, jens scherbl
// webninjas.net

(function(b){var a={init:function(c){return this.each(function(){var d=b(this);var f=d.children();var g=b(c.nav).children();var e={effect:"show",random:false,speed:800,delay:4000};if(c){b.extend(e,c);}if(f.length>1){e.index=e.random?Math.floor(Math.random()*f.length):0;f.hide();f.eq(e.index).show();if(g){g.each(function(){b(this).removeClass("active");});g.eq(e.index).addClass("active");}e.timeout=setTimeout(function(){d.billboard("next");},e.delay);d.data("billboard",e);d.mouseover(function(){var h=b(this).data("billboard");clearTimeout(h.timeout);});d.mouseout(function(){var h=b(this);var i=h.data("billboard");i.timeout=setTimeout(function(){h.billboard("next");},i.delay);h.data("billboard",i);});}});},next:function(){return this.each(function(){var c=b(this);var f=c.children();var e=c.data("billboard");var h=b(e.nav).children();var g=e.index;var d;clearTimeout(e.timeout);if(f.length>1){if(e.random){do{d=Math.floor(Math.random()*f.length);}while(d==g);}else{d=g+1<f.length?g+1:0;}e.index=d;c.data("billboard",e);if(h){h.each(function(){b(this).removeClass("active");});h.eq(d).addClass("active");}c.billboard(e.effect,g,d,function(){e.timeout=setTimeout(function(){c.billboard("next");},e.delay);c.data("billboard",e);});}});},prev:function(){return this.each(function(){var c=b(this);var g=c.children();var f=c.data("billboard");var i=b(f.nav).children();var h=f.index;var e;var d;clearTimeout(f.timeout);if(g.length>1){d=h-1>=0?h-1:g.length-1;f.index=d;c.data("billboard",f);if(i){i.each(function(){b(this).removeClass("active");});i.eq(d).addClass("active");}switch(f.effect){case"up":e="down";break;case"down":e="up";break;case"left":e="right";break;case"right":e="left";break;default:e=f.effect;break;}c.billboard(e,h,d,function(){f.timeout=setTimeout(function(){c.billboard("next");},f.delay);c.data("billboard",f);});}});},stop:function(c){return this.each(function(){var d=b(this);var f=d.children();var e=d.data("billboard");var h=b(e.nav).children();var g=e.index;c=c-1;clearTimeout(e.timeout);if(f.length>1&&c<f.length&&c!=g){e.index=c;d.data("billboard",e);if(h){h.each(function(){b(this).removeClass("active");});h.eq(c).addClass("active");}d.billboard(e.effect,g,c);}});},show:function(d,c,e){return this.each(function(){var f=b(this);var g=f.children();g.eq(d).hide();g.eq(c).show();if(e){e();}});},fade:function(d,c,e){return this.each(function(){var f=b(this);var h=f.children();var g=f.data("billboard");h.eq(d).fadeOut(g.speed);h.eq(c).fadeIn(g.speed,e);});},up:function(d,c,e){return this.each(function(){var g=b(this);var i=g.children();var h=g.data("billboard");var f=g.height();i.eq(d).stop().css({top:"0px"}).animate({top:"-"+f+"px"},h.speed);i.eq(c).stop().css({top:f+"px"}).show().animate({top:"0px"},h.speed,e);});},down:function(d,c,e){return this.each(function(){var g=b(this);var i=g.children();var h=g.data("billboard");var f=g.height();i.eq(d).stop().css({top:"0px"}).animate({top:f+"px"},h.speed);i.eq(c).stop().css({top:"-"+f+"px"}).show().animate({top:"0px"},h.speed,e);});},left:function(d,c,e){return this.each(function(){var f=b(this);var i=f.children();var h=f.data("billboard");var g=f.width();i.eq(d).stop().css({left:"0px"}).animate({left:"-"+g+"px"},h.speed);i.eq(c).stop().css({left:g+"px"}).show().animate({left:"0px"},h.speed,e);});},right:function(d,c,e){return this.each(function(){var f=b(this);var i=f.children();var h=f.data("billboard");var g=f.width();i.eq(d).stop().css({left:"0px"}).animate({left:g+"px"},h.speed);i.eq(c).stop().css({left:"-"+g+"px"}).show().animate({left:"0px"},h.speed,e);});}};b.fn.billboard=function(c){if(a[c]){return a[c].apply(this,Array.prototype.slice.call(arguments,1));}else{if(typeof c==="object"||!c){return a.init.apply(this,arguments);}else{b.error("Method "+c+" does not exist on jQuery.billboard");}}};})(jQuery);
