(function($){"use strict";var methods={init:function(options){var p={width:'auto',height:'auto',direction:'left',scrollDelay:85,scrollAmount:6,circular:false,dragAndDrop:true,hoverStop:true,scrollStop:true,startShow:false,xml:false,touchEvent:true,stopOutScreen:true,create:function(){},moveStart:function(){},moveStop:function(){},drag:function(){},dragStart:function(){},dragStop:function(){},wayEnd:function(){},removeContentFadeDuration:300};if(options){$.extend(p,options);}
return this.each(function(){var mEl=$(this).addClass('mWrap');var mElIndex=$('*').index($(this));mEl.data().mElIndex=mElIndex;var pos=function(el,parent){var oldObj=el.position();var wrapper=parent||$(document);var rightVal=(wrapper.outerWidth()-(el.position().left+el.outerWidth()));var bottomVal=(wrapper.outerHeight()-(el.position().top+el.outerHeight()));var newObj={right:rightVal,bottom:bottomVal};$.extend(newObj,oldObj);return newObj;};mEl.data().style=mEl.attr('style');$.extend(p,mEl.data());$.extend(mEl.data(),p);if(!$('.mMove',mEl).length){mEl.wrapInner('<div class="mMove"></div>');}
var mMove=$('.mMove',mEl);mEl.css({position:'relative',overflow:'hidden',maxWidth:'100%',height:mEl.data().height,width:mEl.data().width});if(mEl.data().scrollDelay<=0){mEl.data().scrollDelay=85;}
mEl.data().outerSizeFunc=function(el){if(mEl.data().direction==='top'||mEl.data().direction==='bottom'){return el.outerHeight();}else{return el.outerWidth();}}
mMove.data().style=mMove.attr('style');if((!mEl.data().updateCont)){mMove.css({position:'absolute',left:'auto',right:'auto',top:'auto',bottom:'auto',float:'left'});}
mEl.data().mMove=mMove;var createMarquee=function(){mEl.data().clickEventFlag=true;if(mEl.data().outerSizeFunc(mMove)>0){var mItem=$('.mItem',mEl);mItem.each(function(){$(this).data().style=$(this).attr('style');$(this).css({display:'inline',zoom:1});});var splittingString=function(splitSide,mItem){mItem.css({paddingLeft:0,paddingRight:0,paddingTop:0,paddingBottom:0});if(mItem.length&&!mEl.data().circular){var paddingVal={};var paddingValFirst={};paddingVal['padding-'+splitSide]=mEl.data().outerSizeFunc(mEl);paddingValFirst['padding-'+splitSide]=0;mItem.css(paddingVal);mItem.eq(0).css(paddingValFirst);}};mEl.data().splittingString=splittingString;var contentString=$('<div>').addClass('cloneContent').html(mMove.html());if(mEl.data().direction==='left'||mEl.data().direction==='right'){mMove.css({whiteSpace:'nowrap'});mEl.data().splittingString('left',mItem);mEl.css({minHeight:mMove.outerHeight()});contentString.css({display:'inline-block'});mEl.data().axis='hor';}else{mMove.css({whiteSpace:'normal'});mItem.css({display:'block'});mEl.data().splittingString('top',mItem);if(mEl.outerHeight()===0){alert('Set Height Parametr for Plugin liMarquee');}
contentString.css({display:'block'});mEl.data().axis='vert';}
var isIE=false||document.documentMode;if(isIE){mEl.add(mEl.find('*')).attr('unselectable','on');}
var moveEvent='mousemove.'+mEl.data().mElIndex;var mousedownEvent='mousedown.'+mEl.data().mElIndex;var mouseupEvent='mouseup.'+mEl.data().mElIndex;var clickEvent='click.'+mEl.data().mElIndex;mEl.data({touchScreen:false,teleport:false,dragging:false,pause:false});if('ontouchstart'in window){moveEvent='touchmove.'+mEl.data().mElIndex;mousedownEvent='touchstart.'+mEl.data().mElIndex;mouseupEvent='touchend.'+mEl.data().mElIndex;mEl.data().touchScreen=true;if($(window).width()<1000){mEl.data().hoverStop=false;}}
mEl.data({moveEvent:moveEvent,mousedownEvent:mousedownEvent,mouseupEvent:mouseupEvent,clickEvent:clickEvent});var cloneContent=function(mMove){if(mEl.data().outerSizeFunc(mMove)!==0){if(mEl.data().outerSizeFunc(mMove)<mEl.data().outerSizeFunc(mEl)&&mEl.data().circular){contentString.clone().appendTo(mMove);mEl.data().cloneContent(mMove);}}else{console.log('The string is empty or contains invalid style');}};mEl.data().cloneContent=cloneContent;mEl.data().cloneContent(mMove);var anim=function(sPos,ePos){if(!mEl.data().pause){if(sPos===undefined){sPos=mEl.data().startPos;}
if(ePos===undefined){ePos=mEl.data().endPos;}
if(ePos!==0&&ePos!==-0){var way=(ePos-sPos);if(way<0){way=way* -1;}
var duration=(way*mEl.data().scrollDelay)/mEl.data().scrollAmount;var directTypeStart={};var directTypeEnd={};directTypeStart[mEl.data().direction]=sPos;directTypeEnd[mEl.data().direction]=ePos;mMove.css(directTypeStart);mEl.addClass('mIni');mEl.data().stopped=false;if(mEl.data().moveStart!==undefined){mEl.data().moveStart();}
mMove.stop(true).animate(directTypeEnd,duration,'linear',function(){if(mEl.data().moveStop!==undefined){mEl.data().moveStop();}
if(mEl.data().wayEnd!==undefined){mEl.data().wayEnd();}
mEl.data().teleport=true;anim();});}}};mEl.data().anim=anim;var addClone=function(){var mMoveClone=mMove.clone().addClass('clone').css({position:'absolute',width:'100%',height:'100%',opacity:0});if(mEl.data().direction==='top'||mEl.data().direction==='bottom'){mMoveClone.css({left:0});}else{mMoveClone.css({top:0});}
var value={};var value2={};value[mEl.data().direction]='-100%';value2[mEl.data().direction]='100%';var cloneBefore=mMoveClone.clone().addClass('cloneBefore').css(value).appendTo(mMove);var cloneAfter=mMoveClone.clone().addClass('cloneAfter').css(value2).appendTo(mMove);if(mEl.data().circular){cloneBefore.add(cloneAfter).css({opacity:1});}};if(mEl.data().circular){addClone();}
if(mEl.data().create!==undefined){mEl.data().create();}
var nowPos=function(){return pos(mMove,mEl)[mEl.data().direction];};mEl.data().nowPos=nowPos;var correctEvent=function(e){var eventType=e;if(mEl.data().touchScreen){if(e.originalEvent.targetTouches.length===1){eventType=e.originalEvent.targetTouches[0];}}
var newParam={left:eventType.pageX,top:eventType.pageY,right:($(window).width()-eventType.pageX),bottom:($(window).height()-eventType.pageY)};$.extend(eventType,newParam);return eventType;};if(mEl.data().hoverStop){mEl.on('mouseenter.'+mEl.data().mElIndex,function(){mEl.off('mouseleave.'+mEl.data().mElIndex);if(mEl.data().dragAndDrop){$('html').addClass('grab');}
if(!mEl.data().stopped){mMove.stop(true);mEl.data().stopped=true;if(mEl.data().moveStop!==undefined){mEl.data().moveStop();}}
mEl.on('mouseleave.'+mEl.data().mElIndex,function(){$(document).off(moveEvent);$('html').removeClass('grab');$('html').removeClass('grabbing');anim(mEl.data().nowPos());});});}
if(!mEl.data().touchScreen&&mEl.data().dragAndDrop||mEl.data().touchScreen&&mEl.data().touchEvent){mEl.on(mousedownEvent,function(e){$(document).off(moveEvent);$(document).off(mouseupEvent);mEl.off('mouseleave.'+mEl.data().mElIndex);$('html').addClass('grabbing');if(!mEl.data().stopped){mMove.stop(true);mEl.data().stopped=true;if(mEl.data().moveStop!==undefined){mEl.data().moveStop();}}
var startMouseCoord=correctEvent(e)[mEl.data().direction];var startMouseY=correctEvent(e)['top'];var startMouseX=correctEvent(e)['left'];var vertSum=0;var horSum=0;var dir=1;$(document).on(moveEvent,function(e){mEl.data().clickEventFlag=false;mEl.off('mouseleave.'+mEl.data().mElIndex);$('html').addClass('grabbing');if(!mEl.data().dragging){if(mEl.data().dragStart!==undefined){mEl.data().dragStart();}
mEl.data().dragging=true;}
var nowPosVal=mEl.data().nowPos();if(!mEl.data().stopped){mMove.stop(true);mEl.data().stopped=true;}
var newMouseCoord=correctEvent(e)[mEl.data().direction];var dragTrue=function(){if(newMouseCoord>startMouseCoord){dir=1;}
if(newMouseCoord<startMouseCoord){dir=-1;}
var shiftVal=(startMouseCoord-newMouseCoord);startMouseCoord=newMouseCoord;var value={};value[mEl.data().direction]='-='+shiftVal;if(mEl.data().circular){if(nowPosVal<=mEl.data().outerSizeFunc(mMove)&&!mEl.data().teleport){mEl.data().teleport=true;}
if(nowPosVal<=(mEl.data().outerSizeFunc(mEl)-mEl.data().outerSizeFunc(mMove))&&dir<0&&mEl.data().teleport){if(mEl.data().wayEnd!==undefined){mEl.data().wayEnd();}
value[mEl.data().direction]='+='+mEl.data().outerSizeFunc(mMove);}
if(nowPosVal>=0&&dir>0&&mEl.data().teleport){if(mEl.data().wayEnd!==undefined){mEl.data().wayEnd();}
value[mEl.data().direction]='-='+mEl.data().outerSizeFunc(mMove);}}else{if(nowPosVal<=-mEl.data().outerSizeFunc(mMove)&&dir<0){if(mEl.data().wayEnd!==undefined){mEl.data().wayEnd();}
value[mEl.data().direction]='+='+(mEl.data().outerSizeFunc(mMove)+mEl.data().outerSizeFunc(mEl));}
if(nowPosVal>=mEl.data().outerSizeFunc(mEl)&&dir>0){if(mEl.data().wayEnd!==undefined){mEl.data().wayEnd();}
value[mEl.data().direction]='-='+(mEl.data().outerSizeFunc(mMove)+mEl.data().outerSizeFunc(mEl));}}
if(mEl.data().drag!==undefined){mEl.data().drag();}
mMove.css(value);if(mEl.data().touchEvent){return false;}}
if(mEl.data().axis=='hor'){var newMouseY=correctEvent(e)['top'];var newMouseX=correctEvent(e)['left'];var vertDif=Math.abs(newMouseY-startMouseY);var horDif=Math.abs(newMouseX-startMouseX);vertSum+=vertDif;horSum+=horDif;if(vertSum>horSum){$(document).trigger(mouseupEvent);}else{dragTrue();}}else{dragTrue();}});$(document).on(mouseupEvent,function(e){if(mEl.data().dragging){if(mEl.data().dragStop!==undefined){mEl.data().dragStop();}
mEl.data().dragging=false;}
if($(e.target).is(mEl)||$(e.target).closest(mEl).length){$(document).off(moveEvent);$('html').removeClass('grabbing');if(mEl.data().hoverStop){mEl.trigger('mouseenter.'+mEl.data().mElIndex);}else{anim(mEl.data().nowPos());}}else{$(document).off(moveEvent);anim(mEl.data().nowPos());$('html').removeClass('grab');$('html').removeClass('grabbing');}
$(document).off(mouseupEvent);setTimeout(function(){mEl.data().clickEventFlag=true;},300);});if(!mEl.data().touchScreen){return false;}});}
var getPosition=function(mEl){var mMove=mEl.data().mMove;var startPos=mEl.data().outerSizeFunc(mEl);var endPos=-mEl.data().outerSizeFunc(mMove);mEl.data().startPos=startPos;mEl.data().endPos=endPos;if(mEl.data().circular){endPos=-(mEl.data().outerSizeFunc(mMove)+(mEl.data().outerSizeFunc(mMove)-mEl.data().outerSizeFunc(mEl)));mEl.data().endPos=endPos;var circularPos=mEl.data().startShow?mEl.data().outerSizeFunc(mMove):(mEl.data().outerSizeFunc(mEl)+mEl.data().outerSizeFunc(mMove));anim(circularPos);}else{var tempStartPos=mEl.data().startShow?0:startPos;anim(tempStartPos);}};mEl.data().getPosition=getPosition;var setPosition=function(mEl){var mMove=mEl.data().mMove;var startPos=mEl.data().outerSizeFunc(mEl);var endPos=-mEl.data().outerSizeFunc(mMove);mEl.data().startPos=startPos;mEl.data().endPos=endPos;if(mEl.data().circular){endPos=-(mEl.data().outerSizeFunc(mMove)+(mEl.data().outerSizeFunc(mMove)-mEl.data().outerSizeFunc(mEl)));mEl.data().endPos=endPos;}};mEl.data().setPosition=setPosition;if(!mEl.data().updateCont){mEl.data().getPosition(mEl);}
var visibilityChanged=function(){if(document.hidden){if(!mEl.data().stopped){mMove.stop(true);mEl.data().stopped=true;if(mEl.data().moveStop!==undefined){mEl.data().moveStop();}}}else{anim(mEl.data().nowPos());}}
$(document).on('visibilitychange',function(){visibilityChanged();})
var resizeId=function(){};$(window).on('resize.'+mEl.data().mElIndex,function(){clearTimeout(resizeId);resizeId=setTimeout(function(){mEl.liMarquee('resetPosition');},300);});var scrollPageId=function(){};var detectStringPos=function(){if(mEl.data().stopOutScreen){if((mEl.offset().top+mEl.outerHeight())<$(window).scrollTop()||mEl.offset().top>($(window).scrollTop()+$(window).height())){if(!mEl.data().stopped){mMove.stop(true);mEl.data().stopped=true;if(mEl.data().moveStop!==undefined){mEl.data().moveStop();}}}else{anim(mEl.data().nowPos());}}else{anim(mEl.data().nowPos());}};$(window).on('scroll.'+mEl.data().mElIndex,function(){if(mEl.data().scrollStop&&!mEl.data().stopped){mMove.stop(true);mEl.data().stopped=true;if(mEl.data().moveStop!==undefined){mEl.data().moveStop();}}
clearTimeout(scrollPageId);scrollPageId=setTimeout(function(){detectStringPos();},100);});mEl.find('a').on('click',function(){if(!mEl.data().clickEventFlag){return false;}});detectStringPos();}else{mMove.text('marquee "'+mEl.attr('class')+'" elements is hidden or missing');createMarquee();mEl.liMarquee('stop');mEl.liMarquee('removeContent');}};if(mEl.data().xml){$.ajax({url:mEl.data().xml,dataType:"xml",success:function(xml){var xmlItem=$(xml).find('item');var xmlItemLength=xmlItem.length;for(var i=0;i<xmlItemLength;i++){var xmlItemActive=xmlItem.eq(i);var xmlItemContent=xmlItemActive.find('title').text();var xmlItemLink=xmlItemActive.find('link').text();if(xmlItemActive.find('link').length){$('<div class="mItem"><a href="'+xmlItemLink+'">'+xmlItemContent+'</a></div>').appendTo(mMove);}else{$('<div class="mItem">').text(xmlItemContent).appendTo(mMove);}}
createMarquee();}});}else{createMarquee();}});},getContent:function(){var mMove=$(this).data().mMove;var content;if(!mMove.is(':empty')){var moveContent=mMove.html();var tempEl=$('<div>').html(moveContent);tempEl.find('.clone').remove();tempEl.find('.cloneContent').remove();content=$.trim(tempEl.html());}else{content=false;}
return content;},addContent:function(per){return this.each(function(){var mEl=$(this);var mMove=mEl.data().mMove;var addingFunc=function(){if(!mEl.data().removing){var newHtml='<div class="mItem">'+per+'</div>';var oldCont=mEl.liMarquee('getContent');var newCont=oldCont;if(!mMove.find('.mItem').length&&oldCont){oldCont='<div class="mItem">'+oldCont+'</div>';}
if(per){if(mEl.data().direction==='left'||mEl.data().direction==='top'){newCont=oldCont?oldCont+newHtml:newHtml;}
if(mEl.data().direction==='right'||mEl.data().direction==='bottom'){newCont=oldCont?newHtml+oldCont:newHtml;}}
mEl.liMarquee('removeContent');var addNewContFunc=function(){if(!mEl.data().removing){mMove.html(newCont);if(oldCont){mEl.data().updateCont=true;}
mEl.liMarquee(mEl.data());if(mEl.data().updateCont){mEl.data().setPosition(mEl);mEl.data().anim(mEl.data().nowPos());}}else{setTimeout(function(){addNewContFunc();},mEl.data().removeContentFadeDuration);}};addNewContFunc();}else{setTimeout(function(){addingFunc();},mEl.data().removeContentFadeDuration);}};addingFunc();});},removeContent:function(){return this.each(function(){$(this).data().removing=true;var mEl=$(this);var mMove=mEl.data().mMove;mMove.children().animate({opacity:0},mEl.data().removeContentFadeDuration);setTimeout(function(){mEl.data().updateCont=true;if(!mEl.data().stopped){mMove.stop(true);mEl.data().stopped=true;}
mEl.off('mouseenter.'+mEl.data().mElIndex);mEl.off('mouseleave.'+mEl.data().mElIndex);mEl.off($(this).data().mousedownEvent);$(window).off('resize.'+mEl.data().mElIndex);$(window).off('scroll.'+mEl.data().mElIndex);$(document).off(mEl.data().moveEvent);$(document).off(mEl.data().mouseupEvent);if(!mEl.data().stopped){mMove.stop(true);mEl.data().stopped=true;}
mMove.empty();mEl.data().removing=false;},mEl.data().removeContentFadeDuration);});},changeOptions:function(options){return this.each(function(){var mEl=$(this);$.extend(mEl.data(),options);mEl.liMarquee('destroy');mEl.data().updateCont=false;mEl.liMarquee(mEl.data());});},destroy:function(){var mEl=$(this);var mMove=mEl.data().mMove;mEl.removeAttr('style').attr('style',mEl.data().style);if(!mEl.data().stopped){mMove.stop(true);mEl.data().stopped=true;}
mMove.removeAttr('style').attr('style',mMove.data().style).removeData();$('.mItem',mEl).each(function(){$(this).removeAttr('style').attr('style',$(this).data().style).removeData();});mEl.off('mouseenter.'+mEl.data().mElIndex);mEl.off('mouseleave.'+mEl.data().mElIndex);mEl.off(mEl.data().mousedownEvent);$(window).off('resize.'+mEl.data().mElIndex);$(window).off('scroll.'+mEl.data().mElIndex);if(mEl.data().moveEvent){$(document).off(mEl.data().moveEvent);}
if(mEl.data().mouseupEvent){$(document).off(mEl.data().mouseupEvent);}
$('.clone',mEl).remove();$('.cloneContent',mEl).remove();var mMoveContent=mMove.html();mMove.remove();mEl.html(mMoveContent).removeClass('mIni').css({opacity:1});},stop:function(){return this.each(function(){var mEl=$(this);if(mEl.is('.mIni')){var mMove=mEl.data().mMove;if(!mEl.data().pause){mEl.data().pause=true;if(!mEl.data().stopped){mMove.stop(true);mEl.data().stopped=true;if(mEl.data().moveStop!==undefined){mEl.data().moveStop();}}}}})},start:function(delayNew){return this.each(function(){var mEl=$(this);if(mEl.data().pause){var delayVal=delayNew?delayNew:0;setTimeout(function(){mEl.data().pause=false;mEl.data().setPosition(mEl);mEl.data().anim(mEl.data().nowPos());$(window).trigger('scroll.'+mEl.data().mElIndex);},delayVal);}});},resetPosition:function(){return this.each(function(){var mEl=$(this);if(mEl.is(':visible')){var mMove=mEl.data().mMove;if(!mEl.data().stopped){mMove.stop(true);mEl.data().stopped=true;}
if(mEl.data().direction==='left'||mEl.data().direction==='right'){mEl.css({minHeight:mMove.outerHeight()});}
mEl.data().setPosition(mEl);mEl.data().anim(mEl.data().nowPos());$(window).trigger('scroll.'+mEl.data().mElIndex);}});}};$.fn.liMarquee=function(method){if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1));}else if(typeof method==='object'||!method){return methods.init.apply(this,arguments);}else{$.error("Метод "+method+" в jQuery.liMarquee doesn't exist");}};})(jQuery);