﻿function InitializeCufon() {
    Cufon.replace('h1', { fontFamily: 'Glypha LT Std', hover: true });
    Cufon.replace('h2', { fontFamily: 'Glypha LT Std', hover: true });
    Cufon.replace('h3', { fontFamily: 'Glypha LT Std', hover: true });
    Cufon.replace('h4', { fontFamily: 'Glypha LT Std', hover: true });
    Cufon.replace('h5', { fontFamily: 'Glypha LT Std', hover: true });
    Cufon.replace('h6', { fontFamily: 'Glypha LT Std', hover: true });

    // Place all html specific tags above
    Cufon.replace('.glypha', { fontFamily: 'Glypha LT Std', hover: true });
    Cufon.replace('.annifont', { fontFamily: 'Annifont', hover: true });

    Cufon.now();
}

function NavigateToLocation(obj) {
    if ($(obj).attr('value') != "")
        document.location.href = $(obj).attr('value');
}

function NavigateToBlog(obj) {
    if ($(obj).attr('value') != "")
        document.location.href = "/blogdetails?id=" + $(obj).attr('value');
}

function SelectTab(tabId) {
    $("ul.tabs li").removeClass("active"); //Remove any "active" class
    $("ul.tabs li a").removeClass("active"); //Remove any "active" class
    
    $(".tab_content").hide(); //Hide all tab content

    var activeTab = $("ul.tabs li:eq(" + parseInt(tabId) + ")");
    activeTab.addClass("active").show(); //Activate the tab
    activeTab.find("a").addClass("active")

    var activeTabContent = $(".tab_content:eq(" + parseInt(tabId) + ")");
    activeTabContent.show(); //Show active tab content

    InitializeCufon();
}

function ClickSelectedTab(tabId) {
    $('#tab-' + tabId).parent().trigger('click');
}

function ClearDetailTab(tabId) {
    var tab = $('#tab-' + tabId);

    tab.attr('onclick', '');
    tab.trigger('click');
}

function ViewLocationMap() {
    var container = $("#mapContainer");

    if (container.attr('class') == 'mapContainer') {
        container.attr('class', 'mapContainerActive')
    } else {
        container.attr('class', 'mapContainer')
    }
    return false;
}

function ShowDialog(obj) {
    var dialog = $("#dialog");
    var html = $(obj);
    
    var title = '';
    if (html.attr('title') != "") {
        title = html.attr('title');
    }

    if (html.attr('value') != "") {
        dialog.html(html.attr('value'));
        dialog.dialog({ title: title, modal: true, closeOnEscape: true});
    }
}

function ShowSchoolEventDialog(obj) {
    var dialog = $("#dialog");
    var html = obj.options[obj.selectedIndex];

    var title = "Career Fair at " + html.text;
    var value = html.value;

    $.ajax({
        type: "POST",
        url: "/Services/SchoolEventHandler.ashx",
        data: { id: value },
        success: function (msg) {
            dialog.html(msg);
            dialog.dialog({ title: title, modal: true, closeOnEscape: true });
        },
        error: function (msg) {
            dialog.html(msg);
            dialog.dialog({ title: title, modal: true, closeOnEscape: true });
        }
    });    
}

function ShowJobDialog(obj) {
    var dialog = $("#dialog");
    var parent = $(obj);
    var html = $("#" + parent.attr("value"));

    var title = '';
    if (html.attr('title') != "") {
        title = html.attr('title');
    }
   
    dialog.html(html.html());
    dialog.dialog({ title: title, modal: true, closeOnEscape: true, height: 400, width: 400 });
}

function ToggleRehmannValue(obj) {    
    var parent = $(obj).parent().parent();
    var child = parent.children('#rehmannValueDescription');

    if (child.hasClass('rehmannValueActive')) {
        child.removeClass('rehmannValueActive');
        child.addClass('rehmannValueInactive');
    }
    else {
        child.removeClass('rehmannValueInactive');
        child.addClass('rehmannValueActive');
    }

    $('.scroll-pane').jScrollPane({ topCapHeight: 10, bottomCapHeight: 10 });
}

function ToggleArchiveAccordion(obj) {
    var archiveHeader = $(obj);
    var archiveHeaderIcon = $("#" + archiveHeader.attr('iconid'));
    var archiveItems = $("#" + archiveHeader.attr('childid'));
    
    if (archiveHeader.attr('class') != 'archiveHeaderActive') {
        archiveHeaderIcon.attr('class', 'archiveIcon rehmann-ui-icon rehmann-ui-icon-minus')
        archiveHeader.attr('class', 'archiveHeaderActive');
        archiveItems.attr('class', 'archiveItemsActive');
    }
    else {
        archiveHeaderIcon.attr('class', 'archiveIcon rehmann-ui-icon rehmann-ui-icon-plus')
        archiveHeader.attr('class', 'archiveHeader');
        archiveItems.attr('class', 'archiveItems');
    }
}

function ToggleBiographyAccordion(obj) {
    var biographyAccordionHeader = $(obj);
    var biographyAccordionItems = $("#" + biographyAccordionHeader.attr('childid'));

    var class1 = biographyAccordionHeader.attr('class');
    
    // Get all elements that has a class attribute that ends with the expression
    $("[class$=AccordionHeaderActive]").each(function () {
        var item = $(this); // Get the item
        var itemClass = item.attr('class'); // Get the item class

        itemClass = itemClass.replace('Active', ''); // Replace Active
        item.attr('class', itemClass); // update items class

        var items = $('#' + item.attr('childid'));
        items.attr('class', 'biographyAccordionItems');
    });
        
    biographyAccordionHeader.attr('class', class1);

    if (biographyAccordionHeader.attr('class').lastIndexOf('Active') == -1) {
        biographyAccordionHeader.attr('class', biographyAccordionHeader.attr('class') + 'Active');
        biographyAccordionItems.attr('class', 'biographyAccordionItemsActive');
    }
    else {
        biographyAccordionHeader.attr('class', biographyAccordionHeader.attr('class').replace('Active', ''));
        biographyAccordionItems.attr('class', 'biographyAccordionItems');
    }

    $('.scroll-pane').jScrollPane();
}

function HandleSliderChange(e, ui) {
    var maxScroll = $("#content-scroll").attr("scrollHeight") -
                  $("#content-scroll").height();
    $("#content-scroll").animate({ scrollTop: ui.value *
     (maxScroll / 100)
    }, 1000);
}

function HandleSliderSlide(e, ui) {
    var maxScroll = $("#content-scroll").attr("scrollHeight") -
                  $("#content-scroll").height();
    $("#content-scroll").attr({ scrollTop: ui.value * (maxScroll / 100) });
}

function ShowAccoutingToday() {
    $('#accountingtoday').css('display', '');    
    $('#videotoday').css('display', 'none');
}

function ShowCollegeGrads() {
    $('#accountingtoday').css('display', 'none');
    $('#videotoday').css('display', '');
}

function ToggleTestimony(obj) {
    return;

    var parent = $(obj);
    var testimony = $('#' + parent.attr('testimonyid'));
    var containers = $('[id=' + parent.attr('containerid') + ']');

    if (testimony.attr('class') == 'testimony') {
        testimony.attr('class', 'testimonyActive');
        containers.css('display', 'none');
        Cufon.replace('span.testimonyActive');
    }
    else {
        testimony.attr('class', 'testimony');
        containers.css('display', '');
    }
}

function SearchRehmann(searchType, searchInputId) {
    var searchText = $("#" + searchInputId).attr('value');

    document.location.href ="/searchresults?t=" + searchType + "&k=" + searchText;
}

function SearchRehmannKeyPressed(obj, event) {
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = event.which;     //firefox
    
    if (key == 13) {

        var searchObj = $(obj);
        document.location.href = "/searchresults?t=" + searchObj.attr('searchType') + "&k=" + searchObj.attr('value');
    }
}


function resetArea() {
    //show image for area1
    mainImage = document.getElementById('mainImage');
    mainImage.src = '../Images/hover/none.gif';
}
function showArea1() {
    //show image for area1
    mainImage = document.getElementById('mainImage');
    mainImage.src = '../Images/hover/ci_sel.gif';
}

function showArea2() {
    //show image for area1
    mainImage = document.getElementById('mainImage');
    mainImage.src = '../Images/hover/wa_sel.gif';
}

function showArea3() {
    //show image for area1
    mainImage = document.getElementById('mainImage');
    mainImage.src = '../Images/hover/cpa_sel.gif';
}

function showArea4() {
    //show image for area1
    mainImage = document.getElementById('mainImage');
    mainImage.src = '../Images/hover/mi.gif';
}

function showArea5() {
    //show image for area1
    mainImage = document.getElementById('mainImage');
    mainImage.src = '../Images/hover/ms.gif';
}


function showArea6() {
    //show image for area1
    mainImage = document.getElementById('mainImage');
    mainImage.src = '../Images/hover/me.gif';
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function PlayPauseVideo(id, width, height, clicked) {
    var imgObj = $("#img" + id);

    if (imgObj.css('display') != 'none' && imgObj.attr('playerMode') == '' && clicked) {
        imgObj.attr('src', '/Images/Rehmann_Pause_' + width + 'x' + height + '.png'); // Change image to pause        
        imgObj.attr('playerMode', 'playing'); // Set player mode
        $f("player" + id).play(); // Play the video
    }
    else if (imgObj.attr('playerMode') == 'playing') {
        imgObj.attr('src', '/Images/Rehmann_Play_' + width + 'x' + height + '.png'); // Change image to pause        
        imgObj.attr('playerMode', 'paused'); // Set player mode 
        $f("player" + id).pause(); // Pause the video
    }
    else if (imgObj.attr('playerMode') == 'paused') {
        imgObj.attr('src', '/Images/Rehmann_Pause_' + width + 'x' + height + '.png'); // Change image to pause        
        imgObj.attr('playerMode', 'playing'); // Set player mode        
        $f("player" + id).resume(); // Resume the video
    }
}

function ShowPlayButton(id, width, height) {
    var imgObj = $("#img" + id);

    imgObj.attr('playerMode', ''); // Set player mode        
    imgObj.attr('src', '/Images/Rehmann_Play_' + width + 'x' + height + '.png'); // Change image to play        
}

$(function () {
    // Causing a browser error that breaks the mega navigation menu
    //$("img.VideoCardImage").imageView({width: 103, height: 103 }); 
});

function getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}
