(function($){$.fn.slides=function(option){option=$.extend({},$.fn.slides.option,option);return this.each(function(){$('.'+option.container,$(this)).children().wrapAll('<div class="slides_control"/>');var elem=$(this),control=$('.slides_control',elem),total=control.children().size(),width=getWidth(),height=getHeight(),start=option.start-1,effect=option.effect.indexOf(',')<0?option.effect:option.effect.replace(' ','').split(',')[0],paginationEffect=option.effect.indexOf(',')<0?effect:option.effect.replace(' ','').split(',')[1],next=0,prev=0,number=0,current=0,loaded,active,clicked,position,direction,imageParent,pauseTimeout,playInterval;equalHeight();if(option.width=="auto"){$(window).resize(function(){var width=getWidth();elem.find('.slide').css({left:width,width:width});equalHeight();control.css({left:-width,width:(width*3),height:getHeight()});});}
if(total<2){$('.'+option.container,$(this)).fadeIn(option.fadeSpeed,option.fadeEasing,function(){loaded=true;option.slidesLoaded();});$('.'+option.next+', .'+option.prev).fadeOut(0);return false;}
function animate(direction,effect,clicked){if(!active&&loaded){active=true;option.animationStart(current+1);switch(direction){case'next':prev=current;next=current+1;next=total===next?0:next;position=getWidth()*2;direction=-getWidth()*2;current=next;break;case'prev':prev=current;next=current-1;next=next===-1?total-1:next;position=0;direction=0;current=next;break;case'pagination':next=parseInt(clicked,10);prev=$('.'+option.paginationClass+' li.'+option.currentClass+' a',elem).attr('href').match('[^#/]+$');if(next>prev){position=getWidth()*2;direction=-getWidth()*2;}else{position=0;direction=0;}
current=next;break;}
if(effect==='fade'){if(option.crossfade){control.children(':eq('+next+')',elem).css({zIndex:10}).fadeIn(option.fadeSpeed,option.fadeEasing,function(){if(option.autoHeight){equalHeight(next);control.animate({height:control.children(':eq('+next+')',elem).outerHeight()},option.autoHeightSpeed,function(){control.children(':eq('+prev+')',elem).css({display:'none',zIndex:0});control.children(':eq('+next+')',elem).css({zIndex:0});option.animationComplete(next+1);active=false;});}else{control.children(':eq('+prev+')',elem).css({display:'none',zIndex:0});control.children(':eq('+next+')',elem).css({zIndex:0});option.animationComplete(next+1);active=false;}});}else{control.children(':eq('+prev+')',elem).fadeOut(option.fadeSpeed,option.fadeEasing,function(){equalHeight(next);if(option.autoHeight){control.animate({height:control.children(':eq('+next+')',elem).outerHeight()},option.autoHeightSpeed,function(){control.children(':eq('+next+')',elem).fadeIn(option.fadeSpeed,option.fadeEasing);});}else{control.children(':eq('+next+')',elem).fadeIn(option.fadeSpeed,option.fadeEasing,function(){if($.browser.msie){$(this).get(0).style.removeAttribute('filter');}});}
option.animationComplete(next+1);active=false;});}}else{control.children(':eq('+next+')').css({left:position,display:'block'});if(option.autoHeight){equalHeight(next);control.animate({left:direction,height:control.children(':eq('+next+')').outerHeight()},option.slideSpeed,option.slideEasing,function(){control.css({left:-getWidth()});control.children(':eq('+next+')').css({left:getWidth(),zIndex:5});control.children(':eq('+prev+')').css({left:getWidth(),display:'none',zIndex:0});option.animationComplete(next+1);active=false;});}else{equalHeight(next);control.animate({left:direction},option.slideSpeed,option.slideEasing,function(){control.css({left:-getWidth()});control.children(':eq('+next+')').css({left:getWidth(),zIndex:5});control.children(':eq('+prev+')').css({left:getWidth(),display:'none',zIndex:0});option.animationComplete(next+1);active=false;});}}
if(option.pagination){$('.'+option.paginationClass+' li.'+option.currentClass,elem).removeClass(option.currentClass);$('.'+option.paginationClass+' li:eq('+next+')',elem).addClass(option.currentClass);}}}
function stop(){clearInterval(elem.data('interval'));}
function equalHeight(pointer){if(!pointer)pointer=current;if(option.equalHeight){var el=control.children(':eq('+pointer+')');jQuery('.bt-title,.bt-introtext',el).height('auto');var maxHeight=Math.max.apply(null,jQuery('.bt-title',el).map(function(){return jQuery(this).height();}).get());if(maxHeight)jQuery('.bt-title',el).height(maxHeight);maxHeight=Math.max.apply(null,jQuery('.bt-introtext',el).map(function(){return jQuery(this).height();}).get());if(maxHeight)jQuery('.bt-introtext',el).height(maxHeight);}}
function getWidth(){return elem.width();}
function getHeight(){var mheight=0;if(option.autoHeight){mheight=control.children(':eq('+current+')').outerHeight();}else{if(option.height){mheight=option.height;}else{mheight=Math.max.apply(null,control.children().map(function(){return $(this).outerHeight();}).get());}}
return mheight?mheight:'auto';}
function pause(){if(option.pause){clearTimeout(elem.data('pause'));clearInterval(elem.data('interval'));pauseTimeout=setTimeout(function(){clearTimeout(elem.data('pause'));playInterval=setInterval(function(){animate("next",effect);},option.play);elem.data('interval',playInterval);},option.pause);elem.data('pause',pauseTimeout);}else{stop();}}
if(total<2){return;}
if(start<0){start=0;}
if(start>total){start=total-1;}
if(option.start){current=start;}
if(option.randomize){control.randomize();}
$('.'+option.container,elem).css({overflow:'hidden',position:'relative'});control.children().css({position:'absolute',top:0,left:control.children().outerWidth(),zIndex:0,display:'none'});control.css({position:'relative',width:(getWidth()*3),height:height,left:-getWidth()});$('.'+option.container,elem).css({display:'block'});if(option.autoHeight){control.children().css({height:'auto'});control.animate({height:control.children(':eq('+start+')').outerHeight()},option.autoHeightSpeed);}
if(option.preload&&control.find('img:eq('+start+')').length){$('.'+option.container,elem).css({background:'url('+option.preloadImage+') no-repeat 50% 50%'});var $imgs=control.find('img');var imgsl=$imgs.length;var u=0;$imgs.each(function(){var img=new Image();$(img).load(function(){++u;if(u==imgsl){startSlider();}}).error(function(){++u;if(u==imgsl){startSlider();}}).attr('src',this.src);});}else{control.children(':eq('+start+')').fadeIn(option.fadeSpeed,option.fadeEasing,function(){loaded=true;option.slidesLoaded();});}
function startSlider(){control.children(':eq('+start+')').fadeIn(option.fadeSpeed,option.fadeEasing,function(){$(this).css({zIndex:5});$('.'+option.container,elem).css({background:''});control.css({height:getHeight()});loaded=true;option.slidesLoaded();});}
if(option.bigTarget){control.children().css({cursor:'pointer'});control.children().click(function(){animate('next',effect);return false;});}
if(option.hoverPause&&option.play){control.bind('mouseover',function(){stop();});control.bind('mouseleave',function(){pause();});}
if(option.generateNextPrev){$('.'+option.container,elem).after('<a href="#" class="'+option.prev+'">Prev</a>');$('.'+option.prev,elem).after('<a href="#" class="'+option.next+'">Next</a>');}
$('.'+option.next,elem).click(function(e){e.preventDefault();if(option.play){pause();}
animate('next',effect);});$('.'+option.prev,elem).click(function(e){e.preventDefault();if(option.play){pause();}
animate('prev',effect);});if(option.generatePagination){if(option.prependPagination){elem.prepend('<ul class='+option.paginationClass+'></ul>');}else{elem.append('<ul class='+option.paginationClass+'></ul>');}
control.children().each(function(){$('.'+option.paginationClass,elem).append('<li><a href="#'+number+'">'+(number+1)+'</a></li>');number++;});}else{$('.'+option.paginationClass+' li a',elem).each(function(){$(this).attr('href','#'+number);number++;});}
$('.'+option.paginationClass+' li:eq('+start+')',elem).addClass(option.currentClass);$('.'+option.paginationClass+' li a',elem).click(function(){if(option.play){pause();}
clicked=$(this).attr('href').match('[^#/]+$');if(current!=clicked){animate('pagination',paginationEffect,clicked);}
return false;});$('a.link',elem).click(function(){if(option.play){pause();}
clicked=$(this).attr('href').match('[^#/]+$')-1;if(current!=clicked){animate('pagination',paginationEffect,clicked);}
return false;});if(option.play){playInterval=setInterval(function(){animate('next',effect);},option.play);elem.data('interval',playInterval);}});};$.fn.slides.option={preload:false,preloadImage:'/img/loading.gif',container:'slides_container',generateNextPrev:false,next:'next',prev:'prev',pagination:true,generatePagination:true,prependPagination:false,paginationClass:'pagination',currentClass:'current',fadeSpeed:350,fadeEasing:'',slideSpeed:350,slideEasing:'',start:1,effect:'slide',crossfade:false,randomize:false,play:0,pause:0,hoverPause:false,autoHeight:false,autoHeightSpeed:350,bigTarget:false,animationStart:function(){},animationComplete:function(){},slidesLoaded:function(){},width:'auto',equalHeight:true};$.fn.randomize=function(callback){function randomizeOrder(){return(Math.round(Math.random())-0.5);}
return($(this).each(function(){var $this=$(this);var $children=$this.children();var childCount=$children.length;if(childCount>1){$children.hide();var indices=[];for(i=0;i<childCount;i++){indices[indices.length]=i;}
indices=indices.sort(randomizeOrder);$.each(indices,function(j,k){var $child=$children.eq(k);var $clone=$child.clone(true);$clone.show().appendTo($this);if(callback!==undefined){callback($child,$clone);}
$child.remove();});}}));};})(jQuery);;