﻿
$(window).load(function () {
    inv_sidescroll();
});

var inv_sidescroll = function () {
    $this = $('div.photo-select');
    $this.wrapInner('<div class="photo-select-inner" />');
    $this.wrapInner('<div class="thumb-wrapper" />');
    $inner = $('div.photo-select .thumb-wrapper');
    $inner.attr('max',  $('div.photo-select .photo-select-inner').height());
    if ($inner.height() > $this.height()) {
        $inner.height($this.height() - 20);
        $this.addClass('has-scroll');
        $this.prepend('<a href="" class="scrolluplink"><img src="/images/inventory/arrow_up.png" class="arrow scrollup" width="30" height="30" alt="Up" /></a>');
        $this.append('<a href="" class="scrolldownlink"><img src="/images/inventory/arrow_down.png" class="arrow scrolldown" width="30" height="30" alt="Up" /></a>');
        $('div.photo-select .scrolluplink').click(function (evt) {
            evt.preventDefault();
            evt.stopPropagation();
            inv_scrollup();
        });
        $('div.photo-select .scrolldownlink').click(function (evt) {
            evt.preventDefault();
            evt.stopPropagation();
            inv_scrolldown();
        });
    } else {

    }
};

var inv_scrollup = function () {
    $this = $('div.photo-select .photo-select-inner');
    cur_top = parseInt($this.css("top").replace('px', ''));
    cur_top += 95;
    if (cur_top > 0 ) { cur_top = 0; }
    $this.css('top', cur_top + 'px');


};

var inv_scrolldown = function () {
    $this = $('div.photo-select .photo-select-inner');
    min_top = $this.parent().height() - $this.parent().attr("max");
    cur_top = parseInt($this.css("top").replace('px', ''));
    cur_top -= 95;
    if (cur_top < min_top) { cur_top = min_top; }
    $this.css('top', cur_top + 'px');

};
