$j = jQuery.noConflict();

$j(document).ready(function() {
    var objDetail = $j('#detail ul li');
    var objThum = $j('#thum_list ul li');
    var page = window.location.toString().match(/(\d{2}).html/) == null ? 1 : window.location.toString().match(/(\d{2}).html/);
    var count = 0;
    var liLeft = [];

    $j('#scroll_right').click(function() {
        var liSize = objDetail.length;

        if (liSize > 6) {
            if (((count + 1) * 6) + 6 < liSize) {
                if (objDetail.eq(liSize - 1).css('left').match(/[\d-]*/) <= 700) {
                    return false;
                } else {
                    count++;
                }
                objDetail.each(function() {
                    $j(this).animate({
                        'left': ($j(this).css('left').match(/[\d-]*/) - (6 * 135)) + 'px'
                    },
                    {
                        queue: true,
                        duration: 100
                    });
                });
            } else {
                objDetail.each(function(idx) {
                    if (idx == liSize - 6) {
                        liLeft[idx] = '25px';
                    } else {
                        liLeft[idx] = ($j(this).css('left').match(/[\d-]*/) - ($j('#detail ul li').eq(liSize - 6).css('left').match(/[\d-]*/) - 25)) + 'px';
                    }
                });
                objDetail.each(function(idx) {
                    $j(this).animate({
                        'left': liLeft[idx]
                    },
                    {
                        queue: true,
                        duration: 100
                    });
                });
            }
        }
    });

    $j('#scroll_left').click(function() {
        var liSize = objDetail.length;

        if (liSize > 6) {
            if (((count + 1) * 6) - 6 > 0) {
                if (objDetail.eq(0).css('left').match(/[\d-]*/) >= 25) {
                    return false;
                } else {
                    count--;
                }

                objDetail.each(function() {
                    $j(this).animate({
                        'left': (parseInt($j(this).css('left').match(/[\d-]*/)) + (6 * 135)) + 'px'
                    },
                    {
                        queue: false,
                        duration: 100
                    });
                });
            } else {
                objDetail.each(function(idx) {
                    if (idx == 0) {
                        liLeft[idx] = '25px';
                    } else {
                        liLeft[idx] = ($j(this).css('left').match(/[\d-]*/) - (parseInt($j('#detail ul li').eq(0).css('left').match(/[\d-]*/)) - 25)) + 'px';
                    }
                });
                objDetail.each(function(idx) {
                    $j(this).animate({
                        'left': liLeft[idx]
                    },
                    {
                        queue: true,
                        duration: 100
                    });
                });
            }
        }
    });

    if (page[1] > 12) {
        objThum.each(function() {
            $j(this).css({'left': ($j(this).css('left').match(/[\d-]*/) - (64 * (page[1] - 12))) + 'px'});
        });
    }

    $j('#tscroll_right').click(function() {
        var liSize = objThum.length;

        if (objThum.eq(liSize - 1).css('left').match(/[\d-]*/) <= 704) {
            return false;
        }
        objThum.each(function() {
            $j(this).animate({
                'left': ($j(this).css('left').match(/[\d-]*/) - 64) + 'px'
            },
            {
                queue: false,
                duration: 100
            });
        });
    });

    $j('#tscroll_left').click(function() {
        if (objThum.eq(0).css('left').match(/[\d-]*/) >= 0) {
            return false;
        }
        objThum.each(function() {
            $j(this).animate({
                'left': (parseInt($j(this).css('left').match(/[\d-]*/)) + 64) + 'px'
            },
            {
                queue: false,
                duration: 100
            });
        });
    });
});