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