var ftpCameraActualImagesObj = new Object(); function ftpCameraActualImageObj(id) { this.id = id; this.sensor = null; this.width = null; this.height = null; this.refresh_period = null; this.has_description = null; this.has_timestamp = null; this.hash_key = null; this.setParams = function () { var nowDate = new Date(); this.sensor = $( "ftpCameraActualImage_hidden_sensor_id_" + this.id ).value; this.width = $("ftpCameraActualImage_hidden_width_id_" + this.id).value; this.height = $( "ftpCameraActualImage_hidden_height_id_" + this.id ).value; this.refresh_period = $( "ftpCameraActualImage_hidden_refresh_period_id_" + this.id ).value; this.has_description = $( "ftpCameraActualImage_hidden_has_description_id_" + this.id ).value; this.has_timestamp = $( "ftpCameraActualImage_hidden_has_timestamp_id_" + this.id ).value; this.resample = $( "ftpCameraActualImage_hidden_resample_id_" + this.id ).value; this.time_old = $( "ftpCameraActualImage_hidden_time_old_id_" + this.id ).value; if ( $("ftpCameraActualImage_hidden_direction_id_" + this.id) != undefined ) this.direction_id = $( "ftpCameraActualImage_hidden_direction_id_" + this.id ).value; this.lang = $("ftpCameraActualImage_hidden_lang_id_" + this.id).value; this.next_time_refresh = nowDate.getTime() / 1000; }; this.reload = function () { var nowDate = new Date(); // unikatni id kvuli refresovani a cache-ovani obrazku -> zpusobuje vzdy refresh var unique_number = Math.floor(Math.random() * 10000000); // zmena obrazku var img_element = $("ftpCameraActualImage_img_id_" + this.id); if (img_element) { img_element.src = imageProviderUrl + "?sensor=" + this.sensor + "&di=" + this.direction_id + "&w=" + this.width + "&h=" + this.height + "&to=" + this.time_old + "&ht=" + this.has_timestamp + "&resample=" + this.resample + "&lang=" + this.lang + "&unique=" + unique_number + "&hash_key=" + ftpCameraActualImagesObj.hash_key; } // zmena desc if (this.has_description == true) { var desc_element = $("ftpCameraActualImage_span_id_" + this.id); if (desc_element) desc_element.innerHTML = "Poslední obnova snímku : " + getActualTimestamp(); } this.next_time_refresh = nowDate.getTime() / 1000 + 1 * this.refresh_period; }; return this; } function ftpCameraActualImageFunctionInit() { ftpCameraActualImagesObj.getImages = function () { this.images = new Object(); this.images_count = 0; this.status = new Object(); var i = 1; var image_element = $("ftpCameraActualImage_div_id_" + i); while (image_element != null) { this.images[i] = new ftpCameraActualImageObj(i); this.images[i].setParams(); this.images_count = this.images_count + 1; this.status[i] = "initialize"; i = i + 1; image_element = $("ftpCameraActualImage_div_id_" + i); } }; ftpCameraActualImagesObj.findNextReloadedImage = function () { var nowDate = new Date(); var actual_time = nowDate.getTime() / 1000; var find_image = new Object(); find_image.id = null; find_image.time = null; find_image.reload = null; // hledam jakykoliv cekajici obrazek for (i = 1; i <= this.images_count; i++) { if (this.status[i] == "waiting") { find_image.id = i; find_image.time = this.images[i].next_time_refresh; find_image.reload = false; } } // zadny neceka na reload if (find_image.id == null) return find_image; // ted hledam prvni ktery je v poradi na reload for (i = 1; i <= this.images_count; i++) { if ( find_image.time > this.images[i].next_time_refresh && this.status[i] == "waiting" ) { find_image.id = i; find_image.time = this.images[i].next_time_refresh; } } if (find_image.time <= actual_time) find_image.reload = true; else find_image.reload = false; return find_image; }; ftpCameraActualImagesObj.startRefreshing = function () { for (var sss in this.status) { if (this.status[sss] == "initialize") { this.status[sss] = "loading"; this.images[sss].reload(); } } var next_reloaded = this.findNextReloadedImage(); if (next_reloaded.reload == true) { this.status[next_reloaded.id] = "loading"; setTimeout("ftpCameraActualImagesObj.startRefreshing()", 1); this.images[next_reloaded.id].reload(); return true; } setTimeout("ftpCameraActualImagesObj.startRefreshing()", 1000); }; ftpCameraActualImagesObj.init = function () { this.getImages(); this.startRefreshing(); }; ftpCameraActualImagesObj.getHashKey = function () { new Ajax.Request("/Discoverer/Tools/get-hash-key/", { method: "post", parameters: {}, onComplete: function (transport) { ftpCameraActualImagesObj.hash_key = transport.responseText; setTimeout("ftpCameraActualImagesObj.getHashKey()", 60000); }, }); }; new Ajax.Request("/Discoverer/Tools/get-hash-key/", { method: "post", parameters: {}, onComplete: function (transport) { ftpCameraActualImagesObj.hash_key = transport.responseText; setTimeout("ftpCameraActualImagesObj.getHashKey()", 60000); ftpCameraActualImagesObj.init(); }, }); ftpCameraActualImagesObj.status = function () { return this.status; }; } changeImage = function (image) { document.getElementById("first").style.display = "none"; var images = document.getElementsByClassName("change"); for (var im = 0; im < images.length; im++) { if (images[im].id == image) document.getElementById(image).style.display = "block"; else document.getElementById(images[im].id).style.display = "none"; } };