﻿function GetCurrentPageIndex() {
    var page = GetHash();
    var index = 0;
    switch (page) {
        case "Home": index = 0; break;
        case "LivingSpaces": index = 1; break;
        case "AroundYou": index = 2; break;
        case "Tour": index = 3; break;
        case "News": index = 4; break;
        case "Connect": index = 5; break;
        case "Residents": index = 6; break;
        case "ForParents": index = 7; break;
    }
    return index;
}
function JSNavflashBackgroundLoaded() {
    myalert("PinnacleStudentBackground loaded");
    var pageIndex = GetCurrentPageIndex();
    myalert("page: " + pageIndex);
    if (true){ //pageIndex != 0) {
        window.setTimeout(function() {
            myalert(" attempting to change to page after load: " + pageIndex);
            getFlashMovie("PinnacleStudentBackground").JSchangePage(pageIndex);
            myalert("post attempt to change page");
        }, 50);
    }
    return pageIndex;
}
function JSgoHome() {
    baseGoPage("Home");
    $get(debugWorkaround.btnHome).click();
    myalert("JSgoHome");
}
function JSdumpHome() {
    baseDumpPage();
    myalert("JSdumpHome");
}
function JSgoLiving() {
    baseGoPage("LivingSpaces");
    $get(debugWorkaround.btnLivingSpaces).click();
    myalert("JSgoLiving");

}
function JSdumpLiving() {
    baseDumpPage();
    myalert("JSdumpLiving");
}
function JSgoAround() {
    baseGoPage("AroundYou");
    $get(debugWorkaround.btnAroundYou).click();
    $(".MapContent").show();
    //Make sure it's container is visible otherwise the map will not render properly
    $("#iframesContainer").show();
    DoFlashReload(".MapContent");
    var strPropLati = document.getElementById("PropHiddenLati").value;
    var strPropLong = document.getElementById("PropHiddenLong").value;
    fnLocatePlaceOnMap(strPropLati, strPropLong, 'MapArea', 14);
    myalert("JSgoAround");

}
function JSdumpAround() {
    baseDumpPage();
    myalert("JSdumpAround");
}
function JSgoTour() {
    baseGoPage("Tour");
    $get(debugWorkaround.btnTour).click();
    myalert("JSgoTour");
}
function JSdumpTour() {
    baseDumpPage();
    myalert("JSdumpTour");
}
function JSgoBlog() {
    baseGoPage("News");
    $get(debugWorkaround.btnTheBlog).click();
    myalert("JSgoBlog");
}
function JSdumpBlog() {
    baseDumpPage();
    myalert("JSdumpBlog");
}
function JSgoConnect() {
    baseGoPage("Connect");
    $get(debugWorkaround.btnConnect).click();
    myalert("JSgoConnect");
}
function JSdumpConnect() {
    baseDumpPage();
    myalert("JSdumpConnect");
}
function JSgoResidents() {
    baseGoPage("Residents");
    $get(debugWorkaround.btnResidents).click();
    myalert("JSgoResidents");
}
function JSdumpResidents() {
    baseDumpPage();
    myalert("JSdumpResidents");
}
function JSgoParents() {
    baseGoPage("ForParents");
    $get(debugWorkaround.btnForParents).click();
    myalert("JSgoParents");
}
function JSdumpParents() {
    baseDumpPage();
    myalert("JSdumpParents");
}
var CurrentPageToUse = "Home";
function baseGoPage(page) {
    CurrentPageToUse = page;
    try {
        pageTracker._trackPageview("/Default.aspx/" + page);
    } catch (e) { }
}
function baseDumpPage(x) {

    $("#iframesContainer .StaticContent").hide();
    $("#iframesContainer").hide();
}
function JSgoRedButton() {
    $.fn.colorbox({ href: baseURL() + "Applications.aspx", open: true, iframe: true, innerWidth: 775, innerHeight: 673 });
}

function makeScrollBarOnThing(jquerySelectedThing, maxHightFP1, fraction) {
    if (fraction === undefined) {
        fraction = 0.75;
    }
    if (jquerySelectedThing.height() >= maxHightFP1) {
        //If we're going to use a scrollbar, make it reasonable to scroll!
        jquerySelectedThing.height(Math.ceil(maxHightFP1 * fraction));
        jquerySelectedThing.jScrollPane();
    }
}
var TelerickResponseEndTimeout;
function TelerickResponseEnd(e) {
    try {
        //set the current page so we may bookmark it.
        if (TelerickResponseEndTimeout) {
            window.clearTimeout(TelerickResponseEndTimeout);
        }
        TelerickResponseEndTimeout = window.setTimeout(
            function() {
                SetHash(CurrentPageToUse);
                //If the name of this changes, I'm screwed.
                document.title = $("#ctl00_cplUnderlayContainerChild_hiddenTitle").val();
            }, 250);
            DoFont();
            $("#iframesContainer").show();
            //Handle Resize sidebar.
            //apparently "height" needs area to be visible.
            //Around you must be treated differently...
            pnlMapTextSearchContainer = $("#MapTextSearchContainer");
            if (CurrentPageToUse == "AroundYou") {
                try {
                    var whole = pnlMapTextSearchContainer.height();
                    var part = 0;
                    getFlashMovie("PinnacleStudentBackground").JSresizeSidebar(whole, part);
                } catch (e) { }
            }
            var pnlHomeInfo = $(".pnlHomeInfo");
            if (pnlHomeInfo.length > 0) {
                var paraDisc = pnlHomeInfo.find(".paraDisc");
                makeScrollBarOnThing(paraDisc, 213,1.0);
            }
            var pnlBlogContainer = $(".pnlBlogContainer"); 
            if (pnlHomeInfo.length > 0) {
                
            }
            var pnlLivingSpacesDetailsjQ = $(".pnlLivingSpacesDetails");
            if (pnlLivingSpacesDetailsjQ.length > 0) {
                try {
                    //unfortunately we cannot just calculate the size
                    //because we don't know the size of the image until after it's loaded.
                    //Fixme (also needs something to be called on failure).
                    var theImgJQ = $("#FPContainer > img");
                    var DoResize = function() {
                        if (theImgJQ.height() > 600) {
                            theImgJQ.height(600) 
                            theImgJQ.css("width", "auto");
                        }
                        var whole = pnlLivingSpacesDetailsjQ.height();
                        var Zpart = pnlLivingSpacesDetailsjQ.find(".section1").height();
                        getFlashMovie("PinnacleStudentBackground").JSresizeSidebar(whole, whole - Zpart);
                    }
                    theImgJQ.bind('load', DoResize);
                    theImgJQ.bind('error', DoResize); // in case picture fails to load, still resize
                    if (theImgJQ.get(0).complete) { DoResize(); }
                    var gvFloorplansContainer = $(".pnlLivingSpaces .gvFloorplansContainer .scrollable");
                    myalert("foo:" + gvFloorplansContainer.height());
                    makeScrollBarOnThing(gvFloorplansContainer, 200);
                    $(".pnlLivingSpacesDetails .lnkApplyNow").click(JSgoRedButton);
                    //set up furniture arranger to be created in colorbox dealio
                    $(".pnlLivingSpacesDetails .lnkFurnitureArranger").click(function(event) {
                        var xhref = $(this).attr("href");
                        $.fn.colorbox({ href: xhref, open: true, iframe: true, innerWidth: 775, innerHeight: 673 });
                        event.preventDefault();
                    });
                    
                } catch (e1) { myalert("INT"); myalert(genExceptionMessage(e1)); }
            }

            //zoom link on Living details colorbox
            $(".pnlLivingSpacesDetails .lnkZoom").colorbox({ "innerHeight": "625px" });
        } catch (e2) { myalert("EX"); myalert(genExceptionMessage(e2)); }
}