
var debug=false;var animating=false;var keepSliding=false;var picCount=0;var realPicCount=0;var picWidth=0;var elementWidth=0;var visibleWidth=0;var posMostLeft=0;var offsetLeft=0;var navId=0;var lastNavId=0;var globalElementId;var globalDirection;var globalVisiblePictures;var globalMargin;var globalStep;var globalDirection
function startSliding(elementId,direction,visiblePictures,margin,step,offset){if(!keepSliding){keepSliding=true;globalElementId=elementId;globalDirection=direction;globalVisiblePictures=visiblePictures;globalMargin=margin;globalStep=step;offsetLeft=offset;move(elementId,direction,visiblePictures,margin,step,specialCallback);}}
function specialCallback(obj){onFinish(obj);if(keepSliding){move(globalElementId,globalDirection,globalVisiblePictures,globalMargin,globalStep,specialCallback);}}
function stopSliding(){keepSliding=false;}
function slide(elementId,direction,visiblePictures,margin,step,navIndex){offsetLeft=0;lastNavId=navIndex;globalDirection=direction;move(elementId,direction,visiblePictures,margin,step,onFinish);}
function move(elementId,direction,visiblePictures,margin,step,callbackFunction){if(!animating){animating=true;var pictures=$(elementId).select('img');picCount=pictures.size();realPicCount=picCount-2;if(picCount<=visiblePictures){if(debug)alert("picCount <= visiblePictures - nothing to do");animating=false;return;}
picWidth=pictures[0].getWidth()+margin;elementWidth=picWidth*picCount;visibleWidth=picWidth*visiblePictures;posMostLeft=(elementWidth-visibleWidth-offsetLeft)*-1;if(debug)alert("picCount: "+picCount+" picWidth: "+picWidth+" elementWidth: "+elementWidth+" posMostLeft: "+posMostLeft);if(direction==0)new Effect.MoveBy(elementId,0,picWidth*step,{duration:1,afterFinish:callbackFunction});if(direction==1)new Effect.MoveBy(elementId,0,-picWidth*step,{duration:1,afterFinish:callbackFunction});}}
function onFinish(obj){var slider=document.getElementById(obj.element.id);var posText=slider.style.left;if(posText==offsetLeft+"px"){var newPosText=posMostLeft+visibleWidth+"px";if(debug)alert("Slider is most left! Set to left: "+newPosText);Element.setStyle(obj.element.id,{left:newPosText});}
if(posText==posMostLeft+"px"){var newPosText=(-visibleWidth+offsetLeft)+"px";if(debug)alert("Slider is most right! Set to left: "+newPosText);Element.setStyle(obj.element.id,{left:newPosText});}
if(lastNavId!=0){if(lastNavId==1&&globalDirection==0){navId=realPicCount;}
else if(lastNavId>=1&&lastNavId<realPicCount&&globalDirection==1){navId=lastNavId+1;}
else if(lastNavId>1&&globalDirection==0){navId=lastNavId-1;}
else if(lastNavId==realPicCount&&globalDirection==1){navId=1;}
var navElement=document.getElementById("navmarker"+navId);var lastNavElement=document.getElementById("navmarker"+lastNavId);Element.setStyle(navElement,{visibility:"visible"});Element.setStyle(lastNavElement,{visibility:"hidden"});navId=0;lastNavId=0;}
animating=false;}
var lastCursorPosition=6;var swichting=false;var markerId="productmarker";var productId="productimage";var productLinkId="productlink";var borderId="bordermarker";function switchProduct(cursorPosition){if(lastCursorPosition==cursorPosition)return;if(!swichting){swichting=true;var marker=document.getElementById(markerId+cursorPosition);var product=document.getElementById(productId+cursorPosition);var productLink=document.getElementById(productLinkId+cursorPosition);var border=document.getElementById(borderId+cursorPosition);Element.setStyle(marker,{visibility:"visible"});Element.setStyle(product,{visibility:"visible"});Element.setStyle(productLink,{visibility:"visible"});Element.setStyle(border,{visibility:"visible"});var markerOld=document.getElementById(markerId+lastCursorPosition);var productOld=document.getElementById(productId+lastCursorPosition);var productLinkOld=document.getElementById(productLinkId+lastCursorPosition);var borderOld=document.getElementById(borderId+lastCursorPosition);Element.setStyle(markerOld,{visibility:"hidden"});Element.setStyle(productOld,{visibility:"hidden"});Element.setStyle(productLinkOld,{visibility:"hidden"});Element.setStyle(borderOld,{visibility:"hidden"});lastCursorPosition=cursorPosition;swichting=false;}}