﻿/// <reference path="jquery-1.3.2-vsdoc2.js"/>

//------------------------------------------------
var movieShowing = false;
var movieHolder = "";
var movieImage = "";
function ShowMovie(baseURL, movieHolderID, movieImageID, movieURL) {
    $("#" + movieImageID).fadeOut("slow", function() {
    $("#" + movieHolderID).show();
    flowplayer(movieHolderID, baseURL + "/images/swf/flowplayer-3.1.0.swf", baseURL + movieURL);
        movieShowing = true;
        movieHolder = movieHolderID;
        movieImage = movieImageID;
    });
}

function HideMovie(frameId) {
    $("#" + movieHolder).hide();
    $("#" + movieImage).fadeIn("slow", function() {
        movieShowing = false;
        ScrollTo(frameId);
    });
}

//------------------------------------------------

function ShowCaseStudy() {
    if ($.browser.msie)
        $(".stateList").hide();
    animateBackground = false;
    $("#caseStudyDisplay").show();
    SetPositionToCenter("caseStudyDisplay", 0, 0);
    $("#caseStudyDisplay").hide();
    $("#caseStudyDisplay").css("visibility", "visible");
    $("#caseStudyDisplay").fadeIn("slow", function() {
        CarouselInit();
    });
}

function HideCaseStudy() {
    $("#caseStudyDisplay").fadeOut("normal", function() {
        $("#caseStudyDisplay").css("visibility", "hidden");
        if ($.browser.msie)
            $(".stateList").show();
    });
}

var navArray;
var navArrayCurrentIndex = 0;
var navArrayMaxIndex;
function CarouselNavInit() {
    navArray = new Array();
    navArrayCurrentIndex = 0;
    $(".carouselLink").each(function() {
        navArray.push($(this).attr("frameHolder"));
    });
    navArrayMaxIndex = navArray.length - 1;
}

function CarouselInit() {
    $(document).ready(function() {
        CarouselNavInit();
        ScrollTo(navArray[navArrayCurrentIndex]);
    });
}

function ScrollTo(frameId) {
    if (movieShowing) {
        HideMovie(frameId);
    }
    else {
        $("#framesHolder").scrollTo($("#" + frameId), "slow", { axis: 'x' });
        SetCurrentIndex(frameId);
        SetNavHighLight(frameId);
        ToggleArrowsVisiblity();
    }
}

function SetCurrentIndex(frameId) {
    for (i = 0; i <= navArrayMaxIndex; i++ ) { 
        if (navArray[i] == frameId) {
            navArrayCurrentIndex = i;
        }
    }
}

function ToggleArrowsVisiblity() {
    if (navArrayCurrentIndex == 0)
        $("#leftArrow").fadeOut("fast");
    else {
        $("#leftArrow").fadeIn("fast");
    }
    if (navArrayCurrentIndex == navArrayMaxIndex)
        $("#rightArrow").fadeOut("fast");
    else {
        $("#rightArrow").fadeIn("fast");
    }    
}

function SetNavHighLight(frameId) {
    $(".carouselLink").each(function() {
        if ($(this).attr("frameHolder") == frameId) {
            $(this).addClass("carouselLinkHighlight");
        }
        else {
            $(this).removeClass("carouselLinkHighlight");
        }
    });
}



function AdvanceCarousel() {
    if (navArrayCurrentIndex == navArrayMaxIndex) {
        navArrayCurrentIndex = 0;
    }
    else {
        navArrayCurrentIndex++;
    }
    ScrollTo(navArray[navArrayCurrentIndex]);
    
}

function ReverseCarousel() {
    if (navArrayCurrentIndex == 0)
        navArrayCurrentIndex = navArrayMaxIndex;
    else
        navArrayCurrentIndex--;
    ScrollTo(navArray[navArrayCurrentIndex]);
}
