/**
* jQuery.smoothDivScroll - Smooth div scrolling using jQuery.
* This plugin is for turning a set of DIV's into a smooth scrolling area.
*
* Copyright (c) 2009 Thomas Kahn - thomas.kahn(at)karnhuset(dot)net
*
* This plugin is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details. <http://www.gnu.org/licenses/>.
*
* Date: 2009-03-05
* @author Thomas Kahn
* @version 0.6
*
*/
(function($){jQuery.fn.smoothDivScroll=function(options){var defaults={scrollingHotSpotLeft:"div.scrollingHotSpotLeft",scrollingHotSpotRight:"div.scrollingHotSpotRight",scrollWrapper:"div.scrollWrapper",scrollableArea:"div.scrollableArea",hiddenOnStart:false,ajaxContentURL:"",countOnlyClass:"",mouseDownSpeedBooster:1};options=$.extend(defaults,options);return this.each(function(){var $mom=$(this);if(options.ajaxContentURL.length!==0){$mom.scrollableAreaWidth=0;$mom.find(options.scrollableArea).load((options.ajaxContentURL),function(){$mom.find(options.scrollableArea).children((options.countOnlyClass)).each(function(){$mom.scrollableAreaWidth=$mom.scrollableAreaWidth+$(this).outerWidth(true);});$mom.find(options.scrollableArea).css("width",($mom.scrollableAreaWidth+"px"));if(options.hiddenOnStart){$mom.hide();}
windowIsResized();setHotSpotHeightForIE();});}
var motherElementOffset=$mom.offset().left;var hotSpotWidth=0;var booster=1;$(window).one("load",function(){if(options.ajaxContentURL.length===0){$mom.scrollableAreaWidth=0;$mom.find(options.scrollableArea).children((options.countOnlyClass)).each(function(){$mom.scrollableAreaWidth=$mom.scrollableAreaWidth+$(this).outerWidth(true);});$mom.find(options.scrollableArea).css("width",$mom.scrollableAreaWidth+"px");if(options.hiddenOnStart){$mom.hide();}}});$(window).bind("resize",function(){windowIsResized();});function windowIsResized()
{if(!(options.hiddenOnStart))
{$mom.scrollableAreaWidth=0;$mom.find(options.scrollableArea).children((options.countOnlyClass)).each(function(){$mom.scrollableAreaWidth=$mom.scrollableAreaWidth+$(this).outerWidth(true);});$mom.find(options.scrollableArea).css("width",$mom.scrollableAreaWidth+'px');}
$mom.find(options.scrollWrapper).scrollLeft("0");var bodyWidth=$("body").innerWidth();if($mom.scrollableAreaWidth<bodyWidth)
{hideLeftHotSpot();hideRightHotSpot();}
else
{showHideHotSpots();}}
function hideLeftHotSpot(){$mom.find(options.scrollingHotSpotLeft).hide();}
function hideRightHotSpot(){$mom.find(options.scrollingHotSpotRight).hide();}
function showLeftHotSpot(){$mom.find(options.scrollingHotSpotLeft).show();if(hotSpotWidth<=0)
{hotSpotWidth=$mom.find(options.scrollingHotSpotLeft).width();}}
function showRightHotSpot(){$mom.find(options.scrollingHotSpotRight).show();if(hotSpotWidth<=0)
{hotSpotWidth=$mom.find(options.scrollingHotSpotRight).width();}}
function setHotSpotHeightForIE()
{jQuery.each(jQuery.browser,function(i,val){if(i=="msie"&&jQuery.browser.version.substr(0,1)=="6")
{$mom.find(options.scrollingHotSpotLeft).css("height",($mom.find(options.scrollableArea).innerHeight()));$mom.find(options.scrollingHotSpotRight).css("height",($mom.find(options.scrollableArea).innerHeight()));}});}
var rightScrollInterval;var scrollXpos;$mom.find(options.scrollingHotSpotRight).bind('mousemove',function(e){var x=e.pageX-(this.offsetLeft+motherElementOffset);x=Math.round(x/(hotSpotWidth/15));scrollXpos=x;});$mom.find(options.scrollingHotSpotRight).bind('mouseover',function(e){rightScrollInterval=setInterval(doScrollRight,15);});$mom.find(options.scrollingHotSpotRight).bind('mouseout',function(e){clearInterval(rightScrollInterval);scrollXpos=0;});$mom.find(options.scrollingHotSpotRight).bind('mousedown',function(e){booster=options.mouseDownSpeedBooster;});$("*").bind('mouseup',function(e){booster=1;});var doScrollRight=function()
{$mom.find(options.scrollWrapper).scrollLeft($mom.find(options.scrollWrapper).scrollLeft()+(scrollXpos*booster));showHideHotSpots();};var leftScrollInterval;$mom.find(options.scrollingHotSpotLeft).bind('mousemove',function(e){var x=$mom.find(options.scrollingHotSpotLeft).innerWidth()-(e.pageX-motherElementOffset);x=Math.round(x/(hotSpotWidth/15));scrollXpos=x;});$mom.find(options.scrollingHotSpotLeft).bind('mouseover',function(e){leftScrollInterval=setInterval(doScrollLeft,15);});$mom.find(options.scrollingHotSpotLeft).bind('mouseout',function(e){clearInterval(leftScrollInterval);scrollXpos=0;});$mom.find(options.scrollingHotSpotLeft).bind('mousedown',function(e){booster=options.mouseDownSpeedBooster;});var doScrollLeft=function()
{$mom.find(options.scrollWrapper).scrollLeft($mom.find(options.scrollWrapper).scrollLeft()-(scrollXpos*booster));showHideHotSpots();};function showHideHotSpots()
{if($mom.find(options.scrollWrapper).scrollLeft()===0)
{hideLeftHotSpot();showRightHotSpot();}
else if(($mom.scrollableAreaWidth)<=($mom.find(options.scrollWrapper).innerWidth()+$mom.find(options.scrollWrapper).scrollLeft()))
{hideRightHotSpot();showLeftHotSpot();}
else
{showRightHotSpot();showLeftHotSpot();}}});};})(jQuery);