function imageLooperBig(allImages) {
    this.allImages = allImages;
    this.imageCount = allImages.length;
    this.currentImageStart = 0;
    this.maxImages = 3;
    
    this.pagesUl = null;
    this.galleryPane = null;
    this.bigPicture = null;
    this.folder = null;
    this.lang = null;
}
imageLooperBig.prototype.init = function(lang, folder) {
    this.pagesUl = document.getElementById("pages_ul");
    this.galleryPane = document.getElementById("gallery_pane");
    this.bigPicture = document.getElementById("big_picture");
    this.lang = lang;
    this.folder = folder;
}
imageLooperBig.prototype.drawPages = function() {
    for (var i = this.pagesUl.childNodes.length - 1; i >= 0; i--) {
        this.pagesUl.removeChild(this.pagesUl.childNodes[i]);
    }
    
    var loops = 0;
    for (var i = this.currentImageStart; loops++ < this.maxImages; i++) {
        i = (i >= this.imageCount)? 0 : i;
        var liObject = document.createElement("li");
        var aObject = document.createElement("a");
//        aObject.href = "gallery-" + this.lang + ".html/" + this.allImages[i].id;
        aObject.innerHTML = " " + ((loops == 1)? "[" : "") + (i + 1) + ((loops == 1)? "]" : "") + " ";
        liObject.appendChild(aObject);
        this.pagesUl.appendChild(liObject);
    }
}
imageLooperBig.prototype.drawImages = function() {
    for (var i = this.galleryPane.childNodes.length - 1; i >= 0; i--) {
        this.galleryPane.removeChild(this.galleryPane.childNodes[i]);
    }


	if (document.all) {
		var obj = this;
		var img = new Image();
		img.src = "admin/files/" + this.folder + "/" + this.allImages[this.currentImageStart].mid + "?" + Math.random();
		img.onload = function() {
			obj.bigPicture.src = this.src;
		}
	} else {
		this.bigPicture.src = "admin/files/" + this.folder + "/" + this.allImages[this.currentImageStart].mid + "?" + Math.random();
	}
    
    var loops = 0;
    for (var i = this.currentImageStart + 1; loops++ < this.maxImages - 1; i++) {
        i = (i >= this.imageCount)? 0 : i;
        var aObject = document.createElement("a");
//        aObject.href = "gallery-" + this.lang + ".html/" + this.allImages[i].id;
        var imgObject = document.createElement("img");
        imgObject.src = "admin/files/" + this.folder + "/" + this.allImages[i].mini;
        imgObject.title = this.allImages[i].id;
        aObject.appendChild(imgObject);
		this.galleryPane.appendChild(aObject);
    }
}
imageLooperBig.prototype.nextImage = function() {
	if (this.imageCount > 0){
    	this.currentImageStart = (this.currentImageStart + 1 >= this.imageCount)? 0 : this.currentImageStart + 1;
    	this.drawPages();
    	this.drawImages();
    }
}
imageLooperBig.prototype.prevImage = function() {
	if (this.imageCount > 0){
    	this.currentImageStart = (this.currentImageStart - 1 < 0)? this.imageCount - 1 : this.currentImageStart - 1;
	    this.drawPages();
    	this.drawImages();
	}
}

function imageLooperSimple(allImages) {
    this.allImages = allImages;
    this.imageCount = allImages.length;
    this.currentImageStart = 0;
    this.maxImages = 5;
    
    this.pagesUl = null;
    this.galleryPane = null;
}
imageLooperSimple.prototype.init = function(lang, url) {
    this.pagesUl = document.getElementById("pages_ul");
    this.galleryPane = document.getElementById("gallery_pane");
    this.lang = lang;
    this.url = url;
}
imageLooperSimple.prototype.drawPages = function() {
    for (var i = this.pagesUl.childNodes.length - 1; i >= 0; i--) {
        this.pagesUl.removeChild(this.pagesUl.childNodes[i]);
    }
    
    var text = document.createElement("li");
    text.innerHTML = "Ñíèìêè: ";
    this.pagesUl.appendChild(text);
    
    var loops = 0;
    for (var i = this.currentImageStart; loops++ < this.maxImages; i++) {
        i = (i >= this.imageCount)? 0 : i;
        var liObject = document.createElement("li");
        var aObject = document.createElement("a");
        aObject.href = this.lang + "/" + "gallery/" + this.allImages[i].id + ".html";
        aObject.innerHTML = " " + (i + 1) + " ";
        liObject.appendChild(aObject);
        this.pagesUl.appendChild(liObject);
    }
}
imageLooperSimple.prototype.drawImages = function() {
    for (var i = this.galleryPane.childNodes.length - 1; i >= 0; i--) {
        this.galleryPane.removeChild(this.galleryPane.childNodes[i]);
    }

    var loops = 0;
    for (var i = this.currentImageStart; loops++ < this.maxImages; i++) {
        i = (i >= this.imageCount)? 0 : i;
        var aObject = document.createElement("a");
        aObject.href = this.lang + "/" + "gallery/" + this.allImages[i].id + ".html";
        //aObject.setStyle = "background-image: url('"+this.url+"/admin/files/gallery/"+this.allImages[i].pic+"')";
        aObject.style.background="url('"+this.url+"/admin/files/gallery/"+this.allImages[i].pic+"') no-repeat center";
//        aObject.style.background="url("+this.url+"/img/haralanov.jpg) center no-repeat";
        aObject.className = 'home_resize'; 
        /*
        var imgObject = document.createElement("img");
        imgObject.src = "admin/files/gallery/" + this.allImages[i].pic;
        imgObject.title = this.allImages[i].id;
        aObject.appendChild(imgObject);
        */
        this.galleryPane.appendChild(aObject);
    }
}
imageLooperSimple.prototype.nextImage = function() {
	if (this.imageCount > 0) {
	    this.currentImageStart = (this.currentImageStart + 1 >= this.imageCount)? 0 : this.currentImageStart + 1;
	    this.drawPages();
	    this.drawImages();
	}
}
imageLooperSimple.prototype.prevImage = function() {
	if (this.imageCount > 0) {
    	this.currentImageStart = (this.currentImageStart - 1 < 0)? this.imageCount - 1 : this.currentImageStart - 1;
    	this.drawPages();
    	this.drawImages();
	}
}
