﻿/// <reference path="jquery-1.3.2-vsdoc2.js"/>

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();
        }
    }
}

function ClearField(object, text) {
    if (document.getElementById(object.id).value == text) {
        document.getElementById(object.id).style.color = "black";
        document.getElementById(object.id).value = "";
    }
}

function RestoreField(object, text) {
    if (document.getElementById(object.id).value == "") {
        document.getElementById(object.id).style.color = "gray";
        document.getElementById(object.id).value = text;
    }
}

function Test() {
    setTimeout("Timeout();", 1000);
}

function Timeout() {
    $("#servicesStrip").fadeIn(4000);
}

var stripArray = [];
function SetStripArray() {
    $(".stripHolder").each(function(index) {
        stripArray.push("#" + this.id);
    });
}

var stripDelay = 4000;
var stripFadeSpeed = 4000;
var stripTimeout;
var animateBackground = true;
function RotateStrip(i) {
    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(stripFadeSpeed, function() {
        $(stripArray[previousIndex]).hide();

        var functionString = "RotateStrip(" + nextIndex + ");";
        if(animateBackground)
            stripTimeout = setTimeout(functionString, stripDelay);               
    });
}

function ScrollSecondaryFrameTo(frameHolderId, frameId) {
    $("#"+frameHolderId).scrollTo($("#" + frameId), "slow", { axis: 'x' });
}

$(document).ready(function() {
    $.localScroll();
    $(".rolloverImage").fadeTo(0, 0);
    SetStripArray();
    var randomnumber = Math.floor(Math.random() * stripArray.length)
    $(stripArray[randomnumber]).show();
    //RotateStrip(randomnumber);
});
