﻿var img_index_1 = 0
var img_index_2 = 0

$(window).load(function() {
    var img = $('.gallery1 div').get(0);

    $('.gallery1').height($(img).height() + 30);
    $('.gallery2').height($(img).height()); 
})


$(document).ready(function() {

    preload_imgs();

    arrange_imgs('.gallery1');
    arrange_imgs('.gallery2');

    var img = $('.gallery1 div').get(0);

    $('.gallery1').height($(img).height() + 30);
    $('.gallery2').height($(img).height());
    $('#content_info1 #left').add('#content_info1 #right').css({ width: '10px', align: 'left' });
    $('#right').click(function() { move_image1(1); });
    $('#left').click(function() { move_image1(-1); });
});

function arrange_imgs(gallery) {
    var x = 0;

    $(gallery + ' div img').each(function(i) {
        var me = this;
        var parent = $(me).parent();

        parent.css({ position: 'absolute', left: (x) + 'px', margin: '2px', padding: '2px', borderStyle: 'none' });
        parent.width($(me).width());
        x += $(me).width() + 8;
    });

    $(gallery).width(x);
}

function move_image1(step) {
    var index = img_index_1 + step;
    var div = $('.gallery1 div').get(index);

    if (typeof (div) != 'undefined') {
        var pos = $(div).position();
        $('.gallery1').animate({ left: (0 - pos.left) + 'px' }, 'slow');
        img_index_1 = index;
    }
}

function preload_imgs() {

    var img_list = new Array(
        '../central/image/about_us/tour_amada_235x170.jpg',
        '../central/image/about_us/tour_mitutoyo_235x170.jpg',
        '../central/image/about_us/tour_mazak1_235x170.jpg',
        '../central/image/about_us/tour_iscar_235x170.jpg',
        '../central/image/about_us/tour_mitsubishi_235x170.jpg',
        '../central/image/about_us/tour_mazak2_235x170.jpg'
        )

    for (var i = 0; i < img_list.length; i++) {
        var pre_img = document.createElement('img');
        pre_img.src = img_list[i];
        pre_img.style.width = 1;
        pre_img.style.display = 'none';
    }
    
}

