﻿var iderere;
var searchstringer;
var iNumResults = 25;
function errorMsg(msg) {
    alert("Error: " + msg);
    hideLoader();
}
function showHome() {
    show("newsContainer");
    hide("divStory");
    hide("divResults");
    hide("divEvent");
    hide("divGallery")
}
function showStory() {
    hide("newsContainer");
    show("divStory");
    hide("divResults");
    hide("divEvent");
    hide("divGallery")
}
function showResults() {
    hide("newsContainer");
    hide("divStory");
    show("divResults");
    hide("divEvent");
    hide("divGallery")
}
function showEvents() {
    hide("newsContainer");
    hide("divStory");
    hide("divResults");
    show("divEvent");
    show("divEventCalendar");
    hide("divGallery")
}
function showGallery() {
    hide("newsContainer");
    hide("divStory");
    hide("divResults");
    hide("divEvent");
    hide("divEventCalendar");
    show("divGallery")
}
function showInStory(result) {
    showStory();
    hideLoader()
    $("#divStory").html(result).slideDown();
}
function showInStorySearch(result) {
    showStory();
    hideLoader()
    $("#divStory").html(result).slideDown();
    service.searchStory(iderere, searchstringer, showInStoryText, errorMsg);
}
function showInStoryText(result) {
    $("#divStoryText").html(result);
}
function showInResults(result) {
    showResults();
    hideLoader()
    $("#divResults").html(result).slideDown();
}
function showInEventStory(result) {
    hideLoader()
    $("#divEventStory").html(result).slideDown();
}
function showInEventCalender(result) {
    $("#divEventCalendar").html(result).slideDown();
}
function showinProfiles(result) {
    hideLoader()
    $("#divtabProfiles").html(result).slideDown();
}
function showInGlossary(result) {
    hideLoader()
    $("#divGlossary").html(result).slideDown();
    $("#divGlossary").parent().animate({ borderWidth: "2px" }, 400).animate({ borderWidth: "1px" }, 400).animate({ borderWidth: "2px" }, 400).animate({ borderWidth: "1px" }, 400).animate({ borderWidth: "2px" }, 400).animate({ borderWidth: "1px" }, 400);
}
function showInGallery(result) {
    hideLoader();
    showGallery();
    $("#divGallery").html(result).slideDown();
}
function showInDivSearchResults(result) {
    hideLoader()
    $("#divSearchResults").html(result).slideDown();
}
function loadStory(ider, backLink, search) {
    loader("divStory");
    scroll(0, 0);
    markSLStory(ider);
    iderere = ider;
    searchstringer = search;
    service.webDisplayStory(ider, backLink, search, showInStorySearch, errorMsg);
}
function loadEmail(IDEmail) {
    loader("divResults");
    scroll(0, 0);
    service.webDisplayEmail(IDEmail, showInResults, errorMsg);
}
function markSLStory(idStory) {
    $(".storyList").removeClass("slSelected");
    $("#dSL" + idStory).addClass("slSelected");
}
function loadWIR(sDate) {
    loader("divResults");
    scroll(0, 0);
    service.webDisplayWeekInReview(sDate, showInResults, errorMsg);
}
function loadCalender(ider) {
    showEvents();
    scroll(0, 0);
    if (document.getElementById("divEventCalendar").innerHTML.length <= 50) {
        service.webDisplayCalender(showInEventCalender, errorMsg);
    }
    loadCalStory(ider);
}
function doSearch(term, idCat, iSkip, iTake) {
    loader("divSearchResults");
    iNumResults = iTake;
    service.DisplaySearch("" + term + "", "" + idCat + "", iSkip, iTake, showInDivSearchResults, errorMsg);
}
function loadSearch(boxID, idCat, iSkip, iTake) {
    doSearch(document.getElementById("" + boxID + "").value, "" + idCat + "", iSkip, iNumResults);
}
function loadGlossaryAll() {
    loader("divResults");
    service.DisplayGlossaryAll(showInResults, errorMsg);
}
function loadCalStory(ider) {
    loader("divEventStory");
    markSLStory(ider);
    service.webDisplayCalStory(ider, showInEventStory, errorMsg);
}
function loadHeadlines(num, cat, type) {
    loader("divResults");
    service.webDisplayHeadline(num, cat, type, showInResults, errorMsg);
}
function loadPage(id) {
    loader("divResults");
    service.webDisplayPage(id, showInResults, errorMsg);
}
function loadProfiles(id) {
    loader("divtabProfiles");
    service.webDisplayProfiles(id, showinProfiles, errorMsg);
}
function loadPublication(mediacode) {
    loader("divResults");
    service.webDisplayPublication(mediacode, showInResults, errorMsg);
}
function removeHighlighting() {
    sp = document.getElementsByTagName("span")
    for (i = 0; i < sp.length; i++) {
        sp[i].style.backgroundColor = "white";
    }
    document.getElementById("divHL").style.display = "none";
}
function loadGallery(idgallery, indexgallery) {
    loader("divStory");
    service.webDisplayGallery(idgallery, indexgallery, showInStory, errorMsg);
}
function loadGalleryImage(idimage, idgallery, order) {
    loader("divGallery");
    service.DisplayGalleryImage(idimage, idgallery, order, showInGallery, errorMsg);
}
function loadGlossary(id, term, letter) {
    loader("divGlossary");
    if (term == "yes") {
        service.webDisplayGlossary(id, document.getElementById("txtglossaryText").value, letter, showInGlossary, errorMsg);
    }
    else {
        service.webDisplayGlossary(id, '', letter, showInGlossary, errorMsg);
    }
}
var adPos = 0;
function displayAd(delay) {
    document.getElementById("divAdMatrix").style.display = "none";
    document.getElementById("divAdLarge").style.display = "block";
    var divs = document.getElementById("divAdLarge").getElementsByTagName("div");
    if (adPos == divs.length)
        adPos = 0
    for (var i = 0; i < divs.length; i++) {
        var div = divs[i];
        if (div.id != "") {
            if (i != adPos) {
                div.style.display = "none";
            }
            else {
                div.style.display = "block";
            }
        }
    }
    adPos++;
    if (delay == 0) {
        clearTimeout(timer)
    }
    else {
        timer = setTimeout("displayMatrix(5000)", delay);
    }
}
function displayMatrix(delay) {
    document.getElementById("divAdLarge").style.display = "none";
    document.getElementById("divAdMatrix").style.display = "block";
    if (delay == 0) {
        clearTimeout(timer)
        document.getElementById("spnStart").style.display = "block"
        document.getElementById("spnStop").style.display = "none"
    }
    else {
        document.getElementById("spnStart").style.display = "none"
        document.getElementById("spnStop").style.display = "block"
        timer = setTimeout("displayAd(10000)", delay);
    }
}
function loader(id) {
    $("#divLoader").css("visibility", "visible");
}
function hideLoader() {
    $("#divLoader").css("visibility", "hidden");
}
function loadFeaturedSlider(lnkElement, IDContainer) {
    $(lnkElement).parent().find("a").removeClass("selectedSlider");
    $(lnkElement).addClass("selectedSlider");
    $(".container").slideUp();
    $("#featStories" + IDContainer).slideDown();
}
$(document).ready(function() {
    var lnker = $(".featuredStorySelector").find("a:first");
    $(".container .TabMenu").each(function() {
        $(this).find(".sliderLink:first").addClass("selector");
    })
    $(".accSlider .Header").click(function() {
        $(this).blur();
        $("#" + this.parentNode.id + " .Body:not(#sliCon" + this.id + ")").slideUp();
        $("#sliCon" + this.id).slideToggle();
        return false;
    });
    $(".Tabs ul li a").live("click", function() {
        $(this).blur();
        $(this).parent().parent().find("li").removeClass("selected");
        $(this).parent().addClass("selected");
        $('#' + this.parentNode.parentNode.parentNode.id + ' .divHolder > div:not(#div' + this.id + ')').slideUp();
        $('#' + this.parentNode.parentNode.parentNode.id + ' .divHolder #div' + this.id).slideDown();
        return false;
    });
    $("a").live("click", function() {
        $(this).blur();
    });
    $(".container .TabMenu .sliderLink").click(function() {
        this.blur();
        $(this).parent().find(".selector").removeClass("selector");
        $(this).addClass("selector");
        var TabWidth = $(this).parent().parent().find(".ContentFrame").width();
        var newLeft = -1 * $(this).parent().parent().find(".sliderLink").index(this) * TabWidth;
        $(this).parent().parent().find(".AllTabs").animate({
            left: +newLeft + "px"
        }, 1000);
        return false;
    });
});
function KeyDownHandler(eventer) {
    if (eventer.keyCode == 13) {
        eventer.returnValue = false;
        eventer.cancel = true;
        document.getElementById("cmdSearch").click();
    }
}