(function(A){A.fn.imageFlow=function(F){var T=this;
var X=A(A(this).find("#images img"));
var a=A(this).find("#images");
var H=A(this).find("#scrollbar");
var Q=A(this).find("#slider");
var M=A(this).find("#loading");
var B=A(this).find("#captions");
var c=A(this).find("#productinfo");
var K=A(this).find("#leftButton");
var R=a.get(0).offsetWidth;
var b=this.get(0).offsetTop;
var U=this.get(0).offsetLeft;
var O=4;
var D=149;
var P={images:X,imagesDiv:a,scrollBarDiv:H,sliderDiv:Q,loading:M,captionDiv:B,productInfo:c,leftButton:K,imagesWidth:R,imagesTop:b,imagesLeft:U,max:X.length,current:0,confReflectionP:0.5,xstep:D,confFocus:O,confSliderWidth:14*0.5,target:0,memTarget:0,timer:0,newPosX:0,captionId:0,dragX:0,posX:0,newSliderPos:0,confSliderCursor:"default",dragging:false,dragObject:null,maxConfFocus:O*D,size:400,scrollBarWidth:R*0.6,scrollBarMultiply:0.6,startAt:4,maxHeight:R*0.51,initMouseWheel:true,slideOnLoad:true};
P=A.extend(P,F);
P.loading.css("visibility","hidden");
P.loading.css("padding","0");
G();
P.scrollBarDiv.css("visibility","visible");
A("#leftButton").css("display","block");
A("#rightButton").css("display","block");
A("#imageflowbox").css("border-bottom","none");
A("#imageflowbox").css("margin-bottom","0");
A("#productinfo").css("display","block");
C();
if(P.initMouseWheel){V()
}if(P.slideOnLoad){E()
}window.onresize=function(){G()
};
function G(e){var d=0;
A(this).css("height",P.maxHeight+"px");
P.imagesWidth=P.imagesDiv.get(0).offsetWidth;
A(P.imagesDiv).css("height",P.imagesWidth*0.338+"px");
P.maxConfFocus=P.confFocus*P.xstep;
P.scrollBarWidth=P.imagesWidth*P.scrollBarMultiply;
P.maxHeight=P.imagesWidth*0.51;
P.scrollBarDiv.css("width",P.scrollBarWidth+"px");
P.sliderDiv.mousedown(function(){L(this)
});
P.sliderDiv.css("cursor",P.confSliderCursor);
P.max=P.images.length;
P.images.each(function(h){var g=this;
var f=A(g).attr("longdesc").split("(;)");
if(g.nodeType==1){g.onclick=function(){W(this.x_pos,this.i)
};
g.x_pos=(-d*P.xstep);
g.i=d;
g.w=g.width;
g.h=g.height;
g.pc=100;
g.url=f[0];
A(g).css("cursor","pointer");
d++
}});
P.max=P.images.length;
J(P.current);
W(P.current,P.captionId)
}function J(d){var e=P.max;
P.current=d;
P.images.each(function(f){var i=this;
var j=f*-P.xstep;
if((j+P.maxConfFocus)<P.memTarget||(j-P.maxConfFocus)>P.memTarget){i.style.visibility="hidden";
i.style.display="none"
}else{var l=Math.sqrt(10000+d*d)+100;
var g=d/l*P.size+P.size;
var o=(i.h/i.h*i.pc)/l*P.size;
A(i).css("display","block");
if(o<P.maxHeight){var h=i.pc/l*P.size
}else{o=P.maxHeight;
h=i.w*o/i.h
}var m=(P.imagesWidth*0.34-o)+P.imagesTop+((o/(P.confReflectionP+1))*P.confReflectionP);
var k=g-(i.pc/2)/l*P.size+P.imagesLeft+"px";
A(i).css("left",k);
if(h&&o){A(i).css("height",o+"px");
A(i).css("width",h+"px");
A(i).css("top",m+"px")
}else{A("body").append("image.w is "+i.w+"<br />")
}A(i).css("visibility","visible");
if(d<0){e++
}else{e=e-1
}if(i.i!=P.captionId){i.onclick=function(){W(this.x_pos,this.i)
}
}else{e=e+1;
i.onclick=function(){document.location=this.url
}
}i.style.zIndex=e
}d+=P.xstep
})
}function I(){if(P.target<P.current-1||P.target>P.current+1){J(P.current+(P.target-P.current)/3);
window.setTimeout(I,50);
P.timer=1
}else{P.timer=0
}}function W(d,e){P.target=d;
P.memTarget=d;
if(P.timer==0){window.setTimeout(I,50);
P.timer=1
}P.captionId=e;
caption=P.images[P.captionId].alt;
if(caption==""){caption="&nbsp;"
}P.captionDiv.html(caption);
var f=A(P.images[P.captionId]).attr("longdesc").split("(;)");
A("#productinfo .productinfo-link").attr("href",f[0]);
A("#productinfo .productinfo-price").attr("href",f[1]);
A("#productinfo .productinfo-shoplink").attr("href",f[1]);
A("#productinfo .productinfo-price").html(f[2]);
A("#productinfo .productinfo-shopname").html(f[3]);
A("#productinfo .productinfo-shopname").attr("href",f[1]);
A("#productinfo .deliverycosts").html(f[4]);
A("#productinfo .deliverycosts").attr("title",f[4]);
P.captionDiv.attr("title",caption);
P.captionDiv.attr("onClick","relocate('"+f[0]+"');");
if(P.dragging==false){P.newSliderPos=(P.scrollBarWidth*(-(d*100/((P.max-1)*P.xstep)))/100)-P.newPosX;
P.sliderDiv.css("marginLeft",(P.newSliderPos-P.confSliderWidth)+"px")
}}function C(){document.onmousemove=S;
document.onmouseup=N;
document.onselectstart=function(){if(P.dragging==true){return false
}else{return true
}}
}function S(h){var g,j,d,i,f;
P.posX=document.all?window.event.clientX:h.pageX;
if(P.dragObject!=null){P.dragging=true;
P.newPosX=(P.posX-P.dragX)+P.confSliderWidth;
if(P.newPosX<(-P.newSliderPos)){P.newPosX=-P.newSliderPos
}if(P.newPosX>(P.scrollBarWidth-P.newSliderPos)){P.newPosX=P.scrollBarWidth-P.newSliderPos
}g=(P.newPosX+P.newSliderPos);
j=g/((P.scrollBarWidth)/(P.max-1));
d=Math.round(j);
i=(d)*-P.xstep;
f=d;
P.dragObject.style.left=P.newPosX+"px";
W(i,f)
}}function L(d){P.dragObject=d;
P.dragX=P.posX-P.dragObject.offsetLeft+P.newSliderPos
}function N(){P.dragObject=null;
P.dragging=false
}function Z(e){var d=false;
if(e>0){if(P.captionId>=1){P.target=P.target+P.xstep;
newCaptionId=P.captionId-1;
d=true
}}else{if(P.captionId<(P.max-1)){P.target=P.target-P.xstep;
newCaptionId=P.captionId+1;
d=true
}}if(d==true){W(P.target,newCaptionId)
}}function Y(d){var e=0;
if(!d){d=window.event
}if(d.wheelDelta){e=d.wheelDelta/120
}else{if(d.detail){e=-d.detail/3
}}if(e){Z(e)
}if(d.preventDefault){d.preventDefault()
}d.returnValue=false
}function V(){if(window.addEventListener){document.getElementById("imageflow").addEventListener("DOMMouseScroll",Y,false)
}document.getElementById("imageflow").onmousewheel=Y
}function E(){W(P.startAt*148*-1,P.startAt)
}A("#leftButton").click(function(){if(P.target<=0){Z(1)
}});
A("#rightButton").click(function(){if(P.target>=-(P.xstep*13)){Z(-1)
}});
A("#leftButton").mouseover(function(){A(this).addClass("hover")
});
A("#leftButton").mouseout(function(){A(this).removeClass("hover")
});
A("#rightButton").mouseover(function(){A(this).addClass("hover")
});
A("#rightButton").mouseout(function(){A(this).removeClass("hover")
});
A("#imageflowbox").click(function(){document.getElementById("imageflow").onselectstart=function(){return false
};
document.getElementById("imageflow").style.MozUserSelect="none"
})
}
})(jQuery);