(function($){$.fn.HScroll=function(HSettings){var Settings=$.extend({ControlWidth:0,ControlPosition:'center'},HSettings||{});var TotalWidth=0;var ContWidth=$(this).width();var ControlWidth=ContWidth;var tmpInterval=0;if(Settings.ControlWidth.length!=0){ControlWidth=Settings.ControlWidth;}
if(ControlWidth>ContWidth){ControlWidth==ContWidth;}
$(this).css("position","relative");$(this).prepend("<div class=\"scrollWrapper\" style=\"position: absolute;left: 0px; top: 0px;\"></div>");$(this).children(".scrollSection").each(function(){TotalWidth+=$(this).width();$(this).css("float","left");});$(this).children(".scrollWrapper").css("width",TotalWidth+"px");$(this).children(".scrollWrapper").css("height",$(this).height()+"px");$(this).children(".scrollSection").clone().appendTo(".scrollWrapper");$(this).children(".scrollSection").remove();var MarLeft=(ContWidth-ControlWidth)/2;if(Settings.ControlPosition=="left"){MarLeft=0;}
if(Settings.ControlPosition=="right"){MarLeft=ContWidth-ControlWidth;}
$(this).append("<div id=\"scrollControls\" style=\"position: absolute; left: "+MarLeft+"px; bottom: 40px; width: "+ControlWidth+"px;\"><div class=\"arrowLeft\"> </div><div style=\"position: relative;\" class=\"scrollBar\"><div style=\"position: absolute; left: 0px;\" class=\"scrollDrag\"> </div></div><div class=\"arrowRight\"> </div></div>");var barWidth=ControlWidth-(parseInt($(".arrowLeft").width())*2);PlaceDrag();$(".scrollBar").css("width",barWidth+"px");$(this).css("height",(parseInt($(this).css("height").replace("px",""))+parseInt($(".arrowLeft").css("height").replace("px","")))+"px");$(".arrowRight").mousedown(function(){tmpInterval=setInterval(function(){MoveRight()},100);});$(".arrowRight").mouseup(function(){clearInterval(tmpInterval);});$(".arrowLeft").mousedown(function(){tmpInterval=setInterval(function(){MoveLeft()},100);});$(".arrowLeft").mouseup(function(){clearInterval(tmpInterval);});$(".arrowLeft").mouseleave(function(){clearInterval(tmpInterval);});$(".arrowRight").mouseleave(function(){clearInterval(tmpInterval);});$(".scrollDrag").draggable({axis:'x',containment:'parent',drag:function(){PlaceWrapper();}});function PlaceDrag(){var CurrLeft=parseInt($(".scrollWrapper").css("left").replace("px","").replace("-",""));var MinLeft=1;var MaxLeft=TotalWidth-ContWidth;var MinValue=1;var MaxValue=ControlWidth-(parseInt($(".arrowLeft").width())*2)-parseInt($(".scrollDrag").width());var scrollPos=Math.round(((MaxValue-MinValue)/(MaxLeft-MinLeft))*CurrLeft);$(".scrollDrag").css("left",scrollPos+"px");}
function PlaceWrapper(){var CurrLeft=parseInt($(".scrollDrag").css("left").replace("px","").replace("-",""));var MinLeft=1;var MaxLeft=ControlWidth-(parseInt($(".arrowLeft").width())*2)-parseInt($(".scrollDrag").width());var MinValue=1;var MaxValue=TotalWidth-ContWidth;var scrollPos=Math.round(((MaxValue-MinValue)/(MaxLeft-MinLeft))*CurrLeft);$(".scrollWrapper").css("left","-"+scrollPos+"px");}
function MoveRight(){var CurrLeft=parseInt($(".scrollWrapper").css("left").replace("px","").replace("-",""));CurrLeft+=20;if(CurrLeft>(TotalWidth-ContWidth)){CurrLeft=(TotalWidth-ContWidth);}
$(".scrollWrapper").animate({left:'-'+CurrLeft+'px'},50,function(){PlaceDrag();});}
function MoveLeft(){var CurrLeft=parseInt($(".scrollWrapper").css("left").replace("px","").replace("-",""));CurrLeft-=20;if(CurrLeft==0){CurrLeft=0;}
$(".scrollWrapper").animate({left:'-'+CurrLeft+'px'},50,function(){PlaceDrag();});}if(TotalWidth < ContWidth) {
 $("#scrollControls").remove();
}}})(jQuery);