/**
 * HoverScroll jQuery Plugin
 *
 * Make an unordered list scrollable by hovering the mouse over it
 *
 * @author RasCarlito <carl.ogren@gmail.com>
 * @version 0.2.4
 * @revision 21
 *
 * FREE BEER LICENSE VERSION 1.02
 *
 * The free beer license is a license to give free software to you and free
 * beer (in)to the author(s).
 *
 */
!function(t){t.fn.hoverscroll=function(e){return e||(e={}),e=t.extend({},t.fn.hoverscroll.params,e),this.each(function(){function o(t,o){t-=g.offset().left,o-=g.offset().top;var r;r=e.vertical?o:t;for(i in w)r>=w[i].from&&r<w[i].to&&("move"==w[i].action?s(w[i].direction,w[i].speed):a())}function r(){if(e.arrows&&!e.fixedArrows){var i,o;e.vertical?(i=h[0].scrollHeight-h.height(),o=h[0].scrollTop):(i=h[0].scrollWidth-h.width(),o=h[0].scrollLeft);var r=e.arrowsOpacity,s=o/i*r;s>r&&(s=r),isNaN(s)&&(s=0);var a=!1;0>=s&&(t("div.arrow.left, div.arrow.top",g).hide(),i>0&&t("div.arrow.right, div.arrow.bottom",g).show().css("opacity",r),a=!0),(s>=r||0>=i)&&(t("div.arrow.right, div.arrow.bottom",g).hide(),a=!0),a||(t("div.arrow.left, div.arrow.top",g).show().css("opacity",s),t("div.arrow.right, div.arrow.bottom",g).show().css("opacity",r-s))}}function s(i,o){g[0].direction!=i&&(e.debug&&t.log("[HoverScroll] Starting to move. direction: "+i+", speed: "+o),a(),g[0].direction=i,g[0].isChanging=!0,d()),g[0].speed!=o&&(e.debug&&t.log("[HoverScroll] Changed speed: "+o),g[0].speed=o)}function a(){g[0].isChanging&&(e.debug&&t.log("[HoverScroll] Stoped moving"),g[0].isChanging=!1,g[0].direction=0,g[0].speed=1,clearTimeout(g[0].timer))}function d(){if(0!=g[0].isChanging){r();var t;t=e.vertical?"scrollTop":"scrollLeft",h[0][t]+=g[0].direction*g[0].speed,g[0].timer=setTimeout(function(){d()},50)}}var n=t(this);e.debug&&t.log("[HoverScroll] Trying to create hoverscroll on element "+this.tagName+"#"+this.id),n.wrap(e.fixedArrows?'<div class="fixed-listcontainer"></div>':'<div class="listcontainer"></div>'),n.addClass("listitem");var h=n.parent();h.wrap('<div class="ui-widget-content hoverscroll'+(e.rtl&&!e.vertical?" rtl":"")+'"></div>');var c,l,p,v,g=h.parent();e.arrows&&(e.vertical?e.fixedArrows?(p='<div class="fixed-arrow top"></div>',v='<div class="fixed-arrow bottom"></div>',h.before(p).after(v)):(p='<div class="arrow top"></div>',v='<div class="arrow bottom"></div>',h.append(p).append(v)):e.fixedArrows?(c='<div class="fixed-arrow left"></div>',l='<div class="fixed-arrow right"></div>',h.before(c).after(l)):(c='<div class="arrow left"></div>',l='<div class="arrow right"></div>',h.append(c).append(l))),g.width(e.width).height(e.height),e.arrows&&e.fixedArrows?e.vertical?(p=h.prev(),v=h.next(),h.width(e.width).height(e.height-(p.height()+v.height()))):(c=h.prev(),l=h.next(),h.height(e.height).width(e.width-(c.width()+l.width()))):h.width(e.width).height(e.height);var f=0;e.vertical?(g.addClass("vertical"),n.children().each(function(){t(this).addClass("item"),"none"!=t(this).css("display")&&(f+=t(this).outerHeight?t(this).outerHeight(!0):t(this).height()+parseInt(t(this).css("padding-top"))+parseInt(t(this).css("padding-bottom"))+parseInt(t(this).css("margin-bottom"))+parseInt(t(this).css("margin-bottom")))}),n.height(f),e.debug&&t.log("[HoverScroll] Computed content height : "+f+"px"),f=g.outerHeight?g.outerHeight():g.height()+parseInt(g.css("padding-top"))+parseInt(g.css("padding-bottom"))+parseInt(g.css("margin-top"))+parseInt(g.css("margin-bottom")),e.debug&&t.log("[HoverScroll] Computed container height : "+f+"px")):(g.addClass("horizontal"),n.children().each(function(){t(this).addClass("item"),f+=t(this).outerWidth?t(this).outerWidth(!0):t(this).width()+parseInt(t(this).css("padding-left"))+parseInt(t(this).css("padding-right"))+parseInt(t(this).css("margin-left"))+parseInt(t(this).css("margin-right"))}),n.width(f),e.debug&&t.log("[HoverScroll] Computed content width : "+f+"px"),f=g.outerWidth?g.outerWidth():g.width()+parseInt(g.css("padding-left"))+parseInt(g.css("padding-right"))+parseInt(g.css("margin-left"))+parseInt(g.css("margin-right")),e.debug&&t.log("[HoverScroll] Computed container width : "+f+"px"));var m=t(this).parent().find(".arrow.top").height();if("gradual"==e.hoverZone)var w={1:{action:"move",from:0,to:.06*f,direction:-1,speed:16},2:{action:"move",from:.06*f,to:.15*f,direction:-1,speed:8},3:{action:"move",from:.15*f,to:.25*f,direction:-1,speed:4},4:{action:"move",from:.25*f,to:.4*f,direction:-1,speed:2},5:{action:"stop",from:.4*f,to:.6*f},6:{action:"move",from:.6*f,to:.75*f,direction:1,speed:2},7:{action:"move",from:.75*f,to:.85*f,direction:1,speed:4},8:{action:"move",from:.85*f,to:.94*f,direction:1,speed:8},9:{action:"move",from:.94*f,to:f,direction:1,speed:16}};else var w={1:{action:"move",from:0,to:m,direction:-1,speed:16},2:{action:"move",from:f-m,to:f,direction:1,speed:16}};g[0].isChanging=!1,g[0].direction=0,g[0].speed=1,e.rtl&&!e.vertical&&(h[0].scrollLeft=h[0].scrollWidth-h.width()),g.mousemove(function(t){o(t.pageX,t.pageY)}).bind("mouseleave, mouseout",function(){a()}),this.startMoving=s,this.stopMoving=a,e.arrows&&!e.fixedArrows?r():t(".arrowleft, .arrowright, .arrowtop, .arrowbottom",g).hide()}),this},t.fn.offset||(t.fn.offset=function(){if(this.left=this.top=0,this[0]&&this[0].offsetParent){var t=this[0];do this.left+=t.offsetLeft,this.top+=t.offsetTop;while(t=t.offsetParent)}return this}),t.fn.hoverscroll.params={vertical:!1,width:400,height:50,arrows:!0,arrowsOpacity:.7,fixedArrows:!1,rtl:!1,debug:!1,hoverZone:"gradual"},t.fn.hoverscroll.destroy=function(i){var e=i.parent().parent(),o=e.parent();t(i).prependTo(o).removeClass("listitem").removeAttr("style"),e.remove()},t.log=function(){try{console.log.apply(console,arguments)}catch(t){try{opera.postError.apply(opera,arguments)}catch(t){}}}}(jQuery);