/* Author: (c) Emmanuel C. Halos (my_mudspring@yahoo.com) Personal use only. */
function vnDecoChanger(pS) { var fs = { o: { veggie: '', decoTop: '', decoBtm: '' }, s: { decoTop: 'decoTop', decoBtm: 'decoBtm' }, t: { v: '', d: '' }, p: { d: 'img/', lastV: -1, veggieLen: 7, veggiePfx: 'vNVeggie', veggieTimeout: 30000, lastD: -1, decoLen: 5, decoPfx: 'decoBg', decoTimeout: 60000 }, id: { veggie: 'vNVeggie' }, evt: { onload: '' } }; this.init = init; function init(pS) { var ls = { ok: 1 }; if (pS.id) { setProp('fs.id', 'pS.id'); } if (pS.s) { setProp('fs.s', 'pS.s'); } if (pS.f) { setProp('fs.f', 'pS.f'); } for (ls.e in fs.o) { eval('fs.o.' + ls.e + ' = document.getElementById(fs.id.' + ls.e + ');'); } if (!fs.o.decoTop) { fs.o.decoTop = getDecoObject(fs.s.decoTop); } if (!fs.o.decoBtm) { fs.o.decoBtm = getDecoObject(fs.s.decoBtm); } if (ls.ok) { clearTimeout(fs.t.v); clearTimeout(fs.t.d); if (fs.o.veggie) { fs.t.v = setTimeout(swapVeggie, fs.p.veggieTimeout); } if (fs.o.decoTop || fs.o.decoBtm ) { fs.t.d = setTimeout(swapDeco, fs.p.decoTimeout); } } return this; } function swapDeco() { var ls = {}; clearTimeout(fs.t.d); if (fs.o.decoTop || fs.o.decoBtm ) { do { ls.idx = Math.round(Math.random() * (fs.p.decoLen-1)) + 1; } while(ls.idx == fs.p.lastD); if (fs.o.decoTop) { delClassName(fs.o.decoTop, fs.p.decoPfx + fs.p.lastD); addClassName(fs.o.decoTop, fs.p.decoPfx + ls.idx); } if (fs.o.decoBtm) { delClassName(fs.o.decoBtm, fs.p.decoPfx + fs.p.lastD); addClassName(fs.o.decoBtm, fs.p.decoPfx + ls.idx); } fs.p.lastD = ls.idx; fs.t.d = setTimeout(swapDeco, fs.p.decoTimeout); } } function swapVeggie() { var ls = {}; clearTimeout(fs.t.v); if (fs.o.veggie) { do { ls.idx = Math.round(Math.random() * (fs.p.veggieLen-1)) + 1; } while(ls.idx == fs.p.lastV); delClassName(fs.o.veggie, fs.p.veggiePfx + fs.p.lastV); addClassName(fs.o.veggie, fs.p.veggiePfx + ls.idx); fs.p.lastV = ls.idx; fs.t.v = setTimeout(swapVeggie, fs.p.veggieTimeout); } } function getDecoObject(pClass) { var ls = { out: '' }; ls.sList = document.getElementsByTagName('span'); for (ls.i=0; ls.i<ls.sList.length; ls.i++) { ls.oS = ls.sList[ls.i]; if (hasClassName(ls.oS, pClass)) { ls.out = ls.oS; break; } } return ls.out; } function setProp(varObj, argObj) { var ls = { varObj: eval(varObj), argObj: eval(argObj) }; if (ls.argObj) { for (ls.p in ls.varObj) { ls.tmp = eval(varObj + '.' + ls.p); switch (typeof(ls.tmp)) { case 'string': case 'number': ls.tmp = eval(argObj + '.' + ls.p); if (typeof(ls.tmp) != 'undefined') { eval(varObj + '.' + ls.p + ' = ls.tmp'); } break; case 'object': setProp(varObj + '.' + ls.p, argObj + '.' + ls.p); break; } } } } function addClassName(pObj, pClass) { var ls = {}; if (!hasClassName(pObj, pClass)) { pObj.className += ((pObj.className.length) ? ' ' : '') + pClass; } } function hasClassName(pObj, pClass) { var ls = { hasClass: 0 }; ls.re1 = new RegExp('' + pClass + '(\\s+|$)', 'g'); ls.re2 = new RegExp('\\s+' + pClass + '(\\s+|$)', 'g'); if (pObj.className.search(ls.re1) > -1 || pObj.className.search(ls.re2) > -1) { ls.hasClass = 1; } return ls.hasClass; } function delClassName(pObj, pClass) { var ls = {}; pObj.className = pObj.className.replace(new RegExp('(^|\s*)' + pClass + '(\s*|$)', 'ig'), ''); pObj.className = pObj.className.replace(/^\s+|\s+$/g, ''); } if (pS) { init(pS); } }
