var Teasers = function(parentID) { this.parentID = parentID; this.parent = null; this.cont = document.createElement("div"); this.descCont = document.createElement("div"); this.data = new Array(); this.classActive = "active"; this.img = document.createElement("img"); this.tmpImg = document.createElement("img"); this.minOpac = 0; this.opacStep = 5; this.opacTimeStep = 20; this.ready = true; this.swapTimeout = 5000; this.timer = null; this.lastI = -1; this.currentInfo = null; var self = this; this.tmpImg.onload = function() { clearTimeout(self.timer); self.startSwap(); }; this.img.onclick = function() { if(self.currentInfo.URL) { location.href = self.currentInfo.URL; } }; this.descCont.onclick = function() { if(self.currentInfo.URL) { location.href = self.currentInfo.URL; } }; this.cont.onclick = function() { if(self.currentInfo.URL) { location.href = self.currentInfo.URL; } }; }; Teasers.prototype.init = function() { this.parent = fLib.getElementById(this.parentID); this.parent.appendChild(this.cont); this.cont.appendChild(this.img); this.cont.appendChild(this.descCont); this.cont.style.position = "relative"; this.descCont.style.position = "absolute"; }; Teasers.prototype.getNext = function(first) { var i = this.lastI + 1; if(i >= this.data.length) { i = 0; } if(this.lastI != i) { this.setItem(i); } if(this.data.length == 1 && first) { var span = this.parent.getElementsByTagName("span")[0]; this.parent.removeChild(span); } }; Teasers.prototype.add = function(imgID, URL, description, x, y) { var span = document.createElement("span"); var l = this.data.push({span: span, img: imgID, URL: URL, description: description, x: x, y: y}); this.setSpanClick(span, l - 1); this.parent.appendChild(span); }; Teasers.prototype.setItem = function(i) { this.lastI = i; this.currentInfo = this.data[i]; this.tmpImg.src = '/media.php?s=orig&a=image&l=cze&id=' + this.currentInfo.img; }; Teasers.prototype.setSpanClick = function(span, i) { var self = this; span.onclick = function(e) { if(self.ready) { clearTimeout(self.timer); self.setItem(i); if(e !== null) { fLib.stopPropagation(e); } } }; }; Teasers.prototype.blur = function() { var i; for(i in this.data) { this.data[i].span.className = ""; } }; Teasers.prototype.startSwap = function() { var self = this; this.ready = false; fLib.fadeElement(this.cont, 100, this.minOpac, this.opacStep, this.opacTimeStep, function() { self.doSwap(); }); }; Teasers.prototype.doSwap = function() { var self = this; this.img.src = this.tmpImg.src; this.descCont.innerHTML = this.currentInfo.description; this.descCont.style.left = this.currentInfo.x + "px"; this.descCont.style.top = this.currentInfo.y + "px"; this.blur(); this.currentInfo.span.className = this.classActive; fLib.fadeElement(this.cont, this.minOpac, 100, this.opacStep, this.opacTimeStep, function() { self.endSwap(); }); }; Teasers.prototype.endSwap = function() { var self = this; this.timer = setTimeout(function() { self.getNext(false); }, this.swapTimeout); this.ready = true; };