
function PhotoRotator(){

    this.lastShowedCookieName = "prShowedIndex"
    this.lengthCookieName = "prSetLength"
    var cookiesLib = new jslt.CookiesLib()
    this.recordToHTML = function(index){
		var record=prImages[index]
        document.getElementById("photo2").src = "/modules/content/" + record[1] + "-conf414x274_m.jpg"
        document.getElementById("tytul").innerHTML = record[2]
        document.getElementById("linkFoto").href = "/" + lang + "/cms_id/lista_hoteli/_get/hotel/" + record[0]
    	if(cookiesLib.checkCookie()){
			cookiesLib.setCookie(this.lastShowedCookieName,index)
			cookiesLib.setCookie(this.lengthCookieName,prImages.length)
		}
	}
	this.randomize=function(length){
		return Math.floor((Math.random() * length + 1)) - 1
	}
    this.nextPhoto = function(){
        var l = prImages.length;
		//console.log(l)
        //jesteśmy na wybranym obiekcie
        if (typeof(id_place) != "undefined") {
            for (var i = 0; i < l; i++) {
                if (prImages[i][0] == id_place) {
                    this.recordToHTML(i)
                    return
                }
            }
        }
		if (!cookiesLib.checkCookie()) {
            this.recordToHTML(this.randomize(l))
            return
        }
        if (l != parseInt(cookiesLib.readCookie(this.lengthCookieName))) {
            this.recordToHTML(this.randomize(l))
            return
        }
		var index=parseInt(cookiesLib.readCookie(this.lastShowedCookieName))+1
		if(index>(l-1)){
			index=0
		}
		//console.log(index)
        this.recordToHTML(index)
    }
    
    this.PhotoRotator = function(){
        window.PhotoRotatorInstance = this
        this.nextPhoto()
        document.getElementById("photo2").onload = function(){
            setTimeout('window.PhotoRotatorInstance.nextPhoto()', 8000)
        }
    }
    this.PhotoRotator()
}
onLoadQueue.appendOnLoad(PhotoRotator)
