var CategoryNav=new Class({Implements:[Events,Options],options:{onActive:Class.empty,openIndex:0},initialize:function(d,c){this.setOptions(c);this.container=$(d);this.menu=this.container.getChildren("ul");this.hoverToggle=true;if($("current_category")){this.options.openIndex=$$("#"+d+" .toggler").indexOf($("current_category").getElements(".toggler")[0]).toInt()}this.hoverComingSoon=new Element("div",{id:"hover_coming_soon"}).inject(document.body);this.hoverGreen=new Element("div",{id:"hover_green"}).inject(document.body);this.hoverOrange=new Element("div",{id:"hover_orange"}).inject(document.body);this.container.getElements("span").addEvents({mouseover:function(a){if(this.hoverToggle){var b=$(a.target);this.updateHover(b)}}.bind(this),mouseleave:function(a){if(this.hoverToggle){this.hideHover()}}.bind(this)});this.menu.setStyle("overflow","hidden");this.accordion=new Accordion($$("#"+d+" .toggler"),$$("#"+d+" .list"),{alwaysHide:false,show:this.options.openIndex,onActive:function(f,a){var b=$$("#"+d+" .toggler").indexOf(f);this.fireEvent("onActive",b);this.hideHover();this.hoverToggle=false;(function(){this.hoverToggle=true}.bind(this)).delay(500);f.getParent().addClass("selected")}.bind(this),onBackground:function(a,b){this.hideHover();this.hoverToggle=false;(function(){this.hoverToggle=true}.bind(this)).delay(500);a.getParent().removeClass("selected")}.bind(this)})},updateHover:function(d){var c=d.getCoordinates();if(Browser.Engine.trident||Browser.Engine.webkit419){c=d.getCoordinates("logo")}if(d.hasClass("hover_coming_soon")){this.hoverComingSoon.setStyles({top:c.top-5,left:c.right+5,visibility:"visible",display:"block"})}else{if(d.hasClass("hover_orange")){this.hoverOrange.setStyles({top:c.top,left:c.left-26,visibility:"visible",display:"block"})}}if(d.hasClass("hover_green")){this.hoverGreen.setStyles({top:c.top,left:c.left-32,visibility:"visible",display:"block"})}},hideHover:function(){this.hoverComingSoon.setStyles({top:0,left:0,visibility:"hidden",display:"none"});this.hoverOrange.setStyles({top:0,left:0,visibility:"hidden",display:"none"});this.hoverGreen.setStyles({top:0,left:0,visibility:"hidden",display:"none"})}});var ProductViewer=new Class({Implements:[Events,Options],options:{showName:true,transitionDuration:1000,focusHeight:220,normalHeight:100},initialize:function(h,e){this.setOptions(e);this.currentIndex=0;this.firstRun=true;if(Browser.Engine.webkit419){this.element=$(h).clone();this.element.set("id",$(h).get("id"));this.element.addClass("script");this.element.replaces(h)}else{this.element=$(h);this.element.addClass("script")}this.viewport=this.element.getElement(".viewport");this.listChildren=this.viewport.getElement("ul").getChildren();this.element.setStyle("opacity",0);this.loadingElement=new Element("div",{id:"product_viewer_loading"}).inject(this.element,"after");this.loadingElement.setStyles({top:this.element.getStyle("top").toInt(),left:this.element.getStyle("left").toInt()});var f=this.listChildren.getElements("img");var g=new Array();f.each(function(a,b){g[b]=a.get("src")});new Asset.images(g,{onProgress:function(b,a){this.loadingElement.set("html","loading "+(b+1)+"/"+g.length)}.bind(this),onComplete:function(){this.loadingElement.destroy();this.element.tween("opacity",1);this.afterLoad()}.bind(this)})},afterLoad:function(){if(this.options.showName){this.name=new Element("div").addClass("name").set("html","&nbsp;").inject(this.element,"top")}this.viewportScroll=new Fx.Scroll(this.viewport,{wheelStops:false,link:"cancel",transition:Fx.Transitions.Sine.easeInOut,duration:this.options.transitionDuration});this.previousElement=new Element("div").set("id","previous").inject(this.viewport,"before").addEvent("click",function(){this.previous()}.bind(this));this.nextElement=new Element("div").set("id","next").inject(this.viewport,"after").addEvent("click",function(){this.next()}.bind(this));this.listChildren.each(function(a){a.getElement("img").setStyles({height:this.options.normalHeight+"px","margin-top":(this.options.focusHeight-this.options.normalHeight)/2+"px"})}.bind(this));var b=this.options.focusHeight/this.options.normalHeight;this.listChildren.each(function(k){var h=k.getCoordinates(this.viewport).left;var j=k.getSize().x;var l=j*b;var a=((l/2)+h).toInt();k.store("center",a);var i=new Fx.Morph(k.getElement("img"),{duration:this.options.transitionDuration,link:"cancel"});k.store("effect",i)}.bind(this));if($chk($("selected"))){this.currentIndex=this.listChildren.indexOf($("selected"))}this.update("next");this.setControls()},previous:function(){if(this.currentIndex!=0){this.currentIndex--;this.update("previous");this.setControls()}},next:function(){if(this.currentIndex!=this.listChildren.length-1){this.currentIndex++;this.update("next");this.setControls()}},setControls:function(){if(this.currentIndex==0){this.previousElement.addClass("last")}else{this.previousElement.removeClass("last")}if(this.currentIndex<this.listChildren.length-1){this.nextElement.removeClass("last")}else{this.nextElement.addClass("last")}},update:function(c){try{if(this.firstRun){this.listChildren[this.currentIndex-2].retrieve("effect").set({height:this.options.normalHeight+"px","margin-top":(this.options.focusHeight-this.options.normalHeight)/2+"px",opacity:0})}else{this.listChildren[this.currentIndex-2].retrieve("effect").start({height:this.options.normalHeight+"px","margin-top":(this.options.focusHeight-this.options.normalHeight)/2+"px",opacity:0})}}catch(d){}try{if(this.firstRun){this.listChildren[this.currentIndex-1].retrieve("effect").set({height:this.options.normalHeight+"px","margin-top":(this.options.focusHeight-this.options.normalHeight)/2+"px",opacity:1})}else{this.listChildren[this.currentIndex-1].retrieve("effect").start({height:this.options.normalHeight+"px","margin-top":(this.options.focusHeight-this.options.normalHeight)/2+"px",opacity:1})}}catch(d){}if(this.firstRun){centerElement=this.listChildren[this.currentIndex].retrieve("effect").set({height:this.options.focusHeight+"px","margin-top":"0px",opacity:1})}else{centerElement=this.listChildren[this.currentIndex].retrieve("effect").start({height:this.options.focusHeight+"px","margin-top":"0px",opacity:1})}try{if(this.firstRun){this.listChildren[this.currentIndex+1].retrieve("effect").set({height:this.options.normalHeight+"px","margin-top":(this.options.focusHeight-this.options.normalHeight)/2+"px",opacity:1})}else{this.listChildren[this.currentIndex+1].retrieve("effect").start({height:this.options.normalHeight+"px","margin-top":(this.options.focusHeight-this.options.normalHeight)/2+"px",opacity:1})}}catch(d){}try{if(this.firstRun){this.listChildren[this.currentIndex+2].retrieve("effect").set({height:this.options.normalHeight+"px","margin-top":(this.options.focusHeight-this.options.normalHeight)/2+"px",opacity:0})}else{this.listChildren[this.currentIndex+2].retrieve("effect").start({height:this.options.normalHeight+"px","margin-top":(this.options.focusHeight-this.options.normalHeight)/2+"px",opacity:0})}}catch(d){}this.center()},center:function(){var b=this.listChildren[this.currentIndex].retrieve("center");if(this.firstRun){this.firstRun=false;this.viewportScroll.set(b-(this.viewport.getSize().x/2),0);if(this.options.showName){this.updateTitle()}}else{this.viewportScroll.start(b-(this.viewport.getSize().x/2),0);if(this.options.showName){this.updateTitle()}}},updateTitle:function(){var b=this.listChildren[this.currentIndex].getElement("div").get("html");this.name.set("html",b)}});var HoverScroller=new Class({Implements:[Events,Options],options:{duration:1000},initialize:function(d,f,e){this.setOptions(e);this.element=$(d);this.scrollable=this.element.getChildren(".scrollable")[0];this.state="stationary";this.scroller=new Fx.Scroll(this.scrollable,{duration:this.options.duration,transition:Fx.Transitions.Quad.easeIn});this.scrollable.setStyles({height:f,overflow:"hidden"});this.up=new Element("div",{"class":"scroll_up",html:"scroll up"}).inject(this.element,"before");this.up.addEvents({mouseover:function(){this.state="up";this.update()}.bind(this),mouseleave:function(){this.state="stationary";this.update()}.bind(this)});this.down=new Element("div",{"class":"scroll_down",html:"scroll down"}).inject(this.element,"after");this.down.addEvents({mouseover:function(){this.state="down";this.update()}.bind(this),mouseleave:function(){this.state="stationary";this.update()}.bind(this)})},update:function(){if(this.state=="down"){this.scroller.toBottom()}else{if(this.state=="up"){this.scroller.toTop()}else{if(this.state=="stationary"){this.scroller.cancel()}}}}});window.addEvent("domready",function(){(function(){var d=new Array();d[0]="/assets/category/grocery_and_cupboard.jpg";d[1]="/assets/category/fresh_produce.jpg";d[2]="/assets/category/meat_and_poultry.jpg";d[3]="/assets/category/dairy_and_beverage.jpg";d[4]="/assets/category/baby_food.jpg";d[5]="/assets/category/bakery.jpg";d[6]="/assets/interface/backgrounds/background.jpg";d[7]="/assets/interface/type/logo_natural.gif";d[8]="/assets/interface/type/logo.gif";new Asset.images(d);$("category_nav").addClass("script");var e=new CategoryNav("category_nav",{openIndex:-1});function f(b){var a=$("logo").getElement("img");if(b==2){if(a.get("src").contains(d[8])){a.get("tween",{property:"opacity",duration:200}).start(0).chain(function(){this.set("src",d[7]);this.tween("opacity",1)}.bind(a))}}else{if(a.get("src").contains(d[7])){a.get("tween",{property:"opacity",duration:200}).start(0).chain(function(){this.set("src",d[8]);this.tween("opacity",1)}.bind(a))}}}if($chk($("product_landing_page"))){e.addEvent("onActive",function(b){if(!$chk($("category_image"))){$$(".call_out").destroy();$("newest_products_heading").tween("opacity","0");$("coupons").tween("opacity","0");$(document.body).removeClass("background-newest_products");var a=new Element("div",{id:"category_image"});a.setStyle("opacity",0);a.adopt(new Element("img"));a.inject("category_nav_position","before")}$("category_image").get("tween",{property:"opacity",duration:200}).start(0).chain(function(){$$("#category_image img").set("src",d[b]);$("category_image").tween("opacity",1)});f(b)})}if($chk($("product_viewer_page"))){e.addEvent("onActive",function(b){if(!$chk($("category_image"))){$("product_viewer").destroy();viewer=null;$("sub_category_heading").destroy();var a=new Element("div",{id:"category_image"});a.setStyle("opacity",0);a.adopt(new Element("img"));a.inject("category_nav_position","before")}$("category_image").get("tween",{property:"opacity",duration:200}).start(0).chain(function(){$$("#category_image img").set("src",d[b]);$("category_image").tween("opacity",1)});f(b)});viewer=new ProductViewer("product_viewer",{showName:true,focusHeight:212,normalHeight:110})}if($chk($("product_details_page"))){e.addEvent("onActive",function(b){if(!$chk($("category_image"))){$("product_viewer").destroy();viewer=null;$("product_image").destroy();$("product_details").destroy();var a=new Element("div",{id:"category_image"});a.setStyle("opacity",0);a.adopt(new Element("img"));a.inject("category_nav_position","before")}$("category_image").get("tween",{property:"opacity",duration:200}).start(0).chain(function(){$$("#category_image img").set("src",d[b]);$("category_image").tween("opacity",1)});f(b)});if($chk($("nutritional"))){new HoverScroller("nutritional",145)}if($("detail_accordion").getChildren().length>2){$("detail_accordion").addClass("script");new Accordion($$("#detail_accordion h3"),$$("#detail_accordion .content"),{onActive:function(a,b){$$("#detail_accordion h3.down").removeClass("down");a.addClass("down")}})}else{$$("#detail_accordion h3").addClass("down");$("detail_accordion").addClass("script")}viewer=new ProductViewer("product_viewer",{showName:true,focusHeight:85,normalHeight:65})}})()});
