﻿//Menu functions----------------------------------------------------------------
var currentlyVisibleMenu = "";
var timeOut = null;
function ShowMenu(menuId, object) {
    CancelHide();
    if (currentlyVisibleMenu != "")
        $("#" + currentlyVisibleMenu).hide();
    $("#" + menuId).show();
    currentlyVisibleMenu = menuId;
}

function HideSubmenu() {
    if (currentlyVisibleMenu != "") {
        $("#" + currentlyVisibleMenu).fadeOut("slow", function() {

        });
        currentlyVisibleMenu = "";
    }
}

function StartHide() {
    if (timeOut == null)
        timeOut = setTimeout("HideSubmenu();", 1500);
}

function CancelHide() {
    if (timeOut != null) {
        clearTimeout(timeOut);
        timeOut = null;
    }
}

var animationQueue = new Queue();
var currentMouseOver = "";

function ShowRollover(object, rolloverObject) {
    currentMouseOver = rolloverObject;
    animationQueue.enqueue(rolloverObject);
    AnimationStart();
}

function HideRollover(object, rolloverObject) {
    currentMouseOver = "";
    animationQueue.enqueue(rolloverObject + ":OFF");
    AnimationStart();
}

var animationLock = false;
function AnimationStart() {
    if (!animationLock) { animationLock = true; ProcessQueue(); }
}

function ProcessQueue() {
    if (animationQueue.isEmpty()) { animationLock = false; }
    else {
        var fadeIn = true;
        var dequed = animationQueue.dequeue();
        if (dequed.indexOf(":OFF") > -1)
            fadeIn = false;
        var objectID = dequed.replace(":OFF", "");
        if (fadeIn && objectID == currentMouseOver) {
            $("#" + objectID).fadeTo("fast", 1, function() {
                ProcessQueue();
            });
        }
        else if (!fadeIn && objectID != currentMouseOver) {
            $("#" + objectID).fadeTo("fast", 0, function() {
                ProcessQueue();
            });
        }
        else {
            ProcessQueue();
        }
    }
}

//Header rotation functions-----------------------------------------------

var stripArray = [];
function SetStripArray() {
    $(".rotatingHeaderImage").each(function(index) {
        stripArray.push("#" + this.id);
    });
}

var stripDelay = 4000;
var stripFadeSpeed = 4000;
function RotateStrip(i, fadeSpeed) {
    var arrayLength = stripArray.length;
    var maxIndex = arrayLength - 1;
    var previousIndex = i - 1;
    if (previousIndex < 0)
        previousIndex = maxIndex;
    var currentIndex = i;
    var nextIndex = currentIndex + 1;
    if (nextIndex > maxIndex)
        nextIndex = 0;

    $(stripArray[previousIndex]).css("z-index", "-10");
    $(stripArray[currentIndex]).css("z-index", "0");

    $(stripArray[currentIndex]).fadeIn(fadeSpeed, function() {
        $(stripArray[previousIndex]).hide();

        var functionString = "RotateStrip(" + nextIndex + ", " + stripFadeSpeed + ");";
        setTimeout(functionString, stripDelay);
    });
}
//bios functions----------------------------------------------------------

var currentBio = "";
function ShowBio(bioName) {
    HideCurrentBio();
    $("#" + bioName + "Expander").fadeOut("fast", function() {
        $("#" + bioName + "Details").slideDown("fast");
        currentBio = bioName;
    });
}

function HideCurrentBio() {
    if (currentBio != "") {
        $("#" + currentBio + "Details").slideUp("fast", function() {
            $("#" + currentBio + "Expander").fadeIn("fast");
            currentBio = "";
        });
    }
}

//portfolio functions-----------------------------------------------------

function ShowLargeImage(imageUrl, categoryName) {
    SetPositionToCenter("viewerHolder", 265, 300);
    $("#largeImage").attr("src", imageUrl);
    $("#viewerCategoryTitle").html(categoryName);
    $("#viewerHolder").fadeIn("fast", function() {
        if (!$.browser.msie) {
            $("#outerHolder").fadeTo("fast", 0.25);
        }
    });
}

function CloseLargeImage() {
    $("#viewerHolder").fadeOut("fast", function() {
        $("#largeImage").attr("src", "");
        if (!$.browser.msie) {
            $("#outerHolder").fadeTo("fast", 1);
        }
    });
}

function SetPositionToCenter(objectId, objectWidth, objectHeight) {
    var topPosition = ($(window).scrollTop() + ($(window).height() / 2) | 0) - objectHeight;
    var leftPosition = ($(window).scrollLeft() + ($(window).width() / 2) | 0) - objectWidth;
    document.getElementById(objectId).style.top = topPosition + "px";
    document.getElementById(objectId).style.left = leftPosition + "px";
}
//form submission functions-----------------------------------------------

function ShowThankyou() {
    $("#submitHolder").fadeOut("fast", function() {
        $("#formThankyou").fadeIn("fast");
    });
}

function HideThankyou() {
    $("#formThankyou").fadeOut("fast", function() {
        $("#submitHolder").fadeIn("fast", function() {
            $('html, body').animate({ scrollTop: 0 }, 'slow');
        });
    });
}

//------------------------------------------------------------------------
$(document).ready(function() {
    $.localScroll();
    SetStripArray();
    if (stripArray.length > 0) {
        var randomnumber = Math.floor(Math.random() * stripArray.length)
        RotateStrip(randomnumber, 0);
    }
    
});