﻿/// <reference path="jquery-1.4.1-vsdoc.js" />
var galleryTimer;

//Javascript init
var jsSize = 0;
switch(websiteSize)
{
    case 0:
        jsSize = 0.64;
    break;
    case 1:
        jsSize = 0.8;
    break;
    case 2:
        jsSize = 1;
    break;
}//switch

function resValue(int1, int2, int3) {

    switch (websiteSize) {
        case 0:
            return int1;
            break;
        case 1:
            return int2;
            break;
        case 2:
            return int3;
            break;
    } //switch
} //resValue


function calcValue(intValue) {
    return parseInt(intValue * jsSize);
} //calcValue

//When dom is ready.
$(document).ready(function() {

    switch (pagetype) {

        case 10:
            startImageRotater("div-imagelist-left-container", "", 3000);
            startImageRotater("div-imagelist-right-container", "", 3000);
            break;
    } //switch
});


function move(containerElementClass, elementClass, direction, distance) {

    //Complete any running animation
    $("." + elementClass).stop(true, true);

    //Calc new position
    var newLeft = $("." + elementClass).position().left + (direction * distance);

    //Check max / min
    if (direction > 0) {
        if (newLeft > 0)
            newLeft = 0;
    }
    else {
        var minLeft = -1 * ($("." + elementClass).width() - $("." + containerElementClass).width());
        if (newLeft < minLeft)
            newLeft = minLeft;
    }

    //start new animation
    $("." + elementClass).css({ "left": newLeft + "px" }, 500);
}

function slide(containerElementClass, elementClass, direction, distance) {

    //Complete any running animation
    $("." + elementClass).stop(true, true);

    //Calc new position
    var newLeft = $("." + elementClass).position().left + (direction * distance);

    //Check max / min
    if (direction > 0) {
        if (newLeft > 0)
            newLeft = 0;
    }
    else {
        var minLeft = -1 * ($("." + elementClass).width() - $("." + containerElementClass).width());
        if (newLeft < minLeft)
            newLeft = minLeft;
    }

    //start new animation
    $("." + elementClass).animate({ "left": newLeft + "px" }, 500);
}

function startImageRotater(imageContainer, counterContainer, interval) {

    if ($("." + imageContainer + " img").length > 0)
        setInterval("nextImage('" + imageContainer + "','" + counterContainer + "')", interval);
} //startImageRotater


function nextImage(imageContainer, counterContainer) {

    //Check if more that one image in container
    if ($("." + imageContainer).children().length > 1) {

        $("." + imageContainer + " img").stop(true, true);
        if(counterContainer.length > 0)
            $("." + counterContainer + " span").stop(true, true);
        
        //IMAGE
        var $currentImage = $("." + imageContainer + " .show");
        var $nextImage = $currentImage.next().length > 0 ? $currentImage.next() : $("." + imageContainer + " :first");

        $nextImage.css({ "display": "block", "z-index": "1", "opacity": "0.0" });
        $currentImage.css({ "z-index": "0" });

        $nextImage.animate({ "opacity": "1.0" }, 1000, "", function () {

            $("." + imageContainer + " .show").css({ "display": "none", "opacity": "0.0" }).addClass("hide").removeClass("show");
            $(this).addClass("show").removeClass("hide");
        });

        //TEXT
        if (counterContainer.length > 0) {

            var $currentText = $("." + counterContainer + " .show");
            var $nextText = $currentText.next().length > 0 ? $currentText.next() : $("." + counterContainer + " :first");

            $nextText.css({ "display": "block", "z-index": "1", "opacity": "0.0" });
            $currentText.css({ "z-index": "0" });

            $currentText.animate({ "opacity": "0.0" }, 1000, "", function () {

                $(this).addClass("hide").removeClass("show");
            });
            $nextText.animate({ "opacity": "1.0" }, 1000, "", function () {

                $(this).addClass("show").removeClass("hide");
            });
        }//if
    }//if
} //nextImage

function prevImage(imageContainer, counterContainer) {

    //Check if more that one image in container
    if ($("." + imageContainer).children().length > 1) {

        $("." + imageContainer + " img").stop(true, true);
        
        //IMAGE
        var $currentImage = $("." + imageContainer + " .show");
        var $nextImage = $currentImage.prev().length > 0 ? $currentImage.prev() : $("." + imageContainer + " :last");

        $nextImage.css({ "display": "block", "z-index": "1", "opacity": "0.0" });
        $currentImage.stop(true, true).css({ "z-index": "0" });

        $nextImage.stop(true,true).animate({ "opacity": "1.0" }, 1000, "", function () {

            $("." + imageContainer + " .show").css({ "display": "none", "opacity": "0.0" }).addClass("hide").removeClass("show");
            $(this).addClass("show").removeClass("hide");
        });

        //TEXT
        if (counterContainer.length > 0) {

            $("." + counterContainer + " span").stop(true, true);
        
            var $currentText = $("." + counterContainer + " .show");
            var $nextText = $currentText.prev().length > 0 ? $currentText.prev() : $("." + counterContainer + " :last");

            $nextText.css({ "display": "block", "z-index": "1", "opacity": "0.0" });
            $currentText.stop(true, true).css({ "z-index": "0" });

            $currentText.stop(true, true).animate({ "opacity": "0.0" }, 1000, "", function () {

                $(this).addClass("hide").removeClass("show");
            });
            $nextText.stop(true, true).animate({ "opacity": "1.0" }, 1000, "", function () {

                $(this).addClass("show").removeClass("hide");
            });
        } //if
    } //if
} //nextImage

function callEIMethod(name, method) {
    thisMovie(name)[method]();
}
function thisMovie(movieName) {
    return document[movieName];
} 
