function Settings(){this.top=0;this.right=737;this.bottom=1000;this.left=0;this.halfWidth=249;this.halfHeight=148;this.itemLeft=141;this.itemTop=-73}function BrandboxItem(){this.x=20;this.y=1;this.width=476;this.height=293}totalItems=brandboxJson.length;currentItem=0;settings=new Settings();brandboxItem=new BrandboxItem();var itemDivs,itemLinks;var paused=false;var disabled=false;var isOpened=false;var clickEnabled=true;$(function(){mapDiv=$("#brandboxMap");itemDivs=$("#brandboxItems > div");itemLinks=$("#brandbox > .items > a");mapDiv.hover(function(){paused=true},function(){paused=false});oldColor=$(itemLinks[0]).css("color");itemLinks.hover(function(){$(this).stop().animate({color:"#e97801"},250)},function(){if(currentItem!=parseInt($(this).data("index"))){$(this).stop().animate({color:oldColor},250)}});$.each(brandboxJson,function(a,d){var c=$("<div />");var b=$("<img />");c.attr("class","poi");c.css("top",this.Y-73);c.css("left",this.X-24);if(isRight(this.X)){c.attr("class",c.attr("class")+" right");c.css("left",this.X-77)}var e=$(itemDivs[a]);e.css("top",this.Y-50);e.css("left",this.X+(isRight(this.X)?-30:15));b.attr("src",this.ThumbnailUrl);c.append(b);mapDiv.prepend(c)});startAnimation(true)});var newX,newY,prevX,prevY,current,currentAniEl;function startAnimation(a){unbindClickEvent();current=brandboxJson[currentItem];newX=correctX((current.X*-1)+settings.halfWidth);newY=correctY((current.Y*-1)+settings.halfHeight+50);currentAniEl=$(itemDivs[currentItem]);mapDiv.animate({left:newX,top:newY},{duration:animationSpeed,complete:function(){prevX=currentAniEl[0].style.left;prevY=currentAniEl[0].style.top;isOpened=true;$(itemLinks[currentItem]).stop().animate({color:"#e97801"},animationSpeed2);currentAniEl.css("display","block").animate({left:brandboxItem.x+(newX*-1),top:brandboxItem.y+(newY*-1),width:brandboxItem.width,height:brandboxItem.height},{duration:animationSpeed2,step:function(d,b){var c=currentAniEl.find("div.center");c.css("left",-((brandboxItem.width/2)*(1-b.pos)));c.css("top",-((brandboxItem.height/2)*(1-b.pos)))},complete:function(){if(!clickEnabled){bindClickEvent()}setTimeout(function(){endAnimation(a)},5000)}})}})}function endAnimation(b,a){currentAniEl=$(itemDivs[currentItem]);if((!paused&&!disabled)||a){unbindClickEvent();isOpened=false;$(itemLinks[currentItem]).stop().animate({color:oldColor},animationSpeed2);currentAniEl.animate({left:prevX,top:prevY,width:0,height:0},{duration:animationSpeed2,step:function(e,c){var d=currentAniEl.find("div.center");d.css("left",-((brandboxItem.width/2)*(c.pos)));d.css("top",-((brandboxItem.height/2)*(c.pos)))},complete:function(){currentAniEl.css("display","none");if(b){currentItem++;if(currentItem==totalItems){currentItem=0}}if(!disabled&&b){startAnimation(b)}}})}else{if(!disabled){setTimeout(function(){endAnimation(currentAniEl)},5000)}}}function bindClickEvent(){clickEnabled=true;itemLinks.bind("click",function(b){var a=parseInt($(b.currentTarget).data("index"));if(a!=currentItem){unbindClickEvent();disabled=true;if(isOpened){endAnimation(false,true)}currentItem=a;startAnimation()}})}function unbindClickEvent(){clickEnabled=false;itemLinks.unbind("click")}function isRight(a){return a>(settings.right/2)}function correctX(a){if(a>60){return 60}else{if(a<-270){return -270}else{if(!isRight(a)){return a-30}else{if(isRight(a)){return a+30}}}}return a}function correctY(a){if(a>77){return 77}else{if(a<-720){return -720}}return a};
