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

(function($){$.fn.scrollGallery=function(r){var s={rotatingSpeed:600,autoRotating:false,rotatingInterval:8000,loop:true,containerClass:'scroll-gallery',additionalClass:'',createMainShadows:false,createClipShadows:false,mainShadowsClass:'s_gal_cont_sh',clipShadowsClass:'s_gal_clip_sh',buttonPrevClass:'button-prev',buttonNextClass:'button-next',buttonPrevHTML:'<a href="#" onclick="return false"><span/></a>',buttonNextHTML:'<a href="#" onclick="return false"><span/></a>',startItem:1,onComplete:null,onRotationPrevCompleted:null,onRotationNextCompleted:null,rewritingCloneLinkClass:null};var t=this;t.options=$.extend({},s,r);t.canAnimate=true;if(!t.hasClass(t.options.containerClass+'-completed')){t.addClass(t.options.containerClass+'-completed');t.items=t.find('>li').css({listStyleType:'none',float:'left',margin:0,border:0});t.items.find('img').css({display:'block'});var u=$('<div class="'+t.options.containerClass+'-clip"/>');t.before($('<div class="'+t.options.additionalClass+'" style="position:absolute;z-index:-1;left:0;top:-100px;width:0;height:0;overflow:hidden;"/>').append(u));setTimeout(function(){t.getGalleryWidth=function(){var a=0;for(var i=0;i<t.items.length;i++)a+=t.items.eq(i).innerWidth();return a};var l=t.getGalleryWidth();if(u.width()<l){t.timerRotating=null;t.hoverOnGallery=false;$.extend(t,{getGalleryPosition:function(){return Math.abs(parseInt(this.css('marginLeft'),10))},getItemPosition:function(a,b){var c=0;for(var i=0;i<b;i++)c+=a.eq(i).innerWidth();return c},showItem:function(f){var g=this;var h=g.find('>li');f=Math.max(Math.min(f,h.length)-1,0);var i=h.eq(f);var j=i[0].cloneItem;function itemVisibile(a){var b=g.getItemPosition(h,h.index(a));var c=b+a.innerWidth();var d=g.getGalleryPosition();var e=d+g.clip.innerWidth();if(b>=d&&c<=e)return true;return false}function getItemParameters(a){var b=g.getGalleryPosition();var c={};var d=g.getItemPosition(h,h.index(a));var e=d+a.innerWidth();if(d<b){c.left=d;c.difference=Math.abs(c.left-b)}else if(e>b+g.clip.width()){c.left=e-g.clip.width();c.difference=Math.abs(e-b-g.clip.width())}return c}if(j&&g.allItems.index(j.prev())!=-1&&g.allItems.index(j.next())!=-1){if(!itemVisibile(i)&&!itemVisibile(j)){var k=getItemParameters((getItemParameters(i).difference<getItemParameters(j).difference?i:j)).left;g.galleryAnimate(-k)}}else{if(!itemVisibile(i))g.galleryAnimate(-getItemParameters(i).left)}},setGalleryTimer:function(){if(!t.timerRotating)t.timerRotating=setInterval(function(){t.next()},t.options.rotatingInterval)},removeGalleryTimer:function(){if(t.timerRotating){clearInterval(t.timerRotating);t.timerRotating=null}}});t.css({position:'relative',zIndex:5,width:l,overflow:'hidden',margin:0,padding:0});t.container=$('<div class="'+t.options.containerClass+'"/>').addClass(t.options.additionalClass).css({position:'relative'});t.before(t.container);var m=$('<div class="'+t.options.containerClass+'-content" style="position:relative;"/>');if(t.options.createMainShadows||t.options.createClipShadows)function createShadowsSpan(a,b){return $('<span class="'+a+' '+a+'_'+b+'"/>').css({position:'absolute',display:'block',overflow:'hidden'})}if(t.options.createMainShadows){$('<div class="'+t.options.containerClass+'-i"/>').css({width:'100%',overflow:'hidden',position:'relative'}).append(createShadowsSpan(t.options.mainShadowsClass,'tl')).append(createShadowsSpan(t.options.mainShadowsClass,'tr')).append(m).appendTo(t.container.append(createShadowsSpan(t.options.mainShadowsClass,'bl')).append(createShadowsSpan(t.options.mainShadowsClass,'br')));t.container.addClass('s_gal_cont_shadows').css({overflow:'hidden'})}else{t.container.append(m)}if(t.options.buttonPrevHTML!=null){t.buttonPrev=$(t.options.buttonPrevHTML).addClass(t.options.buttonPrevClass).css({display:'none','text-decoration':'none',outline:'none',overflow:'hidden',position:'absolute',top:'50%',left:0}).appendTo(m).click(function(){if(t.canAnimate&&t.options.autoRotating&&q!=null){t.removeGalleryTimer();var a=setInterval(function(){if(t.canAnimate){clearInterval(a);if(!t.hoverOnGallery)t.setGalleryTimer()}},50)}return false}).hover(function(){$(this).addClass(t.options.buttonPrevClass+'-hover')},function(){$(this).removeClass(t.options.buttonPrevClass+'-hover')});t.buttonPrev.css({'margin-top':-Math.round(t.buttonPrev.height()/2)}).find('span').css({position:'absolute',display:'block',cursor:'pointer'})}if(t.options.buttonNextHTML!=null){t.buttonNext=$(t.options.buttonNextHTML).addClass(t.options.buttonNextClass).css({display:'none','text-decoration':'none',outline:'none',overflow:'hidden',position:'absolute',top:'50%',right:0}).appendTo(m).click(function(){if(t.canAnimate&&t.options.autoRotating&&q!=null){t.removeGalleryTimer();var a=setInterval(function(){if(t.canAnimate){clearInterval(a);if(!t.hoverOnGallery)t.setGalleryTimer()}},50)}return false}).hover(function(){$(this).addClass(t.options.buttonNextClass+'-hover')},function(){$(this).removeClass(t.options.buttonNextClass+'-hover')});t.buttonNext.css({'margin-top':-Math.round(t.buttonNext.height()/2)}).find('span').css({position:'absolute',display:'block',cursor:'pointer'})}t.clip=$('<div class="'+t.options.containerClass+'-clip"/>').css({position:'relative',overflow:'hidden'});if(t.options.createClipShadows){var n=$('<div class="s_gal_clip_shadows_i"/>').css({position:'relative',overflow:'hidden'}).append(createShadowsSpan(t.options.clipShadowsClass,'tl')).append(createShadowsSpan(t.options.clipShadowsClass,'tr')).append(t.clip);$('<div class="s_gal_clip_shadows"/>').css({position:'relative',overflow:'hidden'}).append(createShadowsSpan(t.options.clipShadowsClass,'bl')).append(createShadowsSpan(t.options.clipShadowsClass,'br')).append(n).appendTo(m)}else{m.append(t.clip)}t.clip.append(t[0]);t.options.startItem=Math.max(Math.min(t.options.startItem,t.items.length)-1,0);if(t.options.startItem!=0){var o=t.getItemPosition(t.items,t.options.startItem);if(o+t.clip.width()<=t.width()){var p=-o}else{var p=-(t.width()-t.clip.width())}t.css({marginLeft:p})}$.fn.scrollGallery.rotatingMethod=$.extend({});var q=$.fn.scrollGallery.rotatingMethod[t.options.rotatingMethod];if(q!=null)q(t);if(t.options.autoRotating&&q!=null){t.setGalleryTimer();t.hover(function(){t.hoverOnGallery=true;t.removeGalleryTimer()},function(){t.hoverOnGallery=false;if(t.canAnimate){t.setGalleryTimer()}else{var a=setInterval(function(){if(t.canAnimate){clearInterval(a);t.setGalleryTimer()}},50)}})}if(typeof(t.options.onComplete)=='function')t.options.onComplete(t);if(t.options.buttonPrevHTML!=null)t.buttonPrev.css({display:'block'});if(t.options.buttonNextHTML!=null)t.buttonNext.css({display:'block'});$(window).bind('unload',function(){t.container.remove()})};u.parent().remove()},35)}return t}})(jQuery);
