﻿JEND.UI={tab:function(pEl,pBox,pEvent,pAuto,pClassName,pRandom){pClassName=pClassName||'c';pRandom=pRandom||false;var cNum=(function(){for(var i=0;i<pBox.length;i++){if(pBox[i].className==pClassName){if(!pRandom){return i}else{pBox[i].className='';var index=parseInt(Math.random()*pBox.length);pBox[index].className='c';return index}}}return null})()||0;var doTab=function(el){if(el===undefined){el=pEl[cNum]}else if(typeof(el)=='number'){el=pEl[el]}for(var i=0;i<pBox.length;i++){if(JEND.DOM.isIn(el,pBox[i])){pBox[i].className=pClassName;cNum=i}else{pBox[i].className=''}}};var doAuto=function(){cNum++;if(cNum==pEl.length){cNum=0}doTab()};if(typeof(pAuto)=='number'){var aT=JEND.UI.auto(doAuto,pAuto)}if(typeof(pEvent)=='number'){doTab(pEvent)}else{for(var i=0;i<pEl.length;i++){if(pEl[i].tagName=='A'&&(pEl[i].href.split('#')[0]==location.href.split('#')[0]||pEl[i].href.split('#')[0]==='')){JEND.EVENT.on(pEl[i],'click',function(e){JEND.EVENT.preventDefault(e||event)})}JEND.EVENT.on(pEl[i],pEvent,function(e){var el=e.target||event.srcElement;doTab(el)});if(typeof(pAuto)=='number'){JEND.EVENT.on(pEl[i],'mouseover',function(){clearInterval(aT);aT=null});JEND.EVENT.on(pEl[i],'mouseout',function(){aT=JEND.UI.auto(doAuto,pAuto)})}}}},pull:function(pEl,pBox,pEvent,pFunction,pClassName){var fA=false;var fB=false;if(typeof(pFunction)=='string'){pClassName=pFunction}else if(typeof(pFunction)=='array'){fA=pFunction[0]||function(){};fB=pFunction[1]||function(){}}else if(typeof(pFunction)=='function'){fA=pFunction}pClassName=pClassName||'c';if(pEvent=='click'){JEND.EVENT.on(pEl,pEvent,function(e){pBox.className=(pBox.className==pClassName)?'':pClassName;if(fA){fA(e)}JEND.EVENT.preventDefault(e)})}if(pEvent=='mouseover'){var tOver=function(e){pBox.className=pClassName;if(fA){fA(e)}};var tOut=function(e){pBox.className='';if(fB){fB(e)}};JEND.EVENT.on(pEl,pEvent,tOver);JEND.EVENT.on(pEl,'mouseout',tOut);if(pEl!=pBox){JEND.EVENT.on(pBox,pEvent,tOver);JEND.EVENT.on(pBox,'mouseout',tOut)}}},roll:{_o:{},x:function(p,pL,pR,pEvent,pDistance,pFunction,pAuto,pFixWH){this.init(p,pL,pR,pEvent,'Left','Right',pDistance,pFunction,pAuto,pFixWH)},y:function(p,pT,pB,pEvent,pDistance,pFunction,pAuto,pFixWH){this.init(p,pT,pB,pEvent,'Top','Bottom',pDistance,pFunction,pAuto,pFixWH)},init:function(p,pA,pB,pEvent,pDA,pDB,pDistance,pFunction,pAuto,pFixWH){var tBox=JEND.DOM.create('div');var tO=JEND.getDOM(p).getChildren()[0];this._o[p]={};this._o[p].items=JEND.getDOM(tO).getChildren();this._o[p].current=this._o[p].itemsWidth=this._o[p].itemsHeight=this._o[p].tempWidth=this._o[p].tempHeight=0;this._o[p].itemWidth=JEND.UI.getStyle(JEND.UI.roll._o[p].items[0]).width.toInt();this._o[p].itemHeight=JEND.UI.getStyle(JEND.UI.roll._o[p].items[0]).height.toInt();this._o[p].fn=pFunction;this._o[p].distance=pDistance;this._o[p].on=false;if(pAuto===true){this._o[p].isAuto=5000}else if(pAuto.constructor==[].constructor||typeof(pAuto)=='number'){this._o[p].isAuto=pAuto}else{this._o[p].isAuto=false}for(var i=0;i<this._o[p].items.length;i++){this._o[p].itemsWidth+=this._o[p].items[i].offsetWidth.toInt();this._o[p].itemsHeight+=this._o[p].items[i].offsetHeight.toInt()}if(pDA=='Left'){tO.style.width=this._o[p].itemsWidth.toPx();tBox.style.width=(this._o[p].itemsWidth*2).toPx();tBox.style.height=JEND.UI.getStyle(tO).height;this._o[p].WH='Width'}else{tO.style.height=this._o[p].itemsHeight.toPx();tBox.style.height=(this._o[p].itemsHeight*2).toPx();tBox.style.width=JEND.UI.getStyle(tO).width;this._o[p].WH='Height'}JEND.getDOM(p)[0].removeChild(tO);JEND.getDOM(p)[0].appendChild(tBox);tBox.appendChild(tO);tBox.appendChild(tO.cloneNode(true));this.action(p,pA,pDB,pEvent);this.action(p,pB,pDA,pEvent);if(this._o[p].isAuto){this.auto(p,pDA);JEND.EVENT.on(JEND.getDOM(p)[0],'mouseover',function(){if(JEND.UI.roll._o[p].onT){clearInterval(JEND.UI.roll._o[p].onT);JEND.UI.roll._o[p].onT=null;JEND.UI.roll._o[p].on=true}});JEND.EVENT.on(JEND.getDOM(p)[0],'mouseout',function(){JEND.UI.roll._o[p].onT=setTimeout(function(){JEND.UI.roll._o[p].on=false;JEND.UI.roll.restartAuto(p,pDA)},1000)})}if(pFixWH){this.fixWH(p);JEND.EVENT.on(window,'resize',function(){JEND.UI.roll.fixWH(p)})}},fixWH:function(p){JEND.getDOM(p)[0].parentNode.style.width='auto';if(JEND.getDOM(p)[0].parentNode.offsetWidth.toInt()>JEND.UI.roll._o[p]['items'+JEND.UI.roll._o[p].WH]-JEND.UI.roll._o[p]['item'+JEND.UI.roll._o[p].WH]){JEND.getDOM(p)[0].parentNode.style.width=(JEND.UI.roll._o[p]['items'+JEND.UI.roll._o[p].WH]-JEND.UI.roll._o[p]['item'+JEND.UI.roll._o[p].WH]).toPx()}},auto:function(p,pD){if(JEND.UI.roll._o[p].a===null||JEND.UI.roll._o[p].a===undefined){JEND.UI.roll._o[p].a=JEND.UI.auto(function(){if(JEND.UI.roll._o[p].fn){JEND.UI.roll._o[p].fn(pD)}JEND.UI.roll.move(p,pD)},JEND.UI.roll._o[p].isAuto[JEND.UI.roll._o[p].current]||JEND.UI.roll._o[p].isAuto)}},restartAuto:function(p,pDD){if(JEND.UI.roll._o[p].t===null||JEND.UI.roll._o[p].t===undefined){JEND.UI.roll.move(p,pDD)}},action:function(p,pD,pDD,pEvent){JEND.EVENT.on(JEND.getDOM(pD)[0],pEvent,function(e){JEND.EVENT.preventDefault(e);if(JEND.UI.roll._o[p].t===null||JEND.UI.roll._o[p].t===undefined){clearInterval(JEND.UI.roll._o[p].a);JEND.UI.roll._o[p].a=null;if(JEND.UI.roll._o[p].fn){JEND.UI.roll._o[p].fn(pD)}JEND.UI.roll.move(p,pDD);return false}})},move:function(p,pDirection){var tDirection='Left';var tIncrement=1;if(pDirection=='Top'||pDirection=='Bottom'){tDirection='Top'}if(pDirection=='Left'||pDirection=='Top'){if(JEND.getDOM(p)[0]['scroll'+tDirection]>=JEND.UI.roll._o[p]['items'+JEND.UI.roll._o[p].WH]){JEND.getDOM(p)[0]['scroll'+tDirection]-=JEND.UI.roll._o[p]['items'+JEND.UI.roll._o[p].WH]}if(JEND.getDOM(p)[0]['scroll'+tDirection]==JEND.UI.roll._o[p]['items'+JEND.UI.roll._o[p].WH]){JEND.getDOM(p)[0]['scroll'+tDirection]=JEND.UI.roll._o[p]['item'+JEND.UI.roll._o[p].WH]*(JEND.UI.roll._o[p].current+1)}}if(pDirection=='Right'||pDirection=='Bottom'){tIncrement=-1;if(JEND.getDOM(p)[0]['scroll'+tDirection]<=JEND.UI.roll._o[p]['item'+JEND.UI.roll._o[p].WH]){JEND.getDOM(p)[0]['scroll'+tDirection]+=JEND.UI.roll._o[p]['items'+JEND.UI.roll._o[p].WH]}if(JEND.getDOM(p)[0]['scroll'+tDirection]==0){JEND.getDOM(p)[0]['scroll'+tDirection]=JEND.UI.roll._o[p]['item'+JEND.UI.roll._o[p].WH]*(JEND.UI.roll._o[p].current+1)}}var tDistance=(JEND.UI.roll._o[p].distance||1)*tIncrement;if(JEND.UI.roll._o[p]['item'+JEND.UI.roll._o[p].WH]-JEND.UI.roll._o[p]['temp'+JEND.UI.roll._o[p].WH]===0){clearInterval(JEND.UI.roll._o[p].t);JEND.UI.roll._o[p].t=null;clearInterval(JEND.UI.roll._o[p].a);JEND.UI.roll._o[p].a=null;JEND.UI.roll._o[p]['temp'+JEND.UI.roll._o[p].WH]=0;JEND.UI.roll._o[p].current+=tIncrement;if(JEND.UI.roll._o[p].current==JEND.UI.roll._o[p].items.length){JEND.UI.roll._o[p].current=0}else if(JEND.UI.roll._o[p].current<0){JEND.UI.roll._o[p].current+=JEND.UI.roll._o[p].items.length}if(JEND.UI.roll._o[p].isAuto&&!JEND.UI.roll._o[p].on){JEND.UI.roll.auto(p,pDirection)}}else{JEND.getDOM(p)[0]['scroll'+tDirection]+=tDistance;JEND.UI.roll._o[p]['temp'+JEND.UI.roll._o[p].WH]+=JEND.UI.roll._o[p].distance;if(!JEND.UI.roll._o[p].t){JEND.UI.roll._o[p].t=JEND.UI.auto(function(){JEND.UI.roll.move(p,pDirection)})}}}},auto:function(p,t){t=t||5;return setInterval(p,t)},getStyle:function(el){if(document.defaultView&&document.defaultView.getComputedStyle){return document.defaultView.getComputedStyle(el,"")}else if(document.documentElement.currentStyle&&el.currentStyle){return el.currentStyle}else{return el.style}}};