ROLLING.main = { //Default. _imgOW:1600, _imgOH:720, _initBool:false, _aniBool:false, _resizeBool:false, _timer:0, _time:6000, //Initialize. init:function(){ this.layout(); this.reset(); this.resetInit(); this.resizeInit(); }, layout:function(){ this.$thumb = $('#blog_column').find('.thumb'); this.$thumbImg = this.$thumb.find('img'); this.$banner = $('#banner'); this.$bannerWrap = this.$banner.find('.banner_wrap'); this.$bannerContainer = this.$bannerWrap.find('.banner_container'); this.$bannerItem = this.$bannerContainer.find('.banner_item'); this.$bannerImg = this.$bannerItem.find('.banner_img'); this.$bannerImgEl = this.$bannerImg.find('img'); this.bannerMax = this.$bannerItem.length; this.$bannerNav = this.$banner.find('.banner_nav'); this.$bannerNavEl = this.$bannerNav.find('a'); this.$bannerNavAnchor = this.$bannerNav.find('.nav_anchor'); }, //Event. reset:function(){ var h = ROLLING.main; setTimeout(function(){ h.thumbResize(); }, 300); this.bannerCurNum = 0; this.bannerExNum = this.bannerCurNum; }, resetInit:function(){ if(this.bannerMax > 1){ this.$bannerNavEl.bind('click', this.onNav); } }, removeInit:function(){ }, //Event Function. onNav:function(e){ e.preventDefault(); var h = ROLLING.main, id = parseInt(h.$bannerNavEl.index(this), 10); if(h._aniBool) return; if(!h._aniBool){ if(h.bannerExNum != id){ clearInterval(h._timer); h.bannerCurNum = id; h.slideMove(); } } }, //Control. slideMove:function(b){ var h = ROLLING.main, bool = (b)? b:false, d; h._aniBool = true; if(!bool){ d = (Math.abs(h.bannerCurNum - h.bannerExNum)*180 + 350)*0.001; h.anchorMove(d); TweenLite.to(h.$bannerContainer, d, {css:{left:h._bannerW*h.bannerCurNum*-1}, ease:Quad.easeInOut, onComplete:function(){ h.$bannerNavEl.removeClass('select'); h.$bannerNavEl.eq(h.bannerCurNum).addClass('select'); h._aniBool = false; h.bannerExNum = h.bannerCurNum; h.onInterval(); }}); }else{ h.anchorMove(0,true); h.$bannerContainer.css({left:h._bannerW*h.bannerCurNum*-1}); h.$bannerNavEl.removeClass('select'); h.$bannerNavEl.eq(h.bannerCurNum).addClass('select'); h._aniBool = false; if(h.bannerExNum != h.bannerCurNum) h.bannerExNum = h.bannerCurNum; h.onInterval(); } }, anchorMove:function(d, b){ var bool = (b)? b:false; if(!bool){ TweenLite.to(this.$bannerNavAnchor, d, {css:{left:66*this.bannerCurNum}}); }else{ this.$bannerNavAnchor.css({left:66*this.bannerCurNum}); } }, //Interval. onRolling:function(){ var h = this; h.bannerCurNum++; if(h.bannerCurNum >= h.bannerMax) h.bannerCurNum = 0; if(h.bannerExNum != h.bannerCurNum){ h.slideMove(); } }, onInterval:function(){ var h = this; if(h._aniBool) return; clearInterval(h._timer); h._timer = setInterval(function(){ (!h._resizeBool)? h.onRolling():clearInterval(h._timer); }, h._time); }, //Resize. resize:function(){ var h = ROLLING.main, bannerW, bannerH, bannerT, bannerL; h._resizeBool = true; if(this.bannerMax > 1) clearInterval(h._timer); h.thumbResize(); h._bannerW = ROLLING.ww; h.$banner.css({width:h._bannerW}); h.$bannerWrap.css({width:h._bannerW}); h.$bannerContainer.css({width:h._bannerW * h.bannerMax}); h.$bannerItem.css({width:h._bannerW}); if(h._bannerW >= h._imgOW){ h._imgW = ROLLING.ww+2; h._imgH = Math.round(h._imgOH * h._imgW / h._imgOW); }else{ h._imgW = h._imgOW; h._imgH = h._imgOH; } h._imgT = Math.round(360 - h._imgH/2); h._imgL = Math.round(512 - h._imgW/2); h.$bannerImgEl.css({width:h._imgW, height:h._imgH, top:h._imgT, left:h._imgL}); h.slideMove(true); if(!this._initBool){ setTimeout(function(){ h.$banner.css({'visibility':'visible'}); h._initBool = true; }, 1); } h._resizeBool = false; }, thumbResize:function(){ $.each(this.$thumbImg, function(i,d){ if($(d).width() != 0){ $(d).css({marginLeft:Math.round(64-$(d).width()/2)}); } }); }, resizeInit:function(){ var h = this; $(window).bind('resize.main',function(){ h.resize(); }); if(window.onorientationchange!==undefined) { $(window).bind('orientationchange.main', function() { h.resize(); }); } $(window).trigger('resize.main'); }, resizeRemoveInit:function(){ $(window).unbind('resize.rolling'); if(window.onorientationchange!==undefined){ $(window).unbind('orientationchange.main'); } } }; $(document).ready(function(){ ROLLING.main.init(); });