(function($){ $(document).ready(function(){ $("#hbanner .hbcontent img").each(function(index){ if($(this).attr("src").replace(/^\s*|\s*$/g,"") == "/site/home-banners/"){ $($(this).parents("li")[0]).remove(); $("#hbbtns li:last-child").remove(); } }); //BannerHandler class: function BannerHandler(init_banner,interval){ id_timeout = null; this.current_banner = init_banner || 0; this.time_interval = interval || 7000; this.banners = $("#hbanner .hbcontent li").length; this.changeBanner(this.current_banner); } /* * Changes the displayed banner to the one specified in int_banner_number * and the corresponding button status. */ BannerHandler.prototype.changeBanner = function(int_banner_number){ this.current_banner = int_banner_number; $("#hbbtns li").removeClass("active"); $($("#hbbtns li").get(int_banner_number)).addClass("active"); $("#hbanner .hbcontent li.active").removeClass("active").css("zIndex",1); $($("#hbanner .hbcontent li").get(int_banner_number)).addClass("active").css("zIndex",2).fadeTo(1200, 1, function(){ $('#hbanner .hbcontent li:not(.active)').fadeTo(0, 0); }); } /* * next() function * * Displays the next banner, or the first one if the last banner is already being displayed. */ BannerHandler.prototype.next = function(){ this.changeBanner((this.current_banner == this.banners - 1)? 0 : this.current_banner + 1); } /* * prev() function * * Displays the previous banner, or the last one if the first banner is already being displayed. */ BannerHandler.prototype.prev = function(){ this.changeBanner((this.current_banner == 0)? this.banners - 1 : this.current_banner - 1); } BannerHandler.prototype.play = function(){ clearInterval(id_timeout); _banner = this; function chgBanner(){ _banner.next() } id_timeout = setInterval(chgBanner,this.time_interval); } BannerHandler.prototype.stop = function(){ clearInterval(id_timeout); } //Banner initialization: if($("#hbbtns li").length > 1){ var banner = new BannerHandler(0,7000); //Click handler for right buttons $("#hbbtns li").each(function(i){ $(this).attr("id",i + "-banner-button") $(this).click(function(){ var button_index = parseInt($(this).attr("id")); banner.stop(); banner.changeBanner(button_index); banner.play(); }); }); banner.play(); }else{ $("#hbbtns").remove(); } }); })(jQuery)