/* Class: Rotator Author: Martin Cadorette Website: http://farao.org Version: 0.0.1 Date: 2009/11/17 Built For: MooTools 1.2 */ var Rotator = new Class({ //implements Implements: [Options, Events], //options options: { fixPngForIe : 1, // In styles.css defaultSlide: '1', // Starting Slide totalSlides: '4', // Total number of Slides switchOn: 'over', // When to switch Slide (click | over) delay: '500', // Delay between each rotation transMethod: 'easeOut', // Possible value: ease, bounce, elastic, linear, quad, cubic, quart, quint, pow, expo, circ, sine, back. // combined with: Out, In or InOut transType: 'fade', // Possible value: fade, reveal, morph, slideLeft, slideRight, slideUp, slideDown transDuration: '2000', transDurationIn: '2000', transDurationOut: '2000' }, //initialization initialize: function(element, options) { //set options //alert("Initi 2"); this.element = $(element); this.setOptions(options); this.options.element = $$(this.options.element); maxSlides = this.options.totalSlides; maxConts = this.element.getElements("*[class*=rot_content]").length; maxButs = this.element.getElements("*[class*=rot_button]").length; if (maxSlides>maxConts) {maxSlides=maxConts;} if (maxSlides>maxButs) {maxSlides=maxButs;} this.maxSlides = maxSlides; //maxSlides = maxSlides; new Element('input', {id: 'sel_rotSlide', type: 'hidden', value: this.options.defaultSlide}).injectInside(this.element) new Element('input', {id: 'sel_rotTotal', type: 'hidden', value: maxSlides}).injectInside(this.element) var coorMain = $("rot_content_1").getCoordinates(); this.element.getElements("*[class*=rot_content]").each(function(el) { el.setStyles({visibility: 'hidden', position: 'absolute', opacity: 0, top: coorMain['y'], left: coorMain['x']}); }, this); this.show(this.options.defaultSlide); $("rot_button_"+this.options.defaultSlide).removeClass("rot_button").addClass("rot_button_on"); if (this.options.delay>0) {myTimer = this.switchSlide.periodical(this.options.delay);} for (i=1; i<=maxSlides; i++) { if (this.options.switchOn=="over") { this.element = $("rot_button_"+i).addEvents({ 'mouseover' : this.pause.bind(this,i), 'mouseout' : this.resume.bind(this,i) }); } if (this.options.switchOn=="click") { this.element = $("rot_button_"+i).addEvents({ 'click' : this.show.bind(this,i), 'mouseover' : this.over.bind(this,i), 'mouseout' : this.resume.bind(this,i) }); } this.element = $("rot_content_"+i).addEvents({ 'mouseover' : this.pause.bind(this,i), 'mouseout' : this.resume.bind(this,i) }); } /* if(this.options.display.fixPngForIe) this.fixIeStuffs(); document.addEvent('mousewheel', function(){ this.isScrolling = false; }.bind(this)); */ }, pause: function(el) { if (myTimer) {$clear(myTimer);} myTimer = null; for (i=1; i<=this.maxSlides; i++) {if (i!=el) {this.hide(i);}} this.show(el); }, resume: function(el) { $("rot_button_"+el).removeClass("rot_button_over"); if (this.options.delay>0) {myTimer = this.switchSlide.periodical(this.options.delay);} }, hide: function(el) { if ($("rot_content_"+el).getStyle("visibility")!="hidden" || $("rot_content_"+el).getStyle("opacity")!="0") { $("rot_button_"+el).removeClass("rot_button_on").addClass("rot_button"); $("rot_content_"+el).fade("out"); } }, show: function(el) { //alert("Show #"+el); for (i=1; i<=this.maxSlides; i++) {if (i!=el) {this.hide(i);}} $("rot_button_"+el).removeClass("rot_button").addClass("rot_button_on"); $("rot_content_"+el).fade("in"); $("sel_rotSlide").value = el; // Reveal http://mootools.net/docs/more/Fx/Fx.Reveal // Slide http://mootools.net/docs/more/Fx/Fx.Slide // Morph http://mootools.net/docs/core/Fx/Fx.Morph }, over: function(el) { //alert("Over #"+el); for (i=1; i<=this.maxSlides; i++) {if (i!=el) {this.hide(i);}} $("rot_button_"+el).removeClass("rot_button").addClass("rot_button_on"); $("rot_button_"+el).addClass("rot_button_over"); $("sel_rotSlide").value = el; }, switchSlide: function() { totSld = $("sel_rotTotal").value; for (i=1; i<=totSld; i++) { $("rot_button_"+i).removeClass("rot_button_on").addClass("rot_button"); if ($("rot_content_"+i).getStyle("visibility")!="hidden") {$("rot_content_"+i).fade("out");} } sCur = parseInt($("sel_rotSlide").value)+1; if (sCur>totSld) {sCur=1;} if (sCur==2) { tSel = $("rot_content_2_image").get("src").split("_"); tSel = parseInt(tSel[(tSel.length-1)][0]); //alert(tSel); var rand=Math.floor(Math.random()*5)+1; if (tSel==rand) {tSel=tSel+1;} if (tSel>6) {tSel=1;} $("rot_content_2_image").set("src","images/rotator/buyers_image_"+rand+".gif"); } $("sel_rotSlide").value = sCur; $("rot_button_"+sCur).removeClass("rot_button").addClass("rot_button_on"); $("rot_content_"+sCur).fade("in"); //alert("Switching to #"+sCur); }, fixIeStuffs : function () { if (Browser.Engine.trident4) { //We fix png stuffs var rpng = new RegExp('url\\(([\.a-zA-Z0-9_/:-]+\.png)\\)'); var search = new RegExp('(.+)formcheck\.css'); for (var i = 0; i < document.styleSheets.length; i++){ if (document.styleSheets[i].href.match(/styles\.css$/)) { var root = document.styleSheets[i].href.replace(search, '$1'); var count = document.styleSheets[i].rules.length; for (var j = 0; j < count; j++){ var cssstyle = document.styleSheets[i].rules[j].style; var bgimage = root + cssstyle.backgroundImage.replace(rpng, '$1'); if (bgimage && bgimage.match(/\.png/i)){ var scale = (cssstyle.backgroundRepeat == 'no-repeat') ? 'crop' : 'scale'; cssstyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, src=\'' + bgimage + '\', sizingMethod=\''+ scale +'\')'; cssstyle.backgroundImage = "none"; } } } } } } });