
if(typeof(AC)=="undefined"){AC={};}

AC.ProductBrowser_02={
productSlider:null,
sliderVal:0,
animationId:false,
viewportWidth:942,
contentWidth:10000,
//contentWidth2:942,
categories:[
{id:'pb-cat1_02',offset:0},
{id:'pb-cat2_02',offset:0.32},
{id:'pb-cat3_02',offset:0.32},
{id:'pb-cat4_02',offset:0.32},
{id:'pb-cat5_02',offset:0.32},
{id:'pb-cat6_02',offset:0.32},
{id:'pb-cat7_02',offset:0.32},
{id:'pb-cat8_02',offset:0.32},
{id:'pb-cat9_02',offset:0.32},
{id:'pb-cat10_02',offset:0.32},
{id:'pb-cat11_02',offset:0.32},
{id:'pb-cat12_02',offset:0.32},
{id:'pb-cat13_02',offset:0.32},
{id:'pb-cat14_02',offset:0.32}
],
isIPhone:AC.Detector.isiPhone(),
iPhoneCategories:[
{id:'pb-cat1_02',offset:0},
{id:'pb-cat2_02',offset:0.32}
],
arrowScrollAmount:0.111,
iPhoneScrollAmount:0.22,
iPhoneContainerWidth:834,
isSliding:false,
lastX:0.32,
isMouseDown:false,
dif:0,
overlap:0,
offsetImageWidth:300,
sliderOffset:291,
offsetContentWidth:-942,
//offsetContentWidth2:-942,
clicked:false,
startIndex:0,

isIpScroll:false,
hasIpDragged:false,
init:function(setupArgs){
if(typeof(setupArgs.categories)!='undefined')this.categories=setupArgs.categories;
if(typeof(setupArgs.imageOverlap)!='undefined')this.overlap=setupArgs.imageOverlap;
if(typeof(setupArgs.sliderCentering)!='undefined')this.sliderOffset=setupArgs.sliderCentering;
if(typeof(setupArgs.initialCategory)!='undefined')this.startIndex=setupArgs.initialCategory;
if(typeof(setupArgs.arrowScrollAmount)!='undefined')this.arrowScrollAmount=setupArgs.arrowScrollAmount;
if(typeof(setupArgs.iPhoneCategories)!='undefined'){this.iPhoneCategories=setupArgs.iPhoneCategories;}
if(typeof(setupArgs.iPhoneScrollAmount)!='undefined')this.iPhoneScrollAmount=setupArgs.iPhoneScrollAmount;
if(typeof(setupArgs.iPhoneContainerWidth)!='undefined')this.iPhoneContainerWidth=setupArgs.iPhoneContainerWidth;

$('pb-productslidertrack_02').style.visibility="visible";
$('pb-productbrowsercontainer_02').style.overflow="hidden";

this.viewportWidth=$('pb-productbrowsercontainer_02').getWidth();
this.viewportWidth=$('pf-resize_02').getWidth();
this.offsetImageWidth=$$('#pb-productslider_02 #pb-edu .pb-productimage_02','#pb-productslider_02 #pb-pro-exp .pb-productimage_03','#pb-productslider_02 #pb-per-exp .pb-productimage_04','#pb-productslider_02 #pb-ext-exp .pb-productimage_06')[0].getWidth()-this.overlap;
//this.offsetImageWidth=$$('#pb-productslider_03 .pb-productimage_05')[0].getWidth()-this.overlap;
this.contentWidth=this.offsetImageWidth*$$('#pb-productslider_02 #pb-edu .pb-productimage_02','#pb-productslider_02 #pb-pro-exp .pb-productimage_03','#pb-productslider_02 #pb-per-exp .pb-productimage_04','#pb-productslider_02 #pb-ext-exp .pb-productimage_06').length;

//this.contentWidth2=this.offsetImageWidth*$$('#pb-productslider_03 .pb-productimage_05').length;

this.offsetContentWidth=-0.4772*(this.contentWidth-this.viewportWidth);
//this.offsetContentWidth=-0.05575*(this.contentWidth-this.viewportWidth);
//this.offsetContentWidth=-0.1045*(this.contentWidth-this.viewportWidth);
//this.offsetContentWidth2=4.975*(this.contentWidth2-this.viewportWidth);

this.productSlider=new Control.Slider('pb-productsliderhandle_02','pb-productslidertrack_02',{
axis:'horizontal'
});

if(AC.ProductBrowser_02.isIPhone){
this.categories=this.iPhoneCategories;
this.arrowScrollAmount=this.iPhoneScrollAmount;
$('pb-productslidertrack_02').style.visibility="none";
$('pb-leftarrow_02').style.visibility="none";
$('pb-rightarrow_02').style.visibility="none";
$('pb-productbrowsercontainer_02').style.width=this.iPhoneContainerWidth+"px";

var leftArrow=document.createElement('div');
leftArrow.id="pb-iphone-leftarrow";

var rightArrow=document.createElement('div');
rightArrow.id="pb-iphone-rightarrow";

$('productbrowser_02').appendChild(leftArrow);
$('productbrowser_02').appendChild(rightArrow);

Event.observe($(leftArrow),'click',function(){
AC.ProductBrowser_02.left();
});

Event.observe($(rightArrow),'click',function(){
AC.ProductBrowser_02.right();
});
}

AC.ProductBrowser_02.animateSlide(this.categories[this.startIndex].offset);


this.productSlider.options.onChange=function(value){
$('pb-productsliderhandleimage_02').style.left=$('pb-productsliderhandle_02').style.left;

if(AC.ProductBrowser_02.isThrow&&!AC.ProductBrowser_02.isSliding){
AC.ProductBrowser_02.isSliding=true;
AC.ProductBrowser_02.isThrow=false;

var mod=value+AC.ProductBrowser_02.throwMod;
if(mod<0)mod=0;
if(mod>1)mod=1;
AC.ProductBrowser_02.animateSlide(mod);
}
else if(!AC.ProductBrowser_02.isSliding&&value){
AC.ProductBrowser_02.isSliding=true;
AC.ProductBrowser_02.animateSlide(value);
}
};

this.productSlider.options.onSlide=function(value){
$('pb-productsliderhandleimage_02').style.left=$('pb-productsliderhandle_02').style.left;
if(value&&!AC.ProductBrowser_02.isSliding){
AC.ProductBrowser_02.isSliding=true;
AC.ProductBrowser_02.isThrow=false;
if(AC.ProductBrowser_02.isMouseDown){
AC.ProductBrowser_02.dif=value-AC.ProductBrowser_02.lastX;
AC.ProductBrowser_02.lastX=value;


if(AC.ProductBrowser_02.dif>0.05){
AC.ProductBrowser_02.isThrow=true;
AC.ProductBrowser_02.throwMod=0.2;
}
else if(AC.ProductBrowser_02.dif<-0.04){
AC.ProductBrowser_02.isThrow=true;
AC.ProductBrowser_02.throwMod=-0.2;
}
}

var w=AC.ProductBrowser_02.offsetContentWidth;
$('pb-productslider_02').style.left=w*value+"px";


//var w2=AC.ProductBrowser_02.offsetContentWidth2;
//$('pb-productslider_03').style.left=w2*value+"px";

this.sliderVal=value;
AC.ProductBrowser_02.lastX=value;
AC.ProductBrowser_02.colorCats();
AC.ProductBrowser_02.isSliding=false;
}

Element.setStyle($('pb-productbrowsercontainer_02'),{overflow:"hidden"});
};

Event.observe('pb-productslidertrack_02','mousedown',function(e){
var o=e.offsetX||e.layerX;
if(Event.element(e).id=='pb-productslidertrack_02'&&o<100)AC.ProductBrowser_02.animateSlide(0);
});
Event.observe('pb-leftarrow_02','mousedown',function(){
AC.ProductBrowser_02.left();
});
Event.observe('pb-rightarrow_02','mousedown',function(){
AC.ProductBrowser_02.right();
});

Event.observe('pb-productsliderhandle_02','mousedown',function(){
AC.ProductBrowser_02.isMouseDown=true;
$('pb-productsliderhandle_02').style.zIndex="5";
});

Event.observe('pb-productsliderhandle_02','mouseup',function(){
AC.ProductBrowser_02.isMouseDown=false;
});

AC.ProductBrowser_02.categories.each(function(c){
Event.observe($(c.id),'mouseup',function(e){
AC.ProductBrowser_02.animateSlide(c.offset);
});
});
},

animateSlide:function(toX){

if(toX>1)toX=1;
if(toX<0)toX=0;
AC.ProductBrowser_02.sliderVal=toX;
window.clearInterval(AC.ProductBrowser_02.animationId);
var w=AC.ProductBrowser_02.offsetContentWidth;
//var w2=AC.ProductBrowser_02.offsetContentWidth2;
var stopPoint=w*toX;
//var stopPoint2=w2*toX;

var sliderStopPoint=(Math.round(AC.ProductBrowser_02.viewportWidth-AC.ProductBrowser_02.sliderOffset)*toX);

AC.ProductBrowser_02.isSliding=true;
AC.ProductBrowser_02.animationId=window.setInterval(function(){
var sliderPos=parseInt($('pb-productslider_02').getStyle('left'))||0;
//var sliderPos2=parseInt($('pb-productslider_03').getStyle('left'))||0;
var handlePos=parseInt($('pb-productsliderhandle_02').getStyle('left'))||0;
var x=AC.ProductBrowser_02.calculateDecel(sliderPos,stopPoint);
//var x2=AC.ProductBrowser_02.calculateDecel(sliderPos2,stopPoint2);
var sx=AC.ProductBrowser_02.calculateDecel(handlePos,sliderStopPoint);
$('pb-productslider_02').style.left=x+"px";
//$('pb-productslider_03').style.left=x2+"px";
$('pb-productsliderhandle_02').style.left=sx+"px";
$('pb-productsliderhandleimage_02').style.left=sx+"px";
AC.ProductBrowser_02.colorCats();

if(x==stopPoint){
window.clearInterval(AC.ProductBrowser_02.animationId);
AC.ProductBrowser_02.isSliding=false;
}
//if(x2==stopPoint2){
//window.clearInterval(AC.ProductBrowser_02.animationId);
//AC.ProductBrowser_02.isSliding=false;
//}
},30);

},


colorCats:function(){
var sliderX=parseInt($('pb-productsliderhandle_02').getStyle('left'))+(($('pb-productsliderhandle_02').getWidth()-20)/2);
AC.ProductBrowser_02.categories.each(function(c){
var left=parseInt($(c.id).getStyle('left'))
var clr=Math.ceil((Math.min(sliderX,left)/Math.max(sliderX,left))*10);
$(c.id).className='pb-catclass'+clr;
});
},

left:function(){
AC.ProductBrowser_02.animateSlide(AC.ProductBrowser_02.sliderVal-AC.ProductBrowser_02.arrowScrollAmount);
},

right:function(){
AC.ProductBrowser_02.animateSlide(AC.ProductBrowser_02.sliderVal+AC.ProductBrowser_02.arrowScrollAmount);
},

calculateDecel:function(from,to){
var n=from-Math.floor((from-to)*.4);
if(Math.abs(from-to)<4)return to;
else return n;
}
};
