var WJAnimation=Class.create({initialize:function(container,options){this.container=$(container);this.initAnimation(options);},initAnimation:function(options){var defaultSpeed=5;var defaultSmoothness=50;this.options=options||{};this.options.speed=this.options.speed||defaultSpeed;this.options.smoothness=this.options.smoothness||defaultSmoothness;},animate:function(goal){clearInterval(this.animating);this.goal=goal;this.loc={x:this.container.offsetLeft,y:this.container.offsetTop};this._calculateSpeed();this.animating=this.move.bind(this).repeat(this.options.smoothness/1000);},_calculateSpeed:function(){var angle=Math.atan((this.loc.x-this.goal.x)/(this.loc.y-this.goal.y));this.options.xspeed=this.options.speed*Math.sin(angle);this.options.yspeed=this.options.speed*Math.cos(angle);},move:function(){this.loc=this.getLocation(this.loc);var done=(this.loc.x==this.goal.x)&&(this.loc.y==this.goal.y);this.container.setStyle({"left":this.loc.x+"px","top":this.loc.y+"px"});if(typeof(this.options.onAnimateStep)=="function"){this.options.onAnimateStep(this.loc,this.goal);}
if(done){clearInterval(this.animating);if(typeof(this.options.onEndAnimate)=="function"){this.options.onEndAnimate(this.goal);}}},stop:function(){clearInterval(this.animating);},getLocation:function(cur){var newloc={x:cur.x+this.options.xspeed,y:cur.y+this.options.yspeed};var diffs={ox:(cur.x-this.goal.x),x:(newloc.x-this.goal.x),oy:(cur.y-this.goal.y),y:(newloc.y-this.goal.y)};if((this._getSign(diffs.ox)!=this._getSign(diffs.x))){newloc.x=this.goal.x;}
if((this._getSign(diffs.oy)!=this._getSign(diffs.y))){newloc.y=this.goal.y;}
return newloc;},_getSign:function(val){return(val>0)?1:((val<0)?-1:0);}});var WJSlowingAnimation=Class.create(WJAnimation,{_calculateSpeed:function(){this.options.xspeed=this.options.speed;this.options.yspeed=this.options.speed;},initAnimation:function($super,options){$super(options);var defaultSnap=0.5;this.options.snap=this.options.snap||defaultSnap;},getLocation:function(cur){var newloc={x:cur.x+((this.goal.x-cur.x)/this.options.speed),y:cur.y+((this.goal.y-cur.y)/this.options.speed)};if(Math.abs(this.goal.x-cur.x)<this.options.snap){newloc.x=this.goal.x;}
if(Math.abs(this.goal.y-cur.y)<this.options.snap){newloc.y=this.goal.y;}
return newloc;}});var WJSlowingConstantAnimation=Class.create(WJSlowingAnimation,{initAnimation:function($super,options){$super(options);var defaultConstant=25;this.options.constfrom=this.options.constfrom||defaultConstant;},getLocation:function(cur){this.xspeed=Math.abs(this.goal.x-cur.x)<this.options.constfrom?this.xspeed:(this.goal.x-cur.x)/this.options.speed;this.yspeed=Math.abs(this.goal.y-cur.y)<this.options.constfrom?this.yspeed:(this.goal.y-cur.y)/this.options.speed;var newloc={x:cur.x+this.xspeed,y:cur.y+this.yspeed};if((Math.abs(this.goal.x-cur.x)<this.options.snap)||(this._getSign(this.goal.x-cur.x)!=this._getSign(this.goal.x-newloc.x))){newloc.x=this.goal.x;}
if((Math.abs(this.goal.y-cur.y)<this.options.snap)||(this._getSign(this.goal.y-cur.y)!=this._getSign(this.goal.y-newloc.y))){newloc.y=this.goal.y;}
return newloc;}});var WJBoursinAnimation=Class.create(WJSlowingConstantAnimation,{initialize:function($super,container,options){var options=options||{};options=$H(options).merge({snap:1,constfrom:25,speed:5,smoothness:50}).toObject();$super(container,options);this.x=this.options.size*-1;this.goal={x:$(container).offsetLeft,y:$(container).offsetTop};this.pause=false;},animate:function($super,direction){if(this.pause){}
else{var direction=direction||1;if(direction==-1){pageTracker._trackPageview("/animatie-vorige-recept.html");}
else if(direction==1){pageTracker._trackPageview("/animatie-volgende-recept.html");}
this.goal.x+=(direction*this.options.size);$super(this.goal);}},fixLocation:function(loc){if(!loc){this.goal.x-=this.options.size;this.container.setStyle({"left":this.goal.x+"px"});}},initAnimation:function($super,options){$super(options);var defaultSize=1010;this.options.size=this.options.size||defaultSize;}});var WJBoursinRecipes=Class.create({initialize:function(container,divsize,boursintop){this.container=container;this.divsize=divsize;this.boursintop=boursintop;this.recipes=new Array();this.currecipe=-1;this.spin=new WJSpin();this._triedRecipe=0;this.url=new WJUrl({ct:"wmdynamic",dt:"toprecipes",module:"Wmrecipeboursin",mode:"top",offset:0,count:3,"wmtrigger[]":["requestufts"]});},loadRecipes:function(query,category,collection,kind,course,persons,preperation,product,sortby){this.registerLoadedRecipes();if(this.recipes.length==0){this._loadRecipes(query,category,collection,kind,course,persons,preperation,product,sortby);}
else{this._replaceRecipes(query,category,collection);}},_loadRecipes:function(query,category,collection,kind,course,persons,preperation,product,sortby){this.container.setStyle({"position":"absolute","width":(3*this.divsize)+"px","left":(-1*this.divsize)+"px"});this.url.addParameter("collection",collection);this.spin.content(this.url,[this.container,this.boursintop.createMainAnimation.bind(this.boursintop),this.boursintop.activateNavigation.bind(this.boursintop),this.boursintop.loadHeaders.bind(this.boursintop),function(){this.boursintop.started=true;}.bind(this)]);this.lastLeftOffset=0;this.lastRightOffset=2;},registerLoadedRecipes:function(){var formobj=$(document.loadedrecipes).serialize(true);if(formobj.loadedid){this.recipes=formobj.loadedid;var recipeindex=(-1*this.container.offsetLeft)/this.divsize;this.currecipe=parseInt(this.recipes[recipeindex]);}},showRecipe:function(id,callback,delay){this.registerLoadedRecipes();$$(".pos_viewrecipe").each(function(s){$(s).show();});$$(".pos_recipe"+id).each(function(s){$(s).hide();});var goalloc=-1;var curloc=-1;for(var i=0;(i<this.recipes.length)&&(goalloc==-1||curloc==-1);i++){if(this.recipes[i]==id){goalloc=i;}
if(this.recipes[i]==this.currecipe){curloc=i;}}
if(goalloc==-1&&(this._triedRecipe<3)){this._triedRecipe++;this._loadRecipe(id,true,callback,delay);}
else if(curloc!=goalloc){this.boursintop.mainAnimation.animate(curloc-goalloc);callback.delay(delay);}
else{callback.delay(delay);}},getCurrentIndex:function(){this.registerLoadedRecipes();for(var i=0;i<this.recipes.length;i++){if(this.recipes[i]==this.currecipe){return i;}}},_loadRecipe:function(id,scroll,callback,delay){this.url.addParameter("id",id);this.container.ajaxUpdateType="appendChild";this.container.setStyle({"width":(this.container.getWidth()+this.divsize)+"px"});var callbacks=[this.container,this.boursintop.activateNavigation.bind(this.boursintop),this.boursintop.loadHeaders.bind(this.boursintop)];if(scroll){callbacks.push(this.showRecipe.bind(this,id,callback,delay));}
this.spin.content(this.url,callbacks);this.url.deleteParameter("id");},addRecipe:function(loc){this.url.addParameter("count",1);if(loc){this.lastRightOffset++;this.url.addParameter("offset",this.lastRightOffset);this.container.ajaxUpdateType="appendChild";}
else{this.lastLeftOffset--;this.url.addParameter("offset",this.lastLeftOffset);this.container.ajaxUpdateType="prependChild";}
this.container.setStyle({"width":(this.container.getWidth()+this.divsize)+"px"});this.spin.content(this.url,[this.container,this.boursintop.mainAnimation.fixLocation.bind(this.boursintop.mainAnimation,loc),this.boursintop.activateNavigation.bind(this.boursintop),this.boursintop.loadHeaders.bind(this.boursintop)]);},_clearRight:function(){this.registerLoadedRecipes();var loadedRecipes=this.container.getElementsByClassName("pos_toprecipe");var removing=false;for(var i=0;i<loadedRecipes.length;i++){var recipe=loadedRecipes[i].getElementsByTagName("input")[0].value;if(removing){loadedRecipes[i].remove();}
else if(recipe==this.currecipe){removing=true;}}}});WJBoursinRecipes.loadRelatedRecipes=function(id,category,type,count){var category=category||"boursin";var type=type||"product";var count=count||1;var spin=new WJSpin();var url=new WJUrl({ct:"wmdynamic",dt:"relatedrecipes",module:"Wmrecipeboursin",id:id,mode:"relatedby"+type,category:category,type:"xml",count:count,"uft[]":"searchresult","disableuft[]":"aeroplane"});spin.content(url,[$$(".pos_relatedrecipes").first(),function(){var jslinks=$$(".pos_relatedrecipes").first().select(".javascript");if(jslinks){boursinNavigator.rewriteJavascriptLinks(jslinks);}}]);};var WJBoursinTop=Class.create({initialize:function(){this.started=false;this.observing=false;this.searchOpen=false;this.testOverlayObserver=this.testOverlay.bindAsEventListener(this);},start:function(container,category,collection,kind,course,persons,preperation,product,sortby){var kind=kind||"";var course=course||"";var persons=persons||"";var preperation=preperation||"";var product=product||"";var sortby=sortby||"";if(category==null){category="boursin";}
this.container=$(container);this.divsize=1010;if(document.loadedrecipes){this.recipes=new WJBoursinRecipes(this.container,this.divsize,this);this.recipes.loadRecipes({},category,collection,kind,course,persons,preperation,product,sortby);}},showRecipe:function(){if(this.started){$(window.document).stopObserving("mousemove",this.testOverlayObserver);this.observing=false;this.showOverlay();var id="";if(this.searchOpen){this.extendedSearchClick();}
if($("recipe_id")){id=$("recipe_id").getTextContent();this.recipes.showRecipe(id,this.hideOverlay.bind(this),3);}}
else{this.showRecipe.bind(this).delay(0.5);}},hideOverlay:function(){if(this.showAnimation){this.showAnimation.stop();}
if(this.hideAnimation){this.hideAnimation.stop();}
var elem=this.container.select(".pos_overlay")[this.recipes.getCurrentIndex()];if(!elem){return;}
this.hideAnimation=new WJSlowingConstantAnimation(elem,{snap:20,constfrom:50,speed:20});this.hideAnimation.animate({x:elem.offsetLeft,y:297});this.lastAction=="hide";if(!this.observing){$(window.document).observe("mousemove",this.testOverlayObserver);this.observing=true;}},testOverlay:function(e){if(this.searchOpen){return;}
if(e.pointerY()>this.container.getHeight()){if(!this.lastAction!="hide"){this.hideOverlay();}}
else{if(!this.lastAction!="show"){this.showOverlay();}}},showOverlay:function(e){if(this.hideAnimation){this.hideAnimation.stop();}
if(this.showAnimation){this.showAnimation.stop();}
this.lastAction=="show";var elem=this.container.select(".pos_overlay")[this.recipes.getCurrentIndex()];if(!elem){return;}
this.showAnimation=new WJSlowingConstantAnimation(elem,{snap:1,constfrom:50,speed:10});this.showAnimation.animate({x:elem.offsetLeft,y:0});},activateNavigation:function(response){$A(this.container.select(".pos_nextrecipe")).each(function(s){$(s).observe("click",this.mainAnimation.animate.bind(this.mainAnimation,-1));$(s).observe("mouseover",function(){$(this.getElementsByTagName("img").item(0)).src=$(this.getElementsByTagName("img").item(0)).src.replace("pijlnaarrechts.","pijlnaarrechtson.");}.bind(s));$(s).observe("mouseout",function(){$(this.getElementsByTagName("img").item(0)).src=$(this.getElementsByTagName("img").item(0)).src.replace("pijlnaarrechtson.","pijlnaarrechts.");}.bind(s));}.bind(this));$A(this.container.select(".pos_previousrecipe")).each(function(s){$(s).observe("click",this.mainAnimation.animate.bind(this.mainAnimation,1));$(s).observe("mouseover",function(){$(this.getElementsByTagName("img").item(0)).src=$(this.getElementsByTagName("img").item(0)).src.replace("pijlnaarlinks.","pijlnaarlinkson.");}.bind(s));$(s).observe("mouseout",function(){$(this.getElementsByTagName("img").item(0)).src=$(this.getElementsByTagName("img").item(0)).src.replace("pijlnaarlinkson.","pijlnaarlinks.");}.bind(s));}.bind(this));$A(this.container.select(".pos_viewrecipe")).each(function(s){$(s).observe("click",function(){document.location.href=$(s).getElementsByTagName("input")[0].value}.bind(s));});},extendedSearchClick:function(e){var elem=$("quicksearch");if(!elem.hasClassName("pos_open")){pageTracker._trackPageview("/open-uitgebreid-zoeken.html");this.searchOpen=true;elem.addClassName("pos_open stl_open");this.oldY=elem.offsetTop;if(this.recipes){var animation=new WJSlowingConstantAnimation(elem,{snap:10,constfrom:30,onEndAnimate:this.switchButton.bind(this,elem.select(".pos_extendedsearchbutton"),"/images/receptenzoekeromlaag.gif"),onAnimateStep:this.resizeInformation.bind(this,elem,true)});animation.animate({x:elem.offsetLeft,y:141});}
else{var animation=new WJSlowingConstantAnimation(elem,{snap:10,constfrom:30,onEndAnimate:this.switchButton.bind(this,elem.select(".pos_extendedsearchbutton"),"/images/receptenzoekeromhoog.gif"),onAnimateStep:this.resizeRecipeSearch.bind(this,elem,true)});animation.animate({x:elem.offsetLeft,y:413});}}
else{this.searchOpen=false;pageTracker._trackPageview("/sluiten-uitgebreid-zoeken.html");elem.removeClassName("pos_open stl_open");if(this.recipes){var animation=new WJSlowingConstantAnimation(elem,{snap:10,constfrom:30,onEndAnimate:this.switchButton.bind(this,elem.select(".pos_extendedsearchbutton"),"/images/receptenzoekeromhoog.gif"),onAnimateStep:this.resizeInformation.bind(this,elem,false)});animation.animate({x:elem.offsetLeft,y:this.oldY});}
else{var animation=new WJSlowingConstantAnimation(elem,{snap:10,constfrom:30,onEndAnimate:this.switchButton.bind(this,elem.select(".pos_extendedsearchbutton"),"/images/receptenzoekeromlaag.gif"),onAnimateStep:this.resizeRecipeSearch.bind(this,elem,true)});animation.animate({x:elem.offsetLeft,y:this.oldY});}}},resizeRecipeSearch:function(search,opening,loc,goal){var div=search.up();var flowdiv=$$(".pos_recipesearchflow")[0];var flowdivheight=flowdiv.getHeight()+(loc.y+56)-div.getHeight();div.setStyle({"height":(loc.y+56)+"px"});flowdiv.setStyle({"height":flowdivheight+"px"});$A(div.select(".pos_layer")).each(function(opening,s){if(opening){$(s).setStyle({"top":((loc.y-this.oldY+56)*-1)+"px","height":(loc.y-this.oldY)+"px"});}
else{$(s).setStyle({"top":((loc.y-this.oldY)*-1)+"px","height":(loc.y-this.oldY)+"px"});}}.bind(this,opening));},resizeInformation:function(elem,opening,loc,goal){if(opening){$A($(elem).up().select(".pos_information")).each(function(s){$(s).setStyle({"height":Math.max(0,(loc.y-goal.y-6))+"px"});});if(loc.y<=300){$$(".pos_viewrecipe").each(function(s){$(s).hide();});}
if(loc.y<=190){$$(".pos_previousrecipe").each(function(s){$(s).hide();});}
if(loc.y<=160){$$(".pos_nextrecipe").each(function(s){$(s).hide();});}}
else{$A($(elem).up().select(".pos_information")).each(function(s){$(s).setStyle({"height":(goal.y-141-Math.abs(goal.y-loc.y))+"px"});});if(loc.y>=380){$$(".pos_viewrecipe").each(function(s){$(s).show();});}
if(loc.y>=210){$$(".pos_previousrecipe").each(function(s){$(s).show();});}
if(loc.y>=190){$$(".pos_nextrecipe").each(function(s){$(s).show();});}}},switchButton:function(divs,url){$A(divs).invoke("select","img").flatten().each(function(i){i.src=url;});$$(".pos_hr").each(function(s){$(s).toggle();});$$(".pos_extendedsearchlink").each(function(s){$(s).toggle();});},loadHeaders:function(response){this.showDelimeters.bind(this).delay(0.5);},showDelimeters:function(){$A(this.container.select(".pos_deli")).each(function(s){$(s).setStyle({"display":"inline"});});},checkNewRecipe:function(loc){if(loc.x==0){this.recipes.addRecipe(false);}
if(loc.x==(-1*(this.container.getWidth()-this.divsize))){this.recipes.addRecipe(true);}},doQuickSearch:function(e){boursinNavigator.navigateTo({ct:"wmdynamic",dt:"searchresult",module:"Wmrecipeboursin",mode:"dosearch",count:"10",category:"boursin",type:"xml",keyword:$("trefwoord").value,"wmtrigger[]":["requestufts"]});},createMainAnimation:function(){this.mainAnimation=new WJBoursinAnimation(this.container,{size:this.divsize,onEndAnimate:this.checkNewRecipe.bind(this)});}});var animation=new WJBoursinTop();
