//style Sheet Functions========================================================= //============================================================================== function setActiveStyleSheet(title) { var i, a, main; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) { a.disabled = true; if(a.getAttribute("title") == title) { a.disabled = false; } } } } function getActiveStyleSheet() { var i, a; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) { return a.getAttribute("title"); } } return null; } function getPreferredStyleSheet() { var i, a; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")) { return a.getAttribute("title"); } } return null; } function createCookie(name,value,days) { var expires; if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); expires = "; expires="+date.toGMTString(); } else { expires = ""; } document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)===' ') { c = c.substring(1,c.length); } if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length,c.length); } } return null; } //General Functions============================================================= //============================================================================== var backgrounds = new Array(); backgrounds[0] = "http://www.vabio.org/wp-content/themes/VaBio/images/masthead01.jpg"; backgrounds[1] = "http://www.vabio.org/wp-content/themes/VaBio/images/masthead02.jpg"; var delay = 7; var times = 5; function getNewClass(e) { var rand = Math.round(10*Math.random()) % 2; e.style.backgroundImage = "url(" + backgrounds[rand] + ")"; } function fadeOut(t, b) { new Effect.Opacity(t.id, { duration: 2.0, transition: Effect.Transitions.linear, from: 1.0, to: 0, delay: delay, queue: 'end', afterFinish: function () {getNewClass(t);} }); } function fadeIn(t, b) { new Effect.Opacity(t.id, { duration: 2.0, transition: Effect.Transitions.linear, from: 0, to: 1.0, delay: delay, queue: 'end', afterFinish: function () {getNewClass(b);} }); } function crossFade(c) { var divs = c.getElementsByTagName('div'); bottom = divs[0]; topp = divs[1]; for(var i = 0; i < times; i ++) { fadeOut(topp, bottom); fadeIn(topp, bottom); } } function checkform ( form ) { if (form.fEmail.value == "") { alert( "Please enter your email address." ); form.fEmail.focus(); return false ; } return true ; } //Behaviour rules=============================================================== //============================================================================== /* var myrules = { 'a' : function(element){ element.onclick = function(){ console.log('dude'); return false; } }, '.styleDefault' : function(element){ element.onclick = function(){ setActiveStyleSheet('default'); return false; } }, '.styleLarge' : function(element){ element.onclick = function(){ setActiveStyleSheet('Large Type'); return false; } }, '.styleHC' : function(element){ element.onclick = function(){ setActiveStyleSheet('High Contrast'); return false; } } }; Behaviour.register(myrules); Behaviour.addLoadEvent(function() { var cookie = readCookie("style"); var title = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet(title); //crossFade($('mastheadContainer')); }); */ // Behaviors =================================================================== //============================================================================== var ImageFader = Behavior.create({ initialize: function(settings) { this.settings = $H(); this.settings.duration = settings.duration; this.settings.period = settings.period; // set some styles real quick var image = this.element.select('img'); this.currentImage = image[0]; this.__stylize(); // get an array of images to rotate this.__getImages(); //run the periodical executer, there is a scope issue var scope = this; new PeriodicalExecuter(function(){scope.__fader();}, this.settings.period); //this.__fader(); }, // beautifully fade the images like a fox __fader : function() { // load next image and make sure it isn't the same one you have up there now this.images = this.__shuffle(this.images); if(this.currentImage.src.indexOf(this.images[0]) > 0) { src = this.images[1]; } else { src = this.images[0]; } var image = new Element('img', { src: this.imagePath + '/' + src, alt: '' }); this.nextImage = image; this.nextImage.setStyle({ display: 'none', position: 'absolute' }); this.element.appendChild(this.nextImage); // fade in next image var oldImage = this.currentImage; this.nextImage.appear({ duration: this.settings.duration, afterFinish: function() {oldImage.remove();} }); // save next image as current image this.currentImage = this.nextImage; }, // __fader // set some necessary styles __stylize : function() { // get the width and height needed var width = this.currentImage.getWidth(); var height = this.currentImage.getHeight(); // set the container's position this.element.setStyle({ position: 'relative', width: width + 'px', height: height + 'px' }); // set the images styles this.currentImage.setStyle({ position: 'absolute' }); }, // __stylize // get an array of images for this particular fader __getImages : function() { // get the image path var input = this.element.select('input.lh_imagePath'); input = input[0]; this.imagePath = input.value; // get the images (filenames) this.images = this.__pullImages(this.imagePath); }, // __getImages // currently pulls the images from a second hidden field. somehow this needs to // happen automatically. however it works it needs to return an array of image // names __pullImages : function() { var input = this.element.select('input.lh_images'); input = input[0]; input = input.value; input = input.split(','); return input; }, // __pullImages // shuffle an array, surely there is a built in for this? __shuffle : function(a) { var i = a.length; if ( i === 0 ) { return false; } while ( --i ) { var j = Math.floor( Math.random() * ( i + 1 ) ); var tempi = a[i]; var tempj = a[j]; a[i] = tempj; a[j] = tempi; } return a; } // __shuffle }); Event.addBehavior({ '.styleDefault:click' : function(e) { setActiveStyleSheet('default'); return false; }, '.styleLarge:click' : function(e) { setActiveStyleSheet('Large Type'); return false; }, '.styleHC:click' : function(e) { setActiveStyleSheet('High Contrast'); return false; }, '.lh_fader' : ImageFader({ duration: 3, period: 10 }) }); //General ====================================================================== //============================================================================== window.onunload = function(e) { var title = getActiveStyleSheet(); createCookie("style", title, 365); }; var cookie = readCookie("style"); var title = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet(title);