jQuery.fn.extend({dmxSlidingBillboard:function(a){return this.each(function(){jQuery.extend(this,new jQuery.dmxSlidingBillboard(this,a))})}});jQuery.dmxSlidingBillboard=function(c,e){e=jQuery.extend({},jQuery.dmxSlidingBillboard.defaults,e);var l,r,p,g,t,m;var q=[],n=[];var s=0,j=0;var h=false,z=null;var o=this;var x=jQuery(c);var y=jQuery(e.header,c);var w=jQuery(e.footer,c);var u=jQuery(e.view,c);var b=jQuery(e.sectionNav,e.globalSectionNav?null:c);var k=jQuery(e.pageNav,e.globalPageNav?null:c);jQuery.extend(o,{dmxSlidingBillboard:true,next:function(){var A=a(s);if(!h){if(e.autoNextSection&&q.length>1&&j==n[s]-1){o.nextSection()}else{o.nextPage()}}},prevSection:function(){if(s==0){o.moveToSection(q.length-1)}else{o.moveToSection(s-1)}},nextSection:function(){if(s==q.length-1){o.moveToSection(0)}else{o.moveToSection(s+1)}},moveToSection:function(A){$section=a(A);if($section.length==1){l.stop();if(e.horizontal){l.animate({left:"-"+$section.position().left+"px"},e.scrollDuration,e.scrollEasing,function(){jQuery(e.section,l).not($section).css({top:"0px"});j=0})}else{l.animate({top:"-"+$section.position().top+"px"},e.scrollDuration,e.scrollEasing,function(){j=0})}d($section.attr("id"))}},setSection:function(A){$section=a(A);this.setPage(0);if($section.length==1){l.stop();if(e.horizontal){l.css({left:"-"+$section.position().left+"px"})}else{l.css({top:"-"+$section.position().top+"px"})}d($section.attr("id"))}},prevPage:function(){if(j==0){o.moveToPage(n[s]-1)}else{o.moveToPage(j-1)}},nextPage:function(){if(j==n[s]-1){o.moveToPage(0)}else{o.moveToPage(j+1)}},moveToPage:function(A){var B=a(s);B.stop();if(e.horizontal){B.animate({top:"-"+(A*p)+"px"},e.scrollDuration,e.scrollEasing,function(){})}else{B.animate({left:"-"+(A*r)+"px"},e.scrollDuration,e.scrollEasing,function(){})}j=A;f(j)},setPage:function(A){var B=a(s);B.stop();if(e.horizontal){B.css({top:"-"+(A*p)+"px"})}else{B.css({left:"-"+(A*r)+"px"})}j=A;f(j)},play:function(A){if(e.scrollInterval>0&&z===null){z=setInterval(o.next,A?A:e.scrollInterval)}},stop:function(){if(z!==null){clearInterval(z);z=null}},redraw:function(){u.css("visibility","hidden");r=u.width();p=x.height()-y.outerHeight(true)-w.outerHeight(true);u.height(p);m=e.columns*e.rows;g=r/e.columns;t=p/e.rows;var A=jQuery(e.item,u).eq(0);var C=g;C-=parseInt(A.css("paddingLeft"))|0;C-=parseInt(A.css("paddingRight"))|0;C-=parseInt(A.css("borderLeftWidth"))|0;C-=parseInt(A.css("borderRightWidth"))|0;C-=parseInt(A.css("marginLeft"))|0;C-=parseInt(A.css("marginRight"))|0;C=Math.floor(C);var B=t;B-=parseInt(A.css("paddingTop"))|0;B-=parseInt(A.css("paddingBottom"))|0;B-=parseInt(A.css("borderTopWidth"))|0;B-=parseInt(A.css("borderBottomWidth"))|0;B-=parseInt(A.css("marginTop"))|0;B-=parseInt(A.css("marginBottom"))|0;B=Math.floor(B);jQuery(e.section,l).each(function(D){jQuery(e.item,this).css({display:"block",position:"absolute",width:C+"px",height:B+"px"}).each(function(E){if(e.horizontal){jQuery(this).css({top:Math.floor(Math.floor(E/e.columns)*t)+"px",left:Math.floor((E%e.columns)*g)+"px"})}else{jQuery(this).css({left:Math.floor(Math.floor(E/e.rows)*g)+"px",top:Math.floor((E%e.rows)*t)+"px"})}jQuery(this).hover(function(){if(jQuery(this).attr("onclick")){jQuery(this).addClass("clickable")}jQuery(this).addClass("hover")},function(){jQuery(this).removeClass("hover clickable")})});n[D]=Math.ceil(jQuery(e.item,this).length/m);q[D]="#"+this.id});if(e.horizontal){jQuery(e.section,l).width(r).each(function(D){jQuery(this).css({position:"absolute",left:Math.floor(D*r)+"px"})})}else{jQuery(e.section,l).height(p).each(function(D){$(this).css({position:"absolute",top:Math.floor(D*p)+"px"})})}jQuery("li>img,li>a>img",x).each(function(){$this=jQuery(this);var D=$this.attr("src");$this.attr("src","");$this.one("load",function(){var K=jQuery(this);var Q=K.offsetParent();var M=K.closest(e.item);var E=K.closest("[class*=layout-]");var F=/layout-(\w+)/i.exec(K.closest("[class*=layout-]").attr("class"))[1]||e.layoutStyle;var N,O;if(typeof(e.imageMaxWidth)=="string"){if(e.imageMaxWidth.indexOf("%")>0){N=Q.width()*(parseInt(e.imageMaxWidth)/100)||0}else{N=parseInt(e.imageMaxWidth)||0}}else{N=e.imageMaxWidth}if(typeof(e.imageMaxHeight)=="string"){if(e.imageMaxHeight.indexOf("%")>0){O=Q.height()*(parseInt(e.imageMaxHeight)/100)||0}else{O=parseInt(e.imageMaxHeight)||0}}else{O=e.imageMaxHeight}K.css({width:"",height:""});var P=Q.width();var I=Q.height();var J=parseInt(Q.css("padding-top"))||0;var H,G,L;if(F!="fill"){if((N/O)<(K.width()/K.height())){H=(parseInt(K.css("marginLeft"))||0)+(parseInt(K.css("marginRight"))||0);G=(parseInt(K.css("borderLeftpWidth"))||0)+(parseInt(K.css("borderRightWidth"))||0);L=(parseInt(K.css("paddingLeft"))||0)+(parseInt(K.css("paddingRight"))||0);if(e.imageScaleUp){K.width(Math.min(P-H-G-L,N))}else{K.width(Math.min(P-H-G-L,N,K.width()))}if(F=="left"){K.css({position:"absolute",top:J+((I/2)-(K.outerHeight(true)/2)),left:Q.css("padding-left"),right:"auto"})}else{if(F=="right"){K.css({position:"absolute",top:J+((I/2)-(K.outerHeight(true)/2)),left:"auto",right:Q.css("padding-right")})}else{if(F=="top"){K.css({position:"absolute",top:J,left:(P/2)-(K.outerWidth(true)/2),right:"auto"})}else{if(F=="full"){K.css({position:"absolute",top:(Q.innerHeight()/2)-(K.outerHeight(true)/2),left:(Q.innerWidth()/2)-(K.outerWidth(true)/2),right:"auto"})}}}}}else{H=(parseInt(K.css("marginTop"))||0)+(parseInt(K.css("marginBottom"))||0);G=(parseInt(K.css("borderTopWidth"))||0)+(parseInt(K.css("borderBottomWidth"))||0);L=(parseInt(K.css("paddingTop"))||0)+(parseInt(K.css("paddingBottom"))||0);if(e.imageScaleUp&&F!="top"){K.height(Math.min(I-H-G-L,O))}else{K.height(Math.min(I-H-G-L,O,K.height()))}if(F=="left"){K.css({position:"absolute",top:J+((I/2)-(K.outerHeight(true)/2)),left:Q.css("padding-left"),right:"auto"})}else{if(F=="right"){K.css({position:"absolute",top:J+((I/2)-(K.outerHeight(true)/2)),left:"auto",right:Q.css("padding-right")})}else{if(F=="top"){K.css({position:"absolute",top:J,left:(P/2)-(K.outerWidth(true)/2),right:"auto"})}else{if(F=="full"){K.css({position:"absolute",top:(Q.innerHeight()/2)-(K.outerHeight(true)/2),left:(Q.innerWidth()/2)-(K.outerWidth(true)/2),right:"auto"})}}}}}}if(F=="left"){M.find("h4,p").css({margin:0,marginLeft:K.outerWidth(true)})}else{if(F=="right"){M.find("h4,p").css({margin:0,marginRight:K.outerWidth(true)})}else{if(F=="top"){M.find("h4,p").eq(0).css({margin:0,marginTop:K.outerHeight(true)})}else{if(F=="full"||e.layoutStyle=="fill"){if(F=="fill"){K.css({position:"absolute",top:0,left:0,right:0,bottom:0,width:M.innerWidth()+"px",height:M.innerHeight()+"px",margin:0,padding:0,border:"0px none"})}K=M.find("h4");H=(parseInt(K.css("marginLeft"))||0)+(parseInt(K.css("marginRight"))||0);G=(parseInt(K.css("borderLeftpWidth"))||0)+(parseInt(K.css("borderRightWidth"))||0);L=(parseInt(K.css("paddingLeft"))||0)+(parseInt(K.css("paddingRight"))||0);M.find("h4").addClass("full").css({position:"absolute",width:M.innerWidth()-H-L-G,left:0,top:0,zIndex:1});K=M.find("p");H=(parseInt(K.css("marginLeft"))||0)+(parseInt(K.css("marginRight"))||0);G=(parseInt(K.css("borderLeftpWidth"))||0)+(parseInt(K.css("borderRightWidth"))||0);L=(parseInt(K.css("paddingLeft"))||0)+(parseInt(K.css("paddingRight"))||0);M.find("p").addClass("full").css({position:"absolute",width:M.innerWidth()-H-L-G,left:0,bottom:0,zIndex:1}).hide();M.hover(function(){$("p",this).slideDown("normal")},function(){$("p",this).slideUp("normal")})}}}}});$this.attr("src",D)});u.css("visibility","visible")}});function v(){x.css("visibility","hidden");if(u.css("position")=="static"){u.css({position:"relative"})}u.css({overflow:"hidden"});u.wrapInner(document.createElement("div"));l=u.children().eq(0);l.css({position:"absolute",left:0,top:0});i();o.redraw();if(location.hash&&jQuery.inArray(location.hash,q)>-1){o.setSection(location.hash)}else{o.setSection(0)}b.find("a[href^=#]").click(function(E){o.moveToSection($(this).attr("href"));return false});var B=jQuery(e.navLeft,e.globalNav?null:c);var A=jQuery(e.navRight,e.globalNav?null:c);var D=jQuery(e.navUp,e.globalNav?null:c);var C=jQuery(e.navDown,e.globalNav?null:c);B.hover(function(){jQuery(this).addClass("hover")},function(){jQuery(this).removeClass("hover")}).click(function(E){if(e.horizontal){o.prevSection()}else{o.prevPage()}});A.hover(function(){jQuery(this).addClass("hover")},function(){jQuery(this).removeClass("hover")}).click(function(E){if(e.horizontal){o.nextSection()}else{o.nextPage()}});D.hover(function(){jQuery(this).addClass("hover")},function(){jQuery(this).removeClass("hover")}).click(function(E){if(e.horizontal){o.prevPage()}else{o.prevSection()}});C.hover(function(){jQuery(this).addClass("hover")},function(){jQuery(this).removeClass("hover")}).click(function(E){if(e.horizontal){o.nextPage()}else{o.nextSection()}});if(e.showSideNavOnMouseOver){B.hide();A.hide();D.hide();C.hide()}x.hover(function(){h=true;if(e.showSideNavOnMouseOver){B.fadeIn();A.fadeIn();D.fadeIn();C.fadeIn()}},function(){h=false;if(e.showSideNavOnMouseOver){B.fadeOut();A.fadeOut();D.fadeOut();C.fadeOut()}});if(e.redrawOnWindowResize){$(window).resize(function(){o.redraw()})}if(e.mousewheel&&x.mousewheel){x.mousewheel(function(E,F){if(F>0){if(e.horizontal){o.prevPage()}else{o.prevSection()}}else{if(F<0){if(e.horizontal){o.nextPage()}else{o.nextSection()}}}return false})}if(e.keyboard){$(document).keyup(function(E){switch(E.keyCode){case 37:if(e.horizontal){o.prevSection()}else{o.prevPage()}break;case 38:if(e.horizontal){o.prevPage()}else{o.prevSection()}break;case 39:if(e.horizontal){o.nextSection()}else{o.nextPage()}break;case 40:if(e.horizontal){o.nextPage()}else{o.nextSection()}break}return false})}if(e.autoPlay){o.play()}x.css("visibility","visible")}function a(A){if(typeof A=="number"){A=q[A]}return jQuery(A,c)}function d(A){s=jQuery.inArray("#"+A,q);jQuery("a.selected",b).removeClass("selected");jQuery("a[href=#"+A+"]",b).addClass("selected");i()}function f(A){jQuery("a.selected",k).removeClass("selected");jQuery("a",k).eq(A).addClass("selected")}function i(){k.empty();if(n[s]>1){for(var B=0;B<n[s];++B){var A=jQuery('<a href="#'+B+'"></a>').data("index",B).text(B+1);A.click(function(){o.moveToPage(jQuery(this).data("index"));return false});k.append(A).append(" ")}}else{k.append('<a href="javascript:void();" style="visibility:hidden;"> </a>')}k.append('<div style="clear:both;"></div>');f(0)}v()};jQuery.dmxSlidingBillboard.defaults={header:".dmxBillboardHeader",view:".dmxBillboardView",footer:".dmxBillboardFooter",section:"ul",item:"li",sectionNav:".dmxBillboardSectionNav",globalSectionNav:false,pageNav:".dmxBillboardPageNav",globalPageNav:false,navLeft:".dmxBillboardLeftNav",navRight:".dmxBillboardRightNav",navUp:".dmxBillboardUpNav",navDown:".dmxBillboardDownNav",globalNav:false,horizontal:true,columns:2,rows:1,scrollInterval:5000,scrollDuration:"normal",scrollEasing:"swing",autoPlay:true,autoNextSection:true,redrawOnWindowResize:false,showSideNavOnMouseOver:false,keyboard:false,mousewheel:false,layoutStyle:"left",imageScaleUp:false,imageMaxWidth:"100%",imageMaxHeight:"100%"};
