/** * trida umi zobrazit galerii pripojenou ke statickemu obsahu stranky * najde si element podle ID prvku a podle aktualni kategorie dostane ID galerie * */ var ContentGallery = function(aGalID) { this.galID = aGalID; this.container = null; this.mainImg = null; this.infoNode = null; this.currImgInfo = null; this.images = new Array(); this.tmpImg = document.createElement("img"); this.fadeDelay = 15; this.opacMax = 100; this.opacMin = 40; this.opacStep = 10; this.imageQueue = new Array(); this.lastID = ""; this.canSwap = false; this.waitCounter = 0; this.inProgress = false; this.gallery = new ShowImage(); this.allowFullscreen = true; this.showButtons = false; this.showTitle = true; this.ready = false; this.onLoad = null; this.thumbVersion = "mini"; this.bigVersion = "medium"; this.fullVersion = "big"; this.loaderPath = "/images/loader.gif"; this.contentContainerID = "wysiwyg_content"; this.contentGalleryClass = "content_gallery"; this.infoClass = "info"; this.contClass = "gallery_container"; this.mainImageClass = "main_image"; this.subImageClass = "sub_image"; this.subCurrentClass = "current"; this.loaderClassName = "loader"; this.client = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0"); }; ContentGallery.prototype.parseOptions = function(options) { for(i in options) { this[i] = options[i]; } }; ContentGallery.prototype.init = function() { var cont = fLib.getElementById(this.contentContainerID); var gal = fLib.getChildrenByClassName(cont, this.contentGalleryClass); if(gal.length >= 1) { this.container = gal[0]; var self = this; this.tmpImg.onload = function() { self.canSwap = true; } this.getImages(); } }; //------------------------------------------------------------------------------ ContentGallery.prototype.processQueue = function() { if(!this.inProgress && this.imageQueue.length > 0) { if(this.currImgInfo) { this.currImgInfo.imgElem.className = this.subImageClass; } this.currImgInfo = this.imageQueue.shift(); this.lastID = this.currImgInfo.id; this.canSwap = false; this.tmpImg.src = "/media.php?a=image&l=cze&s=" + this.bigVersion + "&id=" + this.lastID; this.inProgress = true; this.waitCounter = 0; this.fade(); } }; ContentGallery.prototype.swapImage = function() { if(this.waitCounter > 1000) { return false; } if(this.canSwap) { this.mainImg.className = this.mainImageClass; this.mainImg.src = this.tmpImg.src; this.currImgInfo.imgElem.className = this.subCurrentClass; this.unfade(); } else { this.waitCounter++; var self = this; setTimeout(function() { self.swapImage(); }, this.fadeDelay); } }; ContentGallery.prototype.fade = function() { var self = this; fLib.fadeElement(this.infoNode, this.opacMax, this.opacMin, this.opacStep, this.fadeDelay); fLib.fadeElement(this.mainImg, this.opacMax, this.opacMin, this.opacStep, this.fadeDelay, function() { self.mainImg.className = self.loaderClassName; self.mainImg.src = self.loaderPath; self.swapImage(); }); }; ContentGallery.prototype.unfade = function() { var self = this; if(this.currImgInfo.title == "" || !this.showTitle) { this.infoNode.style.display = "none"; } else { this.infoNode.style.display = "block"; this.infoNode.innerHTML = this.currImgInfo.title; fLib.fadeElement(this.infoNode, this.opacMin, this.opacMax, this.opacStep, this.fadeDelay) } fLib.fadeElement(this.mainImg, this.opacMin, this.opacMax, this.opacStep, this.fadeDelay, function() { self.finishSwap() }); }; ContentGallery.prototype.finishSwap = function() { this.inProgress = false; this.processQueue(); }; ContentGallery.prototype.addImage = function(id, title) { var img = document.createElement("img"); var self = this; var imgInfo = { 'id': id, 'title': title, 'imgElem': img, 'loaded': false }; img.onclick = function() { if(self.allowFullscreen) { self.gallery.display("/media.php?a=image&l=cze&s=" + self.fullVersion + "&id=" + id); } }; img.onmouseover = function() { if(self.lastID != id) { var i = self.findImageIndex(id); self.imageQueue = []; self.imageQueue.push(self.images[i]); self.processQueue(); } }; img.onload = function() { imgInfo.loaded = true; if(self.onLoad) { self.imageLoaded(); } } img.alt = title; img.src = "/media.php?a=image&l=cze&s=" + this.thumbVersion + "&id=" + id; img.className = this.subImageClass; this.images.push(imgInfo); return img; }; ContentGallery.prototype.makeGallery = function(data) { var img; var self = this; this.lastID = data[0].id; var imgCont = document.createElement("div"); var mainImgCont = document.createElement("div"); mainImgCont.className = this.contClass; if(this.showButtons) { var buttPrev = document.createElement("div"); buttPrev.className = "button_prev"; buttPrev.onclick = function() { var i = Math.max(self.findImageIndex(self.currImgInfo.id) - 1, 0); self.imageQueue.push(self.images[i]); self.processQueue(); } var buttNext = document.createElement("div"); buttNext.className = "button_next"; buttNext.onclick = function() { var i = Math.min(self.findImageIndex(self.currImgInfo.id) + 1, self.images.length - 1); self.imageQueue.push(self.images[i]); self.processQueue(); } mainImgCont.appendChild(buttPrev); mainImgCont.appendChild(buttNext); } //hlavni obrazek this.mainImg = document.createElement("img"); //infoblok this.infoNode = document.createElement("div"); this.infoNode.className = this.infoClass; if(data[0].description != "" && this.showTitle) { this.infoNode.innerHTML = data[0].description; } else { this.infoNode.style.display = "none"; } this.mainImg.onclick = function() { if(self.allowFullscreen) { self.gallery.display("/media.php?a=image&l=cze&s=" + self.fullVersion + "&id=" + self.lastID); } } imgCont.appendChild(mainImgCont); mainImgCont.appendChild(this.mainImg); mainImgCont.appendChild(this.infoNode); this.container.appendChild(imgCont); this.container.appendChild(document.createElement("br")); for(i in data) { img = this.addImage(data[i].id, data[i].description); this.gallery.addImage("/media.php?a=image&l=cze&s=" + self.fullVersion + "&id=" + data[i].id); if(data.length > 1) { this.container.appendChild(img); } } this.imageQueue.push(this.images[0]); this.processQueue(); this.ready = true; this.imageLoaded(); }; ContentGallery.prototype.imageLoaded = function() { if(!this.ready || !this.onLoad) { return false; } for(i in this.images) { if(!this.images[i].loaded) { return false; } } this.onLoad(); }; ContentGallery.prototype.getClientData = function() { if(this.client.readyState == 4) { if(this.client.status == 200) { data = eval(this.client.responseText); if(data.length > 0) { this.makeGallery(data); } } else { myAlert('There was a problem with the HTTP request.'); } } }; ContentGallery.prototype.getImages = function() { var url = 'a=javascript&s=getContentGallery&id=' + this.galID; var self = this; fLib.postData(this.client, '/index.php', url, function() { self.getClientData(); }); }; ContentGallery.prototype.findImageIndex = function(id) { var i; for(i in this.images) { if(this.images[i].id == id) { return parseInt(i); } } return -1; };