﻿var puppiesWidth = 1032;
var boxWidth = 505;
var diff = 0;
var dist = 0;
var fromIndex = 0;
//var toindex = 1;

var rotating = false;
var direction = 0;
var angle = 0;

$(function () {
    getFirstPosition();
    slideTo(5);
    $('.newToolbar td').click(function () {
        if ($(this).attr('id') != fromIndex) {
            slideTo($(this).attr('id'));
        }
    });
});

/***********************************/

function getFirstPosition() {
    var screenWidth = $(window).width();

    dist = puppiesWidth + (boxWidth / 2);

    diff = ((screenWidth / 2) - dist);

    dist = puppiesWidth + boxWidth;
}

function slideTo(toIndex) {
    if (fromIndex == 6) {
        $.ajax({
            type: 'GET',
            url: '/Partials/Contact',
            success: function (data) {
                $('#contactUsWrappingDIV').html(data);
            },
            error: function (x, y, z) {
                alert(x.responseText);
            }
        });
    }

    updateSignatures();
    rotating = true;

    if (toIndex > fromIndex) {
        direction = 9;
    } else {
        direction = -9;
    }

    doRotation();

    /*$('#' + toIndex).css('background-image', 'url("/Content/buttonBackground.png")');
    $('#' + toIndex).css('color', '#000000');
    //$('#' + toIndex).css('border', 'none');

    $('#' + fromIndex).css('background-image', 'none');
    $('#' + fromIndex).css('color', '#FFFFFF');
    //$('#' + fromIndex).css('border', '1px solid #FFFFFF');*/

    $('.newToolbar').css('backgroundPosition', '0px -' + ((toIndex * 50) - 50).toString() + 'px');

    if (toIndex == 1) {
        $('#contentWrapper').animate({ left: diff.toString() + 'px' }, 1000, function () { rotating = false; /*window.angle = 0;*/ });
    }
    else {
        $('#contentWrapper').animate({ left: (diff + (-(dist * (toIndex - 1)))).toString() + 'px' }, 1000, function () { rotating = false; /*window.angle = 0;*/ });
    }

    fromIndex = toIndex;
}

function doRotation() {
    if (rotating) {
        window.interval = setInterval(function () {
            if (rotating) {
                angle += direction;
                $("#medium_cog").rotate(angle);
                $("#minicog1").rotate(-angle);
                $("#minicog2").rotate(angle);
                $("#big_cog").rotate(angle);
            }
            else {
                //angle = window.angle;
                clearInterval(window.interval);
            }
        }, 50);
    }
}
