/** * guide_slideshow.js */ var slide_show = new slideShow('slide_show'); slide_show.numof = 6; function slideShow(class_name) { this.class_name = class_name; this.numof = 0; this.slide = 1; this.timer = false; this.transtimer = new Array(this.numof); /* numof has to be set in HTML page */ this.startSlideshow = function (num) { this.numof = num; this.outslide(); } this.projector = function () { if (this.slide == this.numof) { this.showslide(1); } else { this.showslide(this.slide+1); } this.timer = setTimeout(this.class_name+'.projector()', 3000); // 3000 } this.showslide = function (num) { if (num != this.slide) { if (navigator.userAgent.indexOf('afari') != -1) { this.hardTransition(this.slide, num); } else { this.softTransition(this.slide, num, 1); } this.slide = num; } } this.overslide = function (num) { if (this.timer) { clearTimeout(this.timer); } this.showslide(num); } this.outslide = function () { this.timer = setTimeout(this.class_name+'.projector()', 1000); } this.getTransparency = function (id) { if (document.getElementById(id).style.filter) { return document.getElementById(id).style.filter.replace(/[^0-9]/g,'') / 10; } else if (document.getElementById(id).style.opacity) { return parseFloat(document.getElementById(id).style.opacity) * 10; } else { return 1; } } this.setTransparency = function (id, transparency) { document.getElementById(id).style.filter = 'Alpha(opacity=' + (transparency * 10) + ')'; document.getElementById(id).style.opacity = transparency / 10; } this.softTransition = function (num1, num2, phase) { // Clean up - stop other jobs if (this.transtimer[num1]) { clearTimeout(this.transtimer[num1]); } if (this.transtimer[num2]) { clearTimeout(this.transtimer[num2]); } // Get transparency transparency1 = this.getTransparency('slide_'+num1); transparency2 = this.getTransparency('slide_'+num2); // Process appropiate phase switch (phase) { case 1: // Clean up - set others to default state for (i = 1; i <= this.numof; i++) { if (i != num1) { document.getElementById('slide_'+i).style.display = 'none'; document.getElementById('slidethumb_'+i).style.borderBottom = '1px solid #e6e6e6'; this.setTransparency('slidethumb_'+i, 4); } } // Set current states document.getElementById('slide_'+num1).style.display = 'block'; document.getElementById('slidethumb_'+num1).style.borderBottom = '5px solid #e6e6e6'; // Process transparency transparency2 = 0; if (transparency1 > 0) { transparency1 = transparency1 - 1; } else { phase = 2; } timernum = num1; break; case 2: document.getElementById('slide_'+num2).style.display = 'block'; phase = 3; timernum = num1; // Intention: No break here! case 3: // Clean up - set others to default state for (i = 1; i <= this.numof; i++) { if (i != num2) { document.getElementById('slide_'+i).style.display = 'none'; document.getElementById('slidethumb_'+i).style.borderBottom = '1px solid #e6e6e6'; this.setTransparency('slidethumb_'+i, 4); } } // Set current states document.getElementById('slide_'+num2).style.display = 'block'; document.getElementById('slidethumb_'+num2).style.borderBottom = '5px solid #e6e6e6'; // Process transparency if (transparency2 < 10) { transparency2 = transparency2 + 1; } else { phase = 4; } timernum = num2; break; } if (phase >= 1 && phase <= 3 ) { // Set current transparency states this.setTransparency('slide_'+num1, transparency1); this.setTransparency('slide_'+num2, transparency2); if (transparency1 >= 4) { this.setTransparency('slidethumb_'+num1, transparency1); } if (transparency2 >= 4) { this.setTransparency('slidethumb_'+num2, transparency2); } // Set timer for next iteration this.transtimer[timernum] = setTimeout(this.class_name+'.softTransition('+num1+', '+num2+', '+phase+')', 10); // 10 } } this.hardTransition = function (num1, num2) { // Clean up - stop other jobs if (this.transtimer[num1]) { clearTimeout(this.transtimer[num1]); } if (this.transtimer[num2]) { clearTimeout(this.transtimer[num2]); } // Clean up - set others to default state for (i = 1; i <= this.numof; i++) { if (i != num2) { document.getElementById('slide_'+i).style.display = 'none'; document.getElementById('slidethumb_'+i).style.borderBottom = '1px solid #e6e6e6'; this.setTransparency('slidethumb_'+i, 4); } } // Set current states document.getElementById('slide_'+num2).style.display = 'block'; document.getElementById('slidethumb_'+num2).style.borderBottom = '5px solid #e6e6e6'; this.setTransparency('slidethumb_'+num2, 10); } return this; }