$(document).ready(function(){$('div.slideshow').gallery({duration:500,autoRotation:5000,listOfSlides:'.slides > li',effect:true});$('div.slider').gallery({duration:500,autoRotation:5000,listOfSlides:'ul > li',effect:true});$('div.carousel').galleryCircle({btPrev:'a.btn-prev',btNext:'a.btn-next',holderList:'.frame',autoRotation:5000,step:1});});(function($){$.fn.gallery=function(options){return new Gallery(this.get(0),options);};function Gallery(context,options){this.init(context,options);};Gallery.prototype={options:{},init:function(context,options){this.options=$.extend({duration:700,slideElement:1,autoRotation:false,effect:false,listOfSlides:'ul > li',switcher:false,disableBtn:false,nextBtn:'a.link-next, a.btn-next, a.next',prevBtn:'a.link-prev, a.btn-prev, a.prev',circle:true,direction:false,event:'click',IE:false},options||{});var _el=$(context).find(this.options.listOfSlides);if(this.options.effect)this.list=_el;else this.list=_el.parent();if(this.options.switcher)this.switcher=$(context).find(this.options.switcher);this.nextBtn=$(context).find(this.options.nextBtn);this.prevBtn=$(context).find(this.options.prevBtn);this.count=_el.index(_el.filter(':last'));if(this.options.switcher)this.active=this.switcher.index(this.switcher.filter('.active:eq(0)'));else this.active=_el.index(_el.filter('.active:eq(0)'));if(this.active<0)this.active=0;this.last=this.active;this.woh=_el.outerWidth(true);if(!this.options.direction)this.installDirections(this.list.parent().width());else{this.woh=_el.outerHeight(true);this.installDirections(this.list.parent().height());}
if(!this.options.effect){this.rew=this.count-this.wrapHolderW+1;if(!this.options.direction)this.list.css({marginLeft:-(this.woh*this.active)});else this.list.css({marginTop:-(this.woh*this.active)});}
else{this.rew=this.count;this.list.css({opacity:0}).removeClass('active').eq(this.active).addClass('active').css({opacity:1}).css('opacity','auto');if(this.options.switcher)this.switcher.removeClass('active').eq(this.active).addClass('active');}
if(this.options.disableBtn){if(this.count<this.wrapHolderW)this.nextBtn.addClass(this.options.disableBtn);if(this.active==0)this.prevBtn.addClass(this.options.disableBtn);}
this.initEvent(this,this.nextBtn,this.prevBtn,true);this.initEvent(this,this.prevBtn,this.nextBtn,false);if(this.options.autoRotation)this.runTimer(this);if(this.options.switcher)this.initEventSwitcher(this,this.switcher);},installDirections:function(temp){this.wrapHolderW=Math.floor(temp/this.woh);if(((this.wrapHolderW-1)*this.woh+this.woh/2)>temp)this.wrapHolderWwrapHolderW--;},fadeElement:function(){if($.browser.msie&&this.options.IE){this.list.eq(this.last).css({opacity:0});this.list.removeClass('active').eq(this.active).addClass('active').css({opacity:'auto'});}
else{this.list.eq(this.last).animate({opacity:0},{queue:false,duration:this.options.duration});this.list.removeClass('active').eq(this.active).addClass('active').animate({opacity:1},{queue:false,duration:this.options.duration,complete:function(){$(this).css('opacity','auto');}});}
if(this.options.switcher)this.switcher.removeClass('active').eq(this.active).addClass('active');this.last=this.active;},scrollElement:function(){if(!this.options.direction)this.list.animate({marginLeft:-(this.woh*this.active)},{queue:false,duration:this.options.duration});else this.list.animate({marginTop:-(this.woh*this.active)},{queue:false,duration:this.options.duration});if(this.options.switcher)this.switcher.removeClass('active').eq(this.active).addClass('active');},runTimer:function($this){if($this._t)clearTimeout($this._t);$this._t=setInterval(function(){$this.toPrepare($this,true);},this.options.autoRotation);},initEventSwitcher:function($this,el){el.bind($this.options.event,function(){$this.active=$this.switcher.index($(this));if($this._t)clearTimeout($this._t);if(!$this.options.effect)$this.scrollElement();else $this.fadeElement();if($this.options.autoRotation)$this.runTimer($this);return false;});},initEvent:function($this,addEventEl,addDisClass,dir){addEventEl.bind($this.options.event,function(){if($this._t)clearTimeout($this._t);if($this.options.disableBtn&&($this.count>$this.wrapHolderW))addDisClass.removeClass($this.options.disableBtn);$this.toPrepare($this,dir);if($this.options.autoRotation)$this.runTimer($this);return false;});},toPrepare:function($this,side){if(($this.active==$this.rew)&&$this.options.circle&&side)$this.active=-$this.options.slideElement;if(($this.active==0)&&$this.options.circle&&!side)$this.active=$this.rew+$this.options.slideElement;for(var i=0;i<$this.options.slideElement;i++){if(side){if($this.active+1>$this.rew){if($this.options.disableBtn&&($this.count>$this.wrapHolderW))$this.nextBtn.addClass($this.options.disableBtn);}
else $this.active++;}
else{if($this.active-1<0){if($this.options.disableBtn&&($this.count>$this.wrapHolderW))$this.prevBtn.addClass($this.options.disableBtn);}
else $this.active--;}};if($this.active==$this.rew&&side)if($this.options.disableBtn&&($this.count>$this.wrapHolderW))$this.nextBtn.addClass($this.options.disableBtn);if($this.active==0&&!side)if($this.options.disableBtn&&($this.count>$this.wrapHolderW))$this.prevBtn.addClass($this.options.disableBtn);if(!$this.options.effect)$this.scrollElement();else $this.fadeElement();},stop:function(){if(this._t)clearTimeout(this._t);},play:function(){if(this._t)clearTimeout(this._t);if(this.options.autoRotation)this.runTimer(this);}}}(jQuery));jQuery.fn.galleryCircle=function(_options){var _options=jQuery.extend({btPrev:'a.prev',btNext:'a.next',holderList:'div',scrollElParent:'ul',scrollEl:'li',duration:700,slideNum:false,step:false,autoRotation:false},_options);return this.each(function(){var _this=jQuery(this);var _next=$(_options.btNext,_this).length?$(_options.btNext,_this):false;var _prev=$(_options.btPrev,_this).length?$(_options.btPrev,_this):false;var _holderList=$(_options.holderList,_this);var _scrollElParent=$(_options.scrollElParent,_holderList);var _scrollEl=$(_options.scrollEl,_scrollElParent);var _cloneEl=_scrollEl.clone();var _cloneEl2=_scrollEl.clone();var _scrollElWidth=_scrollEl.outerWidth(true);var _widthSum=_scrollElWidth*_scrollEl.length;var _step=_holderList.outerWidth();var _margin=_widthSum;if(_options.step){_step=_scrollEl.eq(0).outerWidth(true)*_options.step;}
_scrollElParent.append(_cloneEl);_scrollElParent.prepend(_cloneEl2);_scrollElParent.css('marginLeft',-_margin);if(_next){_next.click(function(){if(!_scrollElParent.is(':animated')){nextSlides();}
return false;});}
if(_prev){_prev.click(function(){if(!_scrollElParent.is(':animated')){prevSlides();}
return false;});}
var _timer=false;if(_options.autoRotation){_timer=setInterval(function(){nextSlides();},_options.autoRotation);}
if(_options.slideNum){if(!$(_options.slideNum,_this).is('a')){var _lis='<ul>';for(var i=0;i<_widthSum/_step;i++){_lis+='<li><a href="#">'+i+'</a></li>';}
_lis+='</ul>';$(_options.slideNum,_this).append(_lis);var _tabs=$(_options.slideNum+' a',_this);}else _tabs=$(_options.slideNum,_this)
_tabs.eq(0).parent().addClass('active');_tabs.each(function(i){$(this).click(function(){if(!_scrollElParent.is(':animated')){setActive(i);if(_timer){clearInterval(_timer);_timer=setInterval(function(){nextSlides();},_options.autoRotation);}
_margin=_widthSum+_step*i;_scrollElParent.animate({'marginLeft':-_margin},{duration:_options.duration});}
return false;});});function setActive(_i){_tabs.parent().removeClass('active');if(_i!=null)_tabs.eq(_i).parent().addClass('active');else{_tabs.eq((_margin-_widthSum)/_step).parent().addClass('active');}}}
function nextSlides(){if(_timer){clearInterval(_timer);_timer=setInterval(function(){nextSlides();},_options.autoRotation);}
_margin+=_step;_scrollElParent.animate({'left':-_step},{duration:_options.duration,complete:function(){$(this).css({marginLeft:-_margin,left:0});if(_margin>=_widthSum*2){_margin=_widthSum+(_margin-_widthSum*2);}
if(_options.slideNum)setActive();_scrollElParent.css({'marginLeft':-_margin});}});}
function prevSlides(){if(_timer){clearInterval(_timer);_timer=setInterval(function(){nextSlides();},_options.autoRotation);}
_margin-=_step;_scrollElParent.animate({'left':_step},{duration:_options.duration,complete:function(){$(this).css({marginLeft:-_margin,left:0});if(_margin<_widthSum){_margin=_widthSum*2-(_widthSum-_margin);}
if(_options.slideNum)
setActive();_scrollElParent.css({'marginLeft':-_margin});}});}});}
$(document).ready(function(){$(function(){$('a#back-top').click(function(){$('body,html').animate({scrollTop:0},800);return false;});});});
