function _xyloo_Container(){ this.Objects=new _xyloo_Objects(); this.DOM=new _xyloo_DOM();}; function _xyloo_Objects(){this.Items=new Array();this.nextIndex=1;this.Length=0}; _xyloo_Objects.prototype.Add=function(obj){this.Items[this.Items.length]=["object #"+this.nextIndex,obj];this.nextIndex++;this.Length=this.Items.length;return"object #"+(this.nextIndex-1)}; function _xyloo_DOM(){};_xyloo_DOM.prototype.IsIE=function(){if(navigator.appName=="Microsoft Internet Explorer")return true;else return false}; _xyloo_Container=new _xyloo_Container(); var BinhBK_Rolling_Global_Counter = new Array(); var BinhBK_Rolling_Timer = new Array(); var RollingCounter_preImage = new Image(); var RollingCounter_preImageUnit = new Image(); var BinhBK_RollingCounter_Pause = false; //RollingCounter_preImage.src = webroot+"rollimg.jpg"; //RollingCounter_preImageUnit.src = webroot+"rollimgunit.jpg"; /*==== Load tập hợp hình của scroll ====*/ function BinhBK_testRun(i) { if (BinhBK_Rolling_Global_Counter[i].running && !BinhBK_RollingCounter_Pause) { BinhBK_Rolling_Global_Counter[i].Run(); BinhBK_Rolling_Timer[i] = setTimeout("BinhBK_testRun("+i+")",BinhBK_Rolling_Global_Counter[i].Container.Delay); } }; /*==== Đối tượng của 1 con số ====*/ function BinhBK_RollingCounter() { /*==== 1 vài biến cơ bản ====*/ this.width = 10; this.height = 13; this.scrolling = "no"; this.frameborder = 0; this.startNumber = 0; this.destinationNumber = 0; this.Delay = 50;/*10 miligiây*/ this.position = 0; /*Trạng thái của counter*/ this.running = false; /*Số vòng lặp*/ this.loop = 0; this.CounterIndex = 0; this.UnitCounter = false; this.Container = null; this.ImgUnit = RollingCounter_preImageUnit; this.ImgCounter = RollingCounter_preImage; /* ---- Counter cha có quan hệ với nó ---- */ this.ParentCounter = null; /*Tốc độ : Số giây cần thực hiện xong lần quay*/ this.speed = 6; /* pixels/second */ /*Số pixel dịch chuyển => bước nhảy*/ this.step = 1; this.IsStarted = false; /*Sai số*/ this.ErrorNumber = 0.01; /*-- Đối tượng Image chứa hình counter (hình dài từ 0-9)--*/ this.ScrollingImage = null; /*==== Tạo 1 đối tượng iframe để đặt hình vào ====*/ this.obj = document.createElement("iframe"); with (this.obj) { frameBorder = 0; style.width = this.width+"px"; style.height = this.height+"px"; scrolling = "no"; style.margin = "0px"; } this.id = _xyloo_Container.Objects.Add(this); this.obj.id = this.id; }; BinhBK_RollingCounter.prototype.SwitchImg = function() { var tmp = this.ImgUnit; this.ImgUnit = this.ImgCounter; this.ImgCounter = tmp; }; BinhBK_RollingCounter.prototype.Create = function() { /*==== create content ====*/ this.IDocument = null; this.IDocument = null; if (_xyloo_Container.DOM.IsIE()) this.IDocument = this.obj.contentWindow.document; else { this.IDocument = this.obj.contentDocument; } if (this.UnitCounter) this.IDocument.write(""); else this.IDocument.write(""); /*Tính toán vị trí theo pixel*/ this.position = -1*parseInt(this.startNumber)*this.height; /*Vì IE và Firefox có cách roll khác nhau nên xét 2 trường hợp*/ if (_xyloo_Container.DOM.IsIE()) this.IDocument.body.firstChild.style.marginTop = this.position; else this.IDocument.body.style.marginTop = this.position; this.destinationNumber = this.startNumber; this.IDocument.close(); }; BinhBK_RollingCounter.prototype.Run = function() { var tempstartNumber = this.startNumber+""; var unitNumber = parseInt(tempstartNumber.charAt(tempstartNumber.length-1)); if (this.startNumber < this.destinationNumber) { /* ---- Nếu số đơn vị đã đến 9 và bắt đầu quay sang số 0 thì cho số chay quay cùng luôn ---- */ if (unitNumber == 9) { /* ---- Cho counter cha chạy 1 đơn vị ---- */ if (!this.ParentCounter.running) { this.ParentCounter.running = true; this.ParentCounter.destinationNumber = parseInt(this.ParentCounter.startNumber) + 1; BinhBK_testRun(this.ParentCounter.CounterIndex,this.ParentCounter.Delay); } } this.position -= this.step; /* ---- Khi quay hết con số hiện tại, chuyển đến con số tiếp theo ---- */ if (this.position <= -1*(unitNumber+1)*this.height) { /* ---- Tăng biến đếm lên 1 đơn vị ---- */ this.startNumber++; this.Container.startNumber++; /* ---- Nếu quay đến 9 thì trở về 0 lại ---- */ if (unitNumber == 9) this.position = 0; else this.position = -1*(unitNumber+1)*this.height; } /*Vì IE và Firefox có cách roll khác nhau nên xét 2 trường hợp*/ if (_xyloo_Container.DOM.IsIE()) this.IDocument.body.firstChild.style.marginTop = this.position; else this.IDocument.body.style.marginTop = this.position; } else { this.running = false; this.IsStarted = false; this.position = -1*unitNumber*this.height; } }; /************************************************************************************************* * Đây là đối tượng couter hoàn chỉnh, bao gồm nhiều counter item trong nó * **************************************************************************************************/ function BinhBK_RollingCounterSet() { this.TotalNumber = 8; this.startNumber = 0; this.Container = null; this.bootTimes = 1; }; BinhBK_RollingCounterSet.prototype.SwitchImg = function() { this.isSwitchImg = !this.isSwitchImg; }; BinhBK_RollingCounterSet.prototype.Create = function() { this.endNumber = this.startNumber; if (this.startNumber > Math.floor(Math.pow(10,this.TotalNumber)*9.9999999999)) { alert("Start number of Rolling counter is invalid. Please select a number that less than "+Math.floor(Math.pow(10,this.TotalNumber)*9.9999999999)); } else { this.startNumber = this.startNumber + ""; var startSetNumber = this.TotalNumber - this.startNumber.length; for (var i=0;i= startSetNumber) startNumber = this.startNumber.charAt(i-startSetNumber); if (i == (this.TotalNumber -1)) UnitCounter = true; if (i > 0) ParentCounter = BinhBK_Rolling_Global_Counter[i-1]; Container = this; obj.style.display = "inline"; obj.style.margin = "0px"; this.Container.appendChild(obj); Create(); } }; this.startNumber = parseInt(this.startNumber); } }; BinhBK_RollingCounterSet.prototype.RunMore = function(number) { this.endNumber += number; var distance = this.endNumber - this.startNumber; if (distance >= 100) { this.Delay = 10; this.bootTimes = 2; } else if (distance > 50) { this.Delay = 50; this.bootTimes = 1; } else if (distance > 20) { this.Delay = 100; this.bootTimes = 1; } else { this.Delay = 250; this.bootTimes = 1; }; BinhBK_Rolling_Global_Counter[BinhBK_Rolling_Global_Counter.length -1].running = true; if ((this.endNumber-number) != this.startNumber) { BinhBK_Rolling_Global_Counter[BinhBK_Rolling_Global_Counter.length -1].destinationNumber += number; clearTimeout(BinhBK_Rolling_Timer[BinhBK_Rolling_Global_Counter.length -1]); } else { BinhBK_Rolling_Global_Counter[BinhBK_Rolling_Global_Counter.length -1].destinationNumber = parseInt(BinhBK_Rolling_Global_Counter[BinhBK_Rolling_Global_Counter.length -1].startNumber) + number; }; /*this.startNumber += number;*/ BinhBK_testRun(BinhBK_Rolling_Global_Counter.length-1,this.Delay); };_xyloo_home_url="http://www.xyloo.fr/"; _xyloo_counter=null; _xyloo_icon_src=_xyloo_home_url + "libs/com/dynamic/dc05/xyloo.gif"; function _xyloo_G(o) {return document.getElementById(o);}; function _xyloo_C(o) {return document.createElement(o);}; function _xyloo_S(v){ return _xyloo_G(v).style; }; function _xyloo_jsexec(url, _id) { ojs = document.getElementById(_id); if (ojs!=null) document.getElementsByTagName("head")[0].removeChild(ojs); var njs = document.createElement("script"); njs.id= _id; njs.type = "text/javascript"; njs.src = url; if (navigator.userAgent.indexOf("Safari")) njs.charset = "utf-8"; njs = document.getElementsByTagName("head")[0].appendChild(njs); return njs; }; function _xyloo_addEvent(target,eventName,handlerName) { if ( target.addEventListener ) { target.addEventListener(eventName, handlerName, false); } else if ( target.attachEvent ) { target.attachEvent("on" + eventName, handlerName); } else { var originalHandler = target["on" + eventName]; if ( originalHandler ) { target["on" + eventName] = function(e){originalHandler(e);}; } else { target["on" + eventName] = handlerName; } } }; RollingCounter_preImage = new Image(); RollingCounter_preImageUnit = new Image(); RollingCounter_preImage.src = _xyloo_home_url + "Templates/xyloo/Images/counters/dynamic/exblack.jpg"; RollingCounter_preImageUnit.src = _xyloo_home_url + "Templates/xyloo/Images/counters/dynamic/exwhite.jpg"; function __XylooCounter(startNum) { divContainer = _xyloo_G("xyloo_container"); if(divContainer) { icon = _xyloo_C("IMG"); icon.src = _xyloo_icon_src; icon.border = "0"; div = _xyloo_C("DIV"); div.style.border = "1px solid #9E9E9A"; div.style.padding = "1px"; div.style.width = "80px"; div1 = _xyloo_C("DIV"); div1.appendChild(icon); div2 = _xyloo_C("DIV"); div2.id = "xylooNumContainer"; div2.style.paddingTop = "1px"; div.appendChild(div1); div1.appendChild(div2); divContainer.appendChild(div); _xyloo_counter = new BinhBK_RollingCounterSet(); _xyloo_counter.Container = div2; _xyloo_counter.width = 10; _xyloo_counter.height = 13; _xyloo_counter.Delay = 1; _xyloo_counter.startNumber = startNum; _xyloo_counter.Create(); _xyloo_counter.RunMore(5); } }; function _xyloo_load_dyncounter() { var req_url = _xyloo_home_url + "Global_Counter"; _xyloo_jsexec (req_url, "06564e407828b4d72dcc49502fb4f840"); setInterval("_xyloo_activate_routing()", 1000*30); }; function _xyloo_activate_routing() { var endNumber = 0; if(_xyloo_counter!=null) endNumber =_xyloo_counter.endNumber; var req_url = _xyloo_home_url + "Global_Counter/atvCounter/" + endNumber; _xyloo_jsexec (req_url,"b212b53619f983fe2d7b33c69be6d776"); }; /* real time update vistor for dyn counter */ _xyloo_addEvent(window, "load", _xyloo_load_dyncounter);