﻿var intCurrentProject = 0;
var intProjectCount = 0;
var blnMoving = false;
var strImages = '';

function InitializeProjectImages() {
    strImages = document.getElementById('imgs').value;
    intImageCount = document.getElementById('img_count').value;
}

function resizeWindow() {
    var size = [0, 0];
    if (typeof window.innerWidth != "undefined") {
        intWidth = window.innerWidth;
        intHeight = window.innerHeight;
    }
    else if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth != 0) {
        intWidth = document.documentElement.clientWidth;
        intHeight = document.documentElement.clientHeight;
    }
    else {
        intWidth = document.getElementsByTagName("body")[0].clientWidth;
        intHeight = document.getElementsByTagName("body")[0].clientHeight;
    }

    intWidth = (Math.max(intWidth - 1050, 0)) / 2;
    document.getElementById('div_main').style.left = intWidth + 'px';
    document.getElementById('div_main').style.marginLeft = '0px';
}

window.onresize = function() {
    resizeWindow();
};

var intCurrentImageIndex = 0;
var intCurrentLargeImageIndex = 0;
var intImageCount = 0;
function showNextImage() {
    if (blnMoving != true) {
        blnMoving = true;
        if (intCurrentImageIndex >= intImageCount - 2) {
            var t1 = new Tween(document.getElementById('div_project_images').style, 'top', Tween.strongEaseOut, -(intCurrentImageIndex * 186), 0, 2, 'px');
            t1.onMotionFinished = function() { blnMoving = false; };
            t1.start();
            intCurrentImageIndex = 0;
        } else {
        var t1 = new Tween(document.getElementById('div_project_images').style, 'top', Tween.strongEaseOut, -(intCurrentImageIndex * 186), -((intCurrentImageIndex + 1) * 186), 2, 'px');
            t1.onMotionFinished = function() { blnMoving = false; };
            t1.start();
            intCurrentImageIndex += 1;
        } 
    }
}

function showPreviousImage() {
    if (blnMoving != true) {
        blnMoving = true;
        if (intCurrentImageIndex <= 0) {
            var t1 = new Tween(document.getElementById('div_project_images').style, 'top', Tween.strongEaseOut, -(intCurrentImageIndex * 186), -((intImageCount - 2) * 186), 2, 'px');
            t1.onMotionFinished = function() { blnMoving = false; };
            t1.start();
            intCurrentImageIndex = intImageCount - 2;
        } else {
            var t1 = new Tween(document.getElementById('div_project_images').style, 'top', Tween.strongEaseOut, -(intCurrentImageIndex * 186), -((intCurrentImageIndex - 1) * 186), 2, 'px');
            t1.onMotionFinished = function() { blnMoving = false; };
            t1.start();
            intCurrentImageIndex -= 1;
        }
    }
}

function showLargeImage(intImageIndexP) {
    intCurrentLargeImageIndex = intImageIndexP;
    document.getElementById('imgLargeImage').src = strImages.split("#")[intCurrentLargeImageIndex];
    document.getElementById('div_mask').style.display = 'block';
}

function closeLargeImage() {
    document.getElementById('div_mask').style.display = 'none';
}

function loadNextImage() {
    if (intCurrentLargeImageIndex >= intImageCount - 1) {
        intCurrentLargeImageIndex = 0;
    } else {
        intCurrentLargeImageIndex += 1;
    }
    document.getElementById('imgLargeImage').src = strImages.split("#")[intCurrentLargeImageIndex];
}

function loadPreviousImage() {
    if (intCurrentLargeImageIndex < 1) {
        intCurrentLargeImageIndex = intImageCount - 1;
    } else {
        intCurrentLargeImageIndex -= 1;
    }
    document.getElementById('imgLargeImage').src = strImages.split("#")[intCurrentLargeImageIndex];
}
