var currentPosition=0;var slideWidth=1600;var slides;var prevPosition;var animating=false;var isInterval=true;var isSlideShow=false;var carouselTimeout=null;var isMouseEnter=false;var agent="desktop";if(navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)){agent="mobile";}
$(document).ready(function(){slides=$('.carousel_item');numberOfSlides=slides.length;slides.wrapAll('<div id="carousel_inner"></div>').css({'float':'left','width':slideWidth});$('#carousel_inner').css('width',slideWidth*numberOfSlides);if(animations.length>0)
runAnimations();if(agent=="mobile")
checkIDevices();carouselTimeout=setInterval("selectItem('next')",8000);});function addEvents(){var video=$("#carousel_item_video"+(currentPosition+1)).children().size();if(video==1){$("#carousel_item_video"+(currentPosition+1)).mousedown(function(){clearInterval(carouselTimeout);isInterval=false;});}}
function handleVimeoProgess(data){var vimeoAPI=document.getElementById("video4");var tim=vimeoAPI.api_getCurrentTime();}
function runAnimations(){for(var i=0;i<animations.length;i++){var item=animations[i];if(typeof(item)!='undefined'){var anim=new Animation(item.item,item.xpos,item.ypos,item.type,item.d1,item.d2,item.loop,item.time,item.ease,item.type);item.animation=anim;if(i==1)
anim.f1();}}}
function checkVideo(){if(agent=="mobile")
return;var video=$("#carousel_item_video"+(prevPosition+1)).children().size();if(video==1){var vimeoAPI=document.getElementById("video"+(prevPosition+1));if(typeof(vimeoAPI.api_pause)!='undefined'){vimeoAPI.api_pause();}}}
function selectItem(__direction){if(!animating){clearInterval(carouselTimeout);isInterval=false;animating=true;if(__direction=="next"){prevPosition=currentPosition
if(currentPosition<slides.length-1){currentPosition++;}else{currentPosition=0;}
addEvents();startAnimations();$('#carousel_slide').animate({'marginLeft':(slideWidth)*(-currentPosition)},600,'easeInOutCirc',function(){animating=false;if(isInterval==false){carouselTimeout=setInterval("selectItem('next')",8000);isInterval=true;stopAnimations();}});}
if(__direction=="prev"){prevPosition=currentPosition;if(currentPosition>0){currentPosition--;}else{currentPosition=4;}
startAnimations();addEvents();$('#carousel_slide').animate({'marginLeft':(slideWidth)*(-currentPosition)},600,'easeInOutCirc',function(){animating=false;if(isInterval==false){carouselTimeout=setInterval("selectItem('next')",8000);isInterval=true;stopAnimations();}});}
checkVideo();toggleIcons();}}
function stopAnimations(){var animation=$("#carousel_item_animation_object"+(prevPosition+1));if(animation.length==1){var anim=animations[prevPosition+1].animation;anim.stop();anim.reset();}}
function startAnimations(){var animation=$("#carousel_item_animation_object"+(currentPosition+1));if(animation.length==1){var anim=animations[currentPosition+1].animation;anim.f1();}}
function toggleIcons(){$("#carousel_item"+(prevPosition+1)+"_sel").fadeOut();$("#carousel_item"+(prevPosition+1)+"_fad").fadeIn();$("#carousel_item"+(currentPosition+1)+"_sel").fadeIn();$("#carousel_item"+(currentPosition+1)+"_fad").fadeOut();}
function selectItemByID(__id){clearInterval(carouselTimeout);isInterval=false;if(!animating){prevPosition=currentPosition;currentPosition=__id;startAnimations();addEvents();animating=true;$('#carousel_slide').animate({'marginLeft':(slideWidth)*(-currentPosition)},600,'easeInOutCirc',function(){animating=false;if(isInterval==false){carouselTimeout=setInterval("selectItem('next')",8000);isInterval=true;stopAnimations();}});checkVideo();toggleIcons();}}
$("#carousel_control_leftarrow").click(function(){isInterval=false;clearTimeout(carouselTimeout);carouselTimeout=-1;selectItem("prev");});$("#carousel_control_rightarrow").click(function(){isInterval=false;clearTimeout(carouselTimeout);carouselTimeout=-1;selectItem("next");});$("#carousel_item1_fad").click(function(){if(currentPosition!=0){selectItemByID(0,"");}});$("#carousel_item2_fad").click(function(){if(currentPosition!=1){selectItemByID(1,"");}});$("#carousel_item3_fad").click(function(){if(currentPosition!=2){selectItemByID(2,"");}});$("#carousel_item4_fad").click(function(){if(currentPosition!=3){selectItemByID(3,"");}});$("#carousel_item5_fad").click(function(){if(currentPosition!=4){selectItemByID(4,"");}});$("#carousel_wrapper").mouseenter(function(){if(carouselTimeout!=-1){isInterval=false;clearInterval(carouselTimeout);carouselTimeout=-1;}}).mouseleave(function(){isInterval=true;carouselTimeout=setInterval("selectItem('next')",8000);});function Animation(__object,__xpos,__ypos,__direction,__dir1,__dir2,__loop,__time,__ease,__type){this.object=__object;this.xpos=__xpos;this.ypos=__ypos;this.directon=__direction;this.dir1=__dir1;this.dir2=__dir2;this.loop=__loop;this.time=__time;this.ease=__ease;this.type=__type;this.prop;if(this.type=="move vertical")this.prop="margin-top";if(this.type=="move horizontal")this.prop="margin-left";$("#"+__object).css("margin-top",__ypos+"px");$("#"+__object).css("margin-left",__xpos+"px");if(this.type=="fade in out"){$("#"+this.object).css("display","none");$("#"+__object).css("visibility","");}else{$("#"+__object).css("visibility","");}
if(typeof(this.ease)!="undefined"){if(this.ease==""||this.ease=="def"){this.ease="swing";};}}
Animation.prototype.f1=function(){var scope=this;var dir2=this.dir2;if(this.type=="move vertical"){$("#"+this.object).animate({"margin-top":this.dir1+"px"},parseInt(this.time),this.ease,function(){if(parseInt(dir2)>0){scope.f2();}})}
if(this.type=="move horizontal"){$("#"+this.object).animate({"margin-left":this.dir1+"px"},parseInt(this.time),this.ease,function(){if(parseInt(dir2)>0){scope.f2();}})}
if(this.type=="fade in out"){$("#"+this.object).fadeIn(parseInt(this.dir1),function(){if(parseInt(dir2)>0){scope.f2();}})}};Animation.prototype.f2=function(){var scope=this;var dir2=this.dir2;var loop=this.loop;if(this.type=="move vertical"){$("#"+this.object).animate({"margin-top":this.dir2+"px"},parseInt(this.time),this.ease,function(){if(loop=="yes"){scope.f1();}})}
if(this.prop=="move horizontal"){$("#"+this.object).animate({"margin-left":this.dir2+"px"},parseInt(this.time),this.ease,function(){if(loop=="yes"){scope.f1();}})}
if(this.type=="fade in out"){$("#"+this.object).fadeIn(parseInt(this.dir2),function(){if(loop=="yes"){}})}};Animation.prototype.stop=function(){$("#"+this.object).stop(true);}
Animation.prototype.reset=function(){$("#"+this.object).css("margin-top",this.ypos+"px");$("#"+this.object).css("margin-left",this.xpos+"px");if(this.type=="fade in out"){$("#"+this.object).css("display","none");}}
function checkIDevices(){if(navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)){var myVideo=document.getElementsByTagName('video')[0];myVideo.addEventListener("play",function(){if(carouselTimeout!=-1){clearInterval(carouselTimeout);}});myVideo.addEventListener("ended",function(){if(carouselTimeout!=-1){carouselTimeout=setInterval("selectItem('next')",8000);}});}}
$("#carousel_item"+(1)+"_sel").fadeIn();$("#carousel_item"+(1)+"_fad").fadeOut();
