
(function(){var o=window['DLPAnimation']=function(options){var opt={longInterval:30000,shortInterval:6000,animateText:true,thumbSelector:'.dlp-thumbs li',largeSelector:'.dlp-main-image img',largeParentSelector:'.dlp-main-image',textSelector:'.dlp-text li',textParentSelector:'.dlp-text',idClassPrefix:'dlp-id-',positionClassPrefix:'dlp-pos-'};$.extend(opt,options);this.animating=false;this.hovering=false;this.interval=null;this.intervalLength=null;this.longInterval=opt.longInterval;this.shortInterval=opt.shortInterval;this.nextClicked=0;this.animateText=opt.animateText;this.clones={};this.elements={};this.selectors={thumb:opt.thumbSelector,large:opt.largeSelector,largeParent:opt.largeParentSelector,text:opt.textSelector,textParent:opt.textParentSelector};this.prefix={};this.prefix['dlpPos']=opt.positionClassPrefix;this.prefix['dlpId']=opt.idClassPrefix;this.getElement('thumb').hover($.proxy(this.onMouseOverThumb,this),$.proxy(this.onMouseOutThumb,this)).find('a').click($.proxy(this.onClickThumb,this));this.setShortInterval();$(this.selectors.largeParent+', '+this.selectors.textParent).hover($.proxy(function(){this.hovering=true;},this),$.proxy(function(){this.hovering=false;},this));},p=o.prototype;p.setLongInterval=function(){if(this.intervalLength=='long'){return;}
window.clearInterval(this.interval);this.interval=window.setInterval($.proxy(this.rotateThumbs,this),this.longInterval);this.intervalLength='long';};p.setShortInterval=function(){if(this.intervalLength=='short'){return;}
window.clearInterval(this.interval);this.interval=window.setInterval($.proxy(this.rotateThumbs,this),this.shortInterval);this.intervalLength='short';};p.rotateThumbs=function(){if(this.hovering){return;}
var el=this.getElement('thumb').filter('.'+this.prefix.dlpPos+this.nextClicked);if(!el.length){el=this.getElement('thumb').filter('.'+this.prefix.dlpPos+1);}
this.setShortInterval();if(el.length){el.find('a:first').trigger('click',true);}
if(el.hasClass('one')){window.clearInterval(this.interval);}};p.onClickThumb=function(event,fakedClick){event.preventDefault();var el=$(event.currentTarget);if(this.animating){return false;}
this.animating=true;if(!fakedClick){window.clearInterval(this.interval);}
var thumb=el.parent();thumb.data('switching',true);thumb.stop(true);var pos=this.getThumbPosition(thumb);this.nextClicked=pos+1;var position=this.prefix.dlpPos+pos;var large=this.getElement('large').filter('.active');var parent=large.parents(this.selectors['largeParent']+':first');var newLarge=this.getElement('large').filter('.'+this.getClass(thumb));var thumbImg=thumb.find('img:first');var newThumb=this.getElement('thumb').filter('.'+this.getClass(large));var newThumbImg=newThumb.find('img:first');var info={large:this.getImageInfo(large),thumb:this.getImageInfo(thumbImg),newLarge:this.getImageInfo(newLarge),newThumb:this.getImageInfo(newThumbImg),largeParent:this.getPositionInfo(parent),thumbParent:this.getPositionInfo(thumb)};var offset=0;if(thumb.data('left')){offset=Math.abs(parseInt(thumb.data('left'))-info.thumbParent.left);if(info.largeParent.left<info.thumbParent.left){offset=-1*offset;}}
var css={large:{start:{position:'absolute',zIndex:10,top:(info.largeParent.top+info.large.marginTop+info.large.paddingTop)+'px',left:(info.largeParent.left+info.large.marginLeft+info.large.paddingLeft)+'px',height:info.large.height,width:info.large.width},end:{top:(info.thumbParent.top+info.thumb.marginTop+info.thumb.paddingTop)+'px',left:(info.thumbParent.left+info.thumb.marginLeft+info.thumb.paddingLeft)+offset+'px',height:info.newThumb.height,width:info.newThumb.width}},newLarge:{start:{position:'absolute',zIndex:9,top:(info.thumbParent.top+info.thumb.marginTop+info.thumb.paddingTop)+'px',left:(info.thumbParent.left+info.thumb.marginLeft+info.thumb.paddingLeft)+'px',height:info.thumb.height,width:info.thumb.width},end:{top:(info.largeParent.top+info.large.marginTop+info.large.paddingTop)+'px',left:(info.largeParent.left+info.large.marginLeft+info.large.paddingLeft)+'px',height:info.newLarge.height,width:info.newLarge.width}}};if(this.clones[this.getClass(large)]){largeClone=this.clones[this.getClass(large)].show();}else{largeClone=large.clone().insertAfter(parent);this.clones[this.getClass(large)]=largeClone;}
largeClone.css(css.large.start);if(this.clones[this.getClass(newLarge)]){newLargeClone=this.clones[this.getClass(newLarge)];}else{newLargeClone=newLarge.clone().insertAfter(parent);this.clones[this.getClass(newLarge)]=newLargeClone;}
newLargeClone.hide().css(css.newLarge.start);if(!jQuery.support.opacity){parent.css({backgroundColor:'white',zIndex:1});}
parent.fadeOut('medium',$.proxy(function(){if(el.hasClass('h')){parent.removeClass('v').addClass('h');}else if(el.hasClass('v')){parent.removeClass('h').addClass('v');}
large.removeClass('active');newLarge.addClass('active');parent.show();var diff=info.largeParent.left-this.getPositionInfo(parent).left;if(diff){css.newLarge.end.left=(parseInt(css.newLarge.end.left)-diff)+'px';}
parent.hide();if(Math.abs(parseInt(css.large.end.left)-parseInt(css.newLarge.start.left))>15){css.large.end.left=(info.thumbParent.left+info.thumb.marginLeft+info.thumb.paddingLeft)+'px';}},this));var oldText=this.getElement('text').filter('.active');if(this.animateText){this.animateTextOut(oldText);}
var text=this.getElement('text').filter('.'+this.getClass(thumb));newLargeClone.fadeIn('medium',$.proxy(function(){largeClone.css('zIndex',7);largeClone.animate(css.large.end,'slow','swing',$.proxy(function(){var newThumb=this.getElement('thumb').filter('.'+this.getClass(large));newThumb.removeAttr('style').removeClass('active').addClass(position);largeClone.fadeOut('medium',$.proxy(function(){this.animating=false;},this));},this));thumb.addClass('active').removeClass(position).data('switching',false).removeAttr('style');newLargeClone.animate(css.newLarge.end,'slow','swing',$.proxy(function(){if(!jQuery.support.opacity){parent.css({backgroundColor:'white',zIndex:1});}
parent.fadeIn('medium',function(){parent.removeAttr('style');newLargeClone.hide();});if(this.animateText){this.animateTextIn(text);}else{oldText.removeClass('active');text.addClass('active');}},this));},this));};p.onMouseOverThumb=function(event){var el=$(event.currentTarget);var offset=15;if(el.data('switching')||this.animating){el.removeData('left');if(!el.data('interval')){el.removeData('left');el.data('interval',window.setInterval($.proxy(function(){this.onMouseOverThumb(event);},this),200));}
return true;}else if(el.data('interval')){window.clearInterval(el.data('interval'));el.removeData('interval');}
var left=el.position().left;if(isNaN(parseInt(el.css('left')))){el.css('left',left+'px');}
if(el.data('animating')&&el.data('left')){offset=offset-Math.abs(left-el.data('left'));left=el.data('left');el.stop(true,false);}
else{el.data('left',left);}
var large=this.getElement('largeParent').position().left;var newLeft=left<large?(left-offset):(left+offset);el.data('animating',true).animate({left:newLeft+'px'},'medium','swing',function(){el.data('animating',false);});};p.onMouseOutThumb=function(event){var el=$(event.currentTarget);if(el.data('interval')){window.clearInterval(el.data('interval'));el.removeData('interval');}
if(el.data('switching')||this.animating){el.removeData('left');return true;}
if(el.data('animating')){el.stop(true,false);}
var left=el.data('left')?el.data('left'):el.position().left;el.data('animating',true).animate({left:left+'px'},'medium','swing',function(){el.data('animating',false);});};p.animateTextIn=function(text){text.addClass('active').css({position:'relative',top:'15px',opacity:0}).animate({top:'0px',opacity:1},'medium','swing',function(){text.removeAttr('style');});};p.animateTextOut=function(text){text.css({position:'relative',top:'0',opacity:1}).animate({top:'15px',opacity:0},'medium','swing',function(){text.removeClass('active').removeAttr('style');});};p.getImageInfo=function(image){var hidden=image.is(':hidden');if(hidden){image.css({position:'absolute',bottom:'1000px'});var parents=image.parents(':hidden');parents.show();if(image.is(':hidden')){image.show();}}
var info={marginTop:parseInt(image.css('margin-top')),marginLeft:parseInt(image.css('margin-left')),paddingTop:parseInt(image.css('padding-top')),paddingLeft:parseInt(image.css('padding-left')),height:image.height()+'px',width:image.width()+'px'};if(hidden){parents.removeAttr('style');image.removeAttr('style');}
return info;};p.getPositionInfo=function(el){return el.position();};p.getClass=function(el){if(el.hasClass('one')){return'one';}else if(el.hasClass('two')){return'two';}else if(el.hasClass('three')){return'three';}else if(el.hasClass('four')){return'four';}else if(el.hasClass('five')){return'five';}else{return'';}
var className=el.attr('class'),index=className.indexOf(this.prefix.dlpId)+this.prefix.dlpId.length,end=className.indexOf(' ',index);if(end===-1){return parseInt(className.substr(index));}else{return parseInt(className.substr(index,end));}};p.getThumbPosition=function(el){var className=el.attr('className'),index=className.indexOf(this.prefix.dlpPos)+this.prefix.dlpPos.length,end=className.indexOf(' ',index);if(end===-1){return parseInt(className.substr(index));}else{return parseInt(className.substr(index,end));}};p.getElement=function(key){if(!this.selectors[key]){return null;}else if(!this.elements[key]&&this.selectors[key]){this.elements[key]=$(this.selectors[key]);}
return this.elements[key];};})();
