
/*
	jQuery plugIn - Scroll Gallery
	Author: Serega Tolmachyov
*/

(function($){$.fn.scrollGallery=function(j){var k={clipWidth:0,rotatingSpeed:500,autoRotating:false,rotatingInterval:8000,loop:true,containerClass:'scroll-gallery',additionalClass:'',createMainShadows:false,createClipShadows:false,buttonPrevClass:'button-prev',buttonNextClass:'button-next',buttonPrevHTML:'<a href="#"><span/></a>',buttonNextHTML:'<a href="#"><span/></a>',currentItem:1};var l=this;l.options=$.extend({},k,j);l.canAnimate=true;if(!l.hasClass(l.options.containerClass+'-completed')){l.items=l.find('>li').css({'list-style-type':'none',float:'left',margin:0,border:0});l.items.find('img').css({display:'block'});var m=$('<div class="'+l.options.containerClass+'-clip"/>');l.before($('<div style="position: absolute; z-index: -1; left:0; top:-100px; height:0; overflow:hidden;"/>').append(m));setTimeout(function(){l.options.clipWidth=m.width();m.parent().remove();var d=0;for(var i=0;i<l.items.length;i++)d+=l.items.eq(i).innerWidth();if(l.options.clipWidth<d){l.timerRotating=null;l.hoverOnGallery=false;$.extend(l,{getGalleryPosition:function(){return Math.abs(parseInt(this.css('margin-left'),10))},moveToItem:function(a){var b=this;a=Math.max(Math.min(a,b.items.length)-1,0);b.options.currentItem=a;if(a!=0){var c=b.items.eq(a).position().left;if(c+b.options.clipWidth<=b.width()){b.css({marginLeft:-c})}else{b.css({marginLeft:-(b.width()-b.options.clipWidth)})}}},setGalleryTimer:function(){if(!l.timerRotating)l.timerRotating=setInterval(function(){l.next()},l.options.rotatingInterval)},removeGalleryTimer:function(){if(l.timerRotating){clearInterval(l.timerRotating);l.timerRotating=null}}});l.addClass(l.options.containerClass+'-completed');l.css({position:'relative',zIndex:5,width:d,overflow:'hidden',margin:0,padding:0});l.container=$('<div class="'+l.options.containerClass+'"/>').addClass(l.options.additionalClass).css({position:'relative'});l.before(l.container);var e=$('<div class="'+l.options.containerClass+'-content"/>').css({position:'relative'});if(l.options.createMainShadows){var f="gm_sg_sh_main gm_sg_sh_main";$('<div class="'+l.options.containerClass+'-i"/>').css({width:'100%',overflow:'hidden',position:'relative'}).append($('<span class="'+f+'_tl"/><span class="'+f+'_tr"/>')).append(e).appendTo(l.container.append($('<span class="'+f+'_bl"/><span class="'+f+'_br"/>')));l.container.addClass('gm_sg_shadows_main').css({overflow:'hidden'}).find('span.gm_sg_sh_main').css({position:'absolute',display:'block',overflow:'hidden'})}else{l.container.append(e)}l.buttonPrev=$(l.options.buttonPrevHTML).addClass(l.options.buttonPrevClass).css({'text-decoration':'none',outline:'none',overflow:'hidden',position:'absolute',top:'50%',left:0}).appendTo(e).click(function(){if(l.canAnimate&&l.options.autoRotating&&h!=null){l.removeGalleryTimer();var a=setInterval(function(){if(l.canAnimate){clearInterval(a);if(!l.hoverOnGallery)l.setGalleryTimer()}},50)}return false}).hover(function(){$(this).addClass(l.options.buttonPrevClass+'-hover')},function(){$(this).removeClass(l.options.buttonPrevClass+'-hover')});l.buttonPrev.css({'margin-top':-Math.round(l.buttonPrev.height()/2)}).find('span').css({position:'absolute',display:'block',cursor:'pointer'});l.buttonNext=$(l.options.buttonNextHTML).addClass(l.options.buttonNextClass).css({'text-decoration':'none',outline:'none',overflow:'hidden',position:'absolute',top:'50%',right:0}).appendTo(e).click(function(){if(l.canAnimate&&l.options.autoRotating&&h!=null){l.removeGalleryTimer();var a=setInterval(function(){if(l.canAnimate){clearInterval(a);if(!l.hoverOnGallery)l.setGalleryTimer()}},50)}return false}).hover(function(){$(this).addClass(l.options.buttonNextClass+'-hover')},function(){$(this).removeClass(l.options.buttonNextClass+'-hover')});l.buttonNext.css({'margin-top':-Math.round(l.buttonNext.height()/2)}).find('span').css({position:'absolute',display:'block',cursor:'pointer'});l.clip=$('<div class="'+l.options.containerClass+'-clip"/>').css({padding:0,position:'relative',overflow:'hidden'});if(l.options.createClipShadows){var f="gm_sg_sh_clip gm_sg_sh_clip";var g=$('<div class="gm_sg_shadows_clip_i"/>').css({position:'relative',overflow:'hidden'}).append($('<span class="'+f+'_tl"/><span class="'+f+'_tr"/>')).append(l.clip);$('<div class="gm_sg_shadows_clip"/>').css({position:'relative',overflow:'hidden'}).append($('<span class="'+f+'_bl"/><span class="'+f+'_br"/>')).append(g).appendTo(e);e.find('span.gm_sg_sh_clip').css({position:'absolute',display:'block',overflow:'hidden'})}else{e.append(l.clip)}l.clip.append(l[0]);l.moveToItem(l.options.currentItem);$.fn.scrollGallery.rotatingMethod=$.extend({});var h=$.fn.scrollGallery.rotatingMethod[l.options.rotatingMethod];if(h!=null)h(l);if(l.options.autoRotating&&h!=null){l.setGalleryTimer();l.hover(function(){l.hoverOnGallery=true;l.removeGalleryTimer()},function(){l.hoverOnGallery=false;if(l.canAnimate){l.setGalleryTimer()}else{var a=setInterval(function(){if(l.canAnimate){clearInterval(a);l.setGalleryTimer()}},50)}})}}},50)}$(window).bind('unload',function(){l.remove()});return l}})(jQuery);
