﻿
var last_indent = parseInt(0);
var image_index = parseInt(0);
var image_index_ver = parseInt(0);

function move_image() {
    var skip = 0, i = 0, w = 0;

    if (arguments.length > 0)
        skip = arguments[0];
    
    i = parseInt(image_index) + parseInt(skip);
    if (i < 0) i = 0;

    var img = $('#image_viewer img').get(i);
    w = (($('#content_info').width() - $(img).width()) / 2) - 20;
    if (i == 0) w = 0;    
    

    var pos = $(img).position();    
    var x = (0 - pos.left) + w;
    
    $('#image_viewer').animate({ left: x + 'px' }, { queue: false, duration: 500 });
    $('#image_title').html(img.alt);

    last_indent = w;
    image_index = i;
}


function move_image_ver(skip) {
    var i = image_index_ver + skip;
    if (skip == 0 && image_index_ver == -1) i = 0;
    if (i >= 0 && i <= 8) {
        var img2 = $($('#horizontal_viewer div').get(i)).position();
        var img = $('#horizontal_viewer div').get(i + 1);
        var x = (0 - img2.top);
        $('#horizontal_viewer').animate({ top: x + 'px' }, { queue: false, duration: 300 });
        image_index_ver += skip;
    }
}


function init_horizontal_nav() {
    var imgs = new Array();

    get_images(imgs);

    $('#horizontal_nav').html('<div id="horizontal_viewer"><div><span class="img_title"></span>' + imgs.join('</div><div><span class="img_title"></span>') + '</div></div>');
    $('#horizontal_nav img').each(function(i) {
        var txt = this.src;
        this.id = i;
        this.src = txt.replace('_big', '_thumb');
        $(this).css({ cursor: 'pointer' });

        $(this).siblings('span').html('<center>' + this.alt + '</center>').css({ textAlign: 'left' });
    });
    
    
    
}


function init_viewer() {
    var w = 0, x = 0;
    var vwr = $('#image_viewer');
    var inf = $('#content_info');
    var img = $('.image_mover');
    var div = $('.div_mover');
    var hor = $('#horizontal_nav');

    //adjust width
    if (!document.all) vwr.css({ position: 'relative' });
    $('#image_viewer img').each(function(i) { w += $(this).width() + 43; });

    vwr.width(w);


    x = img.filter('#left').width();
    w = $('#content').width() - $('#horizontal_nav').width();
    w = w - x - x-50;
    inf.width(w);

    w = hor.width() + x + 20;
    inf.css({ left: w + 'px' });

    var pos = inf.position();
    var h = (inf.height() - img.filter('#right').height()) / 2;

    div.css({ top: (pos.top) + 'px' });
    img.css({ top: (h) + 'px' });

    pos = inf.offset();
    w = inf.width();
    
    div.filter('#left').css({ left: (pos.left - x) + 'px' });
    div.filter('#right').css({ left: (pos.left + w) + 'px' });

    x = $('.image_mover').filter('#up').height();
    h = inf.height();
    hor.css({ left: 110 + 'px', height: (h - x - x) + 'px', top: (pos.top + x) + 'px' });

    w = (hor.width() - $('.image_mover').filter('#up').width()) / 2;
    t = pos.top;
    pos = hor.offset();
    $('.image_mover').filter('#up').css({ left: (pos.left + w) + 'px', top: t + 'px' });
    $('.image_mover').filter('#down').css({ left: (pos.left + w) + 'px', top: (t + h - x) + 'px' });

    vwr.width(5000);
}

function init_svc_images() {
    var imgs = new Array();
    
    get_images(imgs);
    $('#image_viewer').html(imgs.join(''));
}

function get_images(imgs) {
    imgs.push('<img alt= "Amada Service Team"           src="../central/image/support/svcteam/pic_amada_big.jpg" />');
    imgs.push('<img alt= "Cutting Tools Service Team"        src="../central/image/support/svcteam/pic_ct_big.jpg" />');
    imgs.push('<img alt= "Mazak Service Team"           src="../central/image/support/svcteam/pic_mazak_big.jpg" />');
    imgs.push('<img alt= "Mitsubishi Service Team"      src="../central/image/support/svcteam/pic_mitsubishi_big.jpg" />');
    imgs.push('<img alt= "Mitutoyo Service Team"        src="../central/image/support/svcteam/pic_mitutoyo_big.jpg" />');
    imgs.push('<img alt= "Hydraulics Service Team"         src="../central/image/support/svcteam/pic_vickers_big.jpg" />');
    imgs.push('<img alt= "Manufacturing Team"   src="../central/image/support/svcteam/pic_mfg_big.jpg" />');
    imgs.push('<img alt= "Logistics Team"       src="../central/image/support/svcteam/pic_log_big.jpg" />');
    imgs.push('<img alt= "IT Team"              src="../central/image/support/svcteam/pic_it_big.jpg" />');

/*
    imgs.push('<img alt= "" src="../central/image/support/svcteam/pic_vickers_thumb.jpg" />');
    imgs.push('<img alt= "" src="../central/image/support/svcteam/pic_amada_thumb.jpg" />');    
    imgs.push('<img alt= "" src="../central/image/support/svcteam/pic_ct_thumb.jpg" />');
    imgs.push('<img alt= "" src="../central/image/support/svcteam/pic_it_thumb.jpg" />');
    imgs.push('<img alt= "" src="../central/image/support/svcteam/pic_log_thumb.jpg" />');
    imgs.push('<img alt= "" src="../central/image/support/svcteam/pic_mazak_thumb.jpg" />');
    imgs.push('<img alt= "" src="../central/image/support/svcteam/pic_mfg_thumb.jpg" />');
    imgs.push('<img alt= "" src="../central/image/support/svcteam/pic_mitsubishi_thumb.jpg" />');
    imgs.push('<img alt= "" src="../central/image/support/svcteam/pic_mitutoyo_thumb.jpg" />');
*/
}




function remove_from_index()
{
    if (image_index >= -1) {
        image_index -= 1;
        var pos = $('#image_viewer').position();
        var img1 = $($('#image_viewer img').get(image_index + 2)).position();
        var img2 = $($('#image_viewer img').get(image_index + 1)).position();
        var img = $('#image_viewer img').get(image_index + 1);
        var w = (($('#content_info').width() - $(img).width()) / 2) - 20;
        var x = (0 - img2.left) + w;

        last_indent = w;
        $('#image_viewer').animate({ left: x + 'px' }, { queue: false, duration: 500 });
        $('#image_title').html(img.alt);
    }
}
