/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 9/11/2008
 * @author Ariel Flesler
 * @version 1.4
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
if(typeof my=="undefined"){my = {};}
my.Scroller = function(element, options) {
  this.frameElt = $(element);
  this.contentElt = this.frameElt.find('.inner-content');
  this.tabsElt = $('#tabs');
  this.autoScroll = true;
        this.currentSection = $('#kg')

        var scroller = this
        this.tabsElt.find('a').mouseover(function(e){
                var scrollitem = $(this).attr('href')
                scroller.scrollTo($(scrollitem))
                scroller.autoScroll = false
        }).click(function(){ return false })

        // setInterval("scroller.doAutoScroll()", 7000)
        setInterval("scroller.doAutoScroll()", 70000)

  this.scrollTo = function(scrollitemElt) {
    var newIndex = this.contentElt.find('.scrollitem').index(scrollitemElt);
    var destinationPosition = scrollitemElt.width() * -newIndex;

    this.contentElt.stop();
    this.contentElt.animate({'left':destinationPosition}, 'normal', 'swing');

    this.selectTab(scrollitemElt);
  };

  this.selectTab = function(selectionElt) {
                var tabName = selectionElt.attr('id');
    this.clearTabs();
    this.tabsElt.find("a[href='#" + tabName + "']").parent('li').addClass('current');
                this.currentSection = selectionElt;
  };

  this.clearTabs = function() {
    this.tabsElt.find('li').removeClass('current');
  };

        this.nextSection = function() {
                var next = this.currentSection.next()
                if (next.length > 0) {
                        return next
                } else {
                        return $('#kg')
                }
        };

        this.doAutoScroll = function() {
                if (this.autoScroll) {
                        this.scrollTo(this.nextSection())
                }
        }
};


