var d = 250; var language; var login = false; var dealersRedirect = false; window.addEvent('domready',function(){ Header(); setStoreLocator(); Newsletter(); $$('#search .search-submit > input').addEvent('mouseenter', function(){ this.morph({ 'background-color':'#ffffff', 'color':'#3e3e3e' }); }).addEvent('mouseleave', function(){ this.morph({ 'background-color':'#e66b50', 'color':'#ffffff' }); }); }); function Header(){ $$("#logo > .back-home-hover").set('tween', { duration: d , transition: Fx.Transitions.Expo.easeInOut } ); $$("#logo > .back-home-hover > *").set('morph', { duration: d , transition: Fx.Transitions.Expo.easeInOut } ).setStyles({ 'top':-30 , 'opacity':0 }); $("logo").addEvent('mouseenter',function(event){ var logo = this.getChildren(".back-home-hover"); logo.setStyle('top',0); this.getChildren(".back-home-hover > *").each(function(item,index){ item.morph.delay(index*100, item, { 'top':0 , 'opacity':1 } ); }); }).addEvent('mouseleave',function(event){ var logo = this.getChildren(".back-home-hover"); logo.setStyle('top',-80); this.getChildren(".back-home-hover > *").each(function(item,index){ (function(){ item.get('morph').cancel(); item.setStyles({ 'top':-30 , 'opacity':0 }); }).delay(index*100); }); }); $$("#sections > .item").each( function(item){ var span = new Element('span', { text: item.get('text') }); item.set('morph', { duration: 1000, transition: Fx.Transitions.Expo.easeInOut }).fade("hide"); item.set('text', '').grab(span, 'bottom').grab(span.clone().set('class', 'active'), 'bottom'); if(document.location.pathname.indexOf(item.get("href")) == -1) { item.getFirst().set('tween', { duration: 300, transition: Fx.Transitions.Expo.easeInOut }); item.addEvent('mouseenter', span.tween.bind(span, ['margin-top', -32])); item.addEvent('mouseleave', span.tween.bind(span, ['margin-top', 0])); } else span.setStyle("margin-top", -32); }); $$("#sections > .item").each(function(item, i){ item.fade.delay(100 * i, item, 1); }); $$("#languages > ul > li.inactive").setStyle('margin-top',-55).set('tween', { duration: 500 , transition: Fx.Transitions.Expo.easeInOut } );; $$("#languages > ul").addEvent('mouseenter',function(){ this.getChildren("li.inactive").tween('marginTop',0); clearInterval(language); this.setStyle('height',225); }).addEvent('mouseleave',function(){ this.getChildren("li.inactive").tween('marginTop',-55); var self = this; language = setTimeout( function(){ self.setStyle('height',35); } ,300); }); $$('#credits > li').set('tween', { duration: d , transition: Fx.Transitions.Expo.easeInOut } ); $$("#credits").addEvent('mouseenter',function(){ this.getChildren("li.item").each(function(el,index){ el.tween.delay( ( 5 - index ) * 50 , el , [ 'bottom', 27 * ( 5 - index ) + 6 ] ); }); clearInterval(language); this.setStyle('height',185); }).addEvent('mouseleave',function(){ this.getChildren("li.item").each(function(el,index){ el.tween('bottom', - 27); }); var self = this; language = setTimeout( function(){ self.setStyle('height',27); } ,300); }); $('login-form').setStyles({ 'display' : 'block', 'opacity':0, 'top': 126 }).set('morph', { duration: 400 , transition: Fx.Transitions.Expo.easeInOut } ); $$('#options > .dealers').addEvent('click', function(event){ event.stop(); if(!dealersRedirect){ new Fx.Scroll(window, { duration: 1000, transition: Fx.Transitions.Quint.easeInOut, offset: { y:-50 } }).toElement('store_locator'); var waiting = setInterval( function(){ $('find-form').tween('background-color','#e66b50'); ( function(){ $('find-form').tween('background-color','#606060'); } ).delay(300); },600); setTimeout(function(){ waiting && clearInterval(waiting); },2500); } else { location.href = 'home?find_dealers'; } }); $$('#options .login').addEvent('click',function(event){ event.stop(); if(login){ $('login-form').morph({ 'opacity':0, 'top': 126 }); login = false; } else { $('login-form').morph({ 'opacity':1, 'top': 63 }); login = true; } }); $$('#login-form .submit').addEvent('click',function(event){ event.stop(); var Req = new Request.JSON({ url:'login', onSuccess: function(json){ if(json.logged){ $$('#login-form > .login').tween('height',0); } else { $('response-login').set('text','wrong username/password'); } } }).post({ 'username': $$('#login-form .username')[0].get('value'), 'password': $$('#login-form .password')[0].get('value'), 'submit': 'Login' }); }); $$("input").each(function(el){ var defaultTxt = el.get('value'); el.addEvent('blur',function(){ if(this.get('value') == '') this.set('value',defaultTxt); }).addEvent('focus',function(){ if(this.get('value') == defaultTxt) this.set('value',''); }); }); } var actualStore; var totalStore; var stores = []; var pause = false; function setStoreLocator(){ $('store_locator').addEvent('submit',function(e){ e.stop(); storeLocator(); }); $('store-paginator').fade('out'); $('total-store').addEvent('click',function(e){ stores[(actualStore%totalStore)].tween('left',-290); actualStore++; stores.each( function(i){ i.setStyle('left',290); } ); $('actual-store').set( 'text' , actualStore%totalStore+1 ); stores[(actualStore%totalStore)].tween('left',0); }); $('actual-store').addEvent('click',function(e){ stores[(actualStore%totalStore)].tween('left',290); actualStore -= 1; stores.each( function(i){ i.setStyle('left',-290); } ); $('actual-store').set( 'text' , actualStore%totalStore+1 ); stores[(actualStore%totalStore)].tween('left',0); }); } function storeLocator() { var geocoder = new google.maps.Geocoder(); var address = $('user_address').get('value'); geocoder.geocode({'address':address},function(results,status){ if(status==google.maps.GeocoderStatus.OK){ if (!pause){ pause = true; $('store-paginator').fade('out'); $('store-container').getChildren(".store").dispose(); var waiting = setInterval( function(){ $('find-form').tween('background-color','#484848'); ( function(){ $('find-form').tween('background-color','#606060'); } ).delay(600); },1200); var div = new Element( 'div.store' ); new Element( 'h5' , { html:'Searching stores:' } ).inject( div ); new Element( 'p' , { html:address + '...' } ).inject( div ); div.set('tween', { duration: d , transition: Fx.Transitions.Expo.easeInOut } ).inject( $('store-container') ).tween( 'left' , 0 ); var Req = new Request.JSON({ url:'store.locator', onSuccess: function(json){ waiting && clearInterval(waiting); if(json.stores.length > 0){ stores = []; $('store-container').getChildren(".store").dispose(); json.stores.each( function(item){ var div = new Element( 'div.store' ); new Element( 'h5' , { html:item.name } ).inject( div ); new Element( 'p' , { html:item.address } ).inject( div ); new Element( 'span' , { html:item.tel_website } ).inject( div ); div.set('tween', { duration: d , transition: Fx.Transitions.Expo.easeInOut } ).inject( $('store-container') ); stores.push( div ); }); stores[0].tween( 'left' , 0 ); actualStore = json.stores.length * 100; totalStore = json.stores.length; $('total-store').set( 'text' , totalStore ); $('actual-store').set( 'text' , '1' ); $('store-paginator').fade('in'); } else { stores = []; $('store-container').getChildren(".store").dispose(); var div = new Element( 'div.store' ); new Element( 'h5' , { html: address } ).inject( div ); new Element( 'p' , { html: 'No stores found near ' + address } ).inject( div ); div.set('tween', { duration: d , transition: Fx.Transitions.Expo.easeInOut } ).inject( $('store-container') ).tween( 'left' , 0 ); } pause = false; } }).post({ 'lat': results[0].geometry.location['Na'], 'lng': results[0].geometry.location['Oa'] }); } } }); } function Newsletter(){ $$("#newsletter-form > form").addEvent('submit', function(e){ e.stop(); var EmailAddress = $("newsletter_input").get('value'); var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if (filter.test(EmailAddress)) { var Req = new Request.HTML({ url:"../zoomail/subscriber/add.php", onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){ $("newsletter_input").set('value',responseHTML); } }).post({ 'EmailAddress': EmailAddress }); } }); }