﻿var map = null;

$(document).ready(function () {
    // Accordion
    $("#accordionMenu").accordion({ header: "h3", autoHeight: false });
    $('#tabs').tabs();
    CreateMap();
    setTimeout('ExtendedInit()', 100);
});

function ExtendedInit() {
    $('#timeStandards').click(function () { window.open('./docs/2009_12MotivationalTimesAnalysis.pdf'); });
    $('#volunteer, #volunteerreg').click(function () { window.open('https://thriva.activenetwork.com/Reg4/Form.aspx?IDTD=6007596&RF=8909156&mode=0'); });
    $('.loadable').click(function () { LinkClicked($(this)); });
    $('#home').click(function () { ShowHome(); });
    //$('#accountLogin').click(function() { OpenAccountIFrame(); });
    $('#accountLogin').click(function () { window.open('https://thriva.activenetwork.com/MyAccount/Login.aspx?Org=FirestoneAkronSwimTeam'); });

    $('#carousel').infiniteCarousel({ imagePath: './images/' });

    //$('#todaysd').text(new Date().getDate());
    //$('#todaysm').text(GetMonth(new Date().getMonth()));

    $('#jTweetsAnywhereDiv').jTweetsAnywhere({
        username: 'firestonetweets',
        //searchParams: ['q=firestonetweets%20OR%20fastwebmaster'],
        count: 10,
        showTweetFeed: {
            showTimestamp: {
                refreshInterval: 15
            },
            autorefresh: {
                mode: 'trigger-insert',
                interval: 30
            },
            paging: { mode: 'more' }
        },
        onDataRequestHandler: function (stats, options) {
            if (stats.dataRequestCount < 11) {
                return true;
            }
            else {
                stopAutorefresh(options);
                //alert("To avoid struggling with Twitter's rate limit, we stop loading data after 10 API calls.");
            }
        }
    });
    $("ul.videoList").ytplaylist({ addThumbs: true, autoPlay: false, holderId: 'ytvideo', playerHeight: 255, playerWidth: 383 });
    //$("ul.videoList").ytplaylist();
    //$('#popupSample').dialog({ modal: true, width: 500, height: 500, title: "FAST Video Gallery" });

    InitializeCongratsPopup();

    //$(document).snowfall({ shadow: true, round: true, minSize: 3, maxSize: 5, collection: '.shadow', flakeCount: 35 }); // add shadows
}

function CreateMap() {
    map = new Array();
    map['board'] = './snippets/board.html';
    map['coaches'] = './snippets/coaches.html';
    map['philosophy'] = './snippets/philosophy.html';
    map['links'] = './snippets/links.html';
    map['glossary'] = './snippets/glossary.html';
    map['meetguidelines'] = './snippets/meetguidelines.html';
    map['taper'] = './snippets/taper.html';
    map['shortvslong'] = './snippets/shortvslong.html';
    map['dq'] = './snippets/dq.html';
    map['eventstoswim'] = './snippets/eventstoswim.html';
    map['officialsduties'] = './snippets/officialsduties.html';
    map['meetvolunteers'] = './snippets/meetvolunteers.html';
    map['helpteam'] = './snippets/helpteam.html';
    map['yearround'] = './snippets/yearround.html';
    map['successathletics'] = './snippets/successathletics.html';
    map['competitionchildren'] = './snippets/competitionchildren.html';
    map['kidssport'] = './snippets/kidssport.html';
    map['swimtired'] = './snippets/swimtired.html';
    map['nutrition'] = './snippets/nutrition.html';
    map['uniform'] = './snippets/uniform.html';
    map['commandments'] = './snippets/commandments.html';
    map['preparation'] = './snippets/preparation.html';
    map['attend'] = './snippets/attend.html';
    map['meettypes'] = './snippets/meettypes.html';
    map['champsmeet'] = './snippets/champsmeet.html';
    map['prelims'] = './snippets/prelims.html';
    map['practicepolicies'] = './snippets/practicepolicies.html';
    map['schedule'] = './snippets/schedule.html';
    map['problems'] = './snippets/problems.html';
    map['fees'] = './snippets/fees.html';
    map['gallery'] = './snippets/gallery.html';
    map['shortcourse'] = './snippets/shortcourse.html';
    map['shortcourseoct'] = './snippets/shortcourseoct.html';
    map['shortcoursenov'] = './snippets/shortcoursenov.html';
    map['shortcoursedec'] = './snippets/shortcoursedec.html';
    map['shortcoursejan'] = './snippets/shortcoursejan.html';
    map['shortcoursefeb'] = './snippets/shortcoursefeb.html';
    map['shortcoursemar'] = './snippets/shortcoursemar.html';
}

function GetMonth(mo) {
    switch (mo) {
        case 0: return "Jan"; break;
        case 1: return "Feb"; break;
        case 2: return "Mar"; break;
        case 3: return "Apr"; break;
        case 4: return "May"; break;
        case 5: return "Jun"; break;
        case 6: return "Jul"; break;
        case 7: return "Aug"; break;
        case 8: return "Sep"; break;
        case 9: return "Oct"; break;
        case 10: return "Nov"; break;
        case 11: return "Dec"; break;
    }
}

function OpenAccountIFrame() {
    var othersContent = $('#othersContent');

    othersContent.find('.subContainers').hide();
    $('#homeContent').hide();

    if (othersContent.find('#accountIFrame').length == 0) {
        othersContent.append("<iframe id='accountIFrame' src='https://thriva.activenetwork.com/MyAccount/Login.aspx?Org=FirestoneAkronSwimTeam'></iframe>");
    }
    else
        othersContent.find('#accountIFrame').show();
}

function ShowHome() {
    var othersContent = $('#othersContent');

    othersContent.find('#accountIFrame').hide();
    othersContent.find('.subContainers').hide();
    $('#homeContent').show();
}

var myScroll;
function InitializeCongratsPopup() {
//    var thelist = $('#thelist');
//    var indicator = $('#indicator');
//    var congratsGroup = $('.congratsGroup');
//    var counter = 1;

//    congratsGroup.each(function() {
//        thelist.append("<li>" + $(this).html() + "</li>");
//        if (counter == 1)
//            indicator.append("<li class='active'>" + counter + "</li>");
//        else
//            indicator.append("<li>" + counter + "</li>");
//        counter++;
//    });

    myScroll = new iScroll('wrapper', {
        snap: true,
        momentum: false,
        hScrollbar: false,
        onScrollEnd: function() {
            try {
                document.querySelector('#indicator > li.active').className = '';
                document.querySelector('#indicator > li:nth-child(' + (this.currPageX + 1) + ')').className = 'active';
            } catch (e) { }
        }
    });
    //$('#congratsPopup').hide();
}

function ExpandCongrats() {
    var congratsPopup = $('#congratsPopup');
    congratsPopup.dialog({
        autoOpen: false,
        title: "Congrats!",
        closeOnEscape: true,
        draggable: true,
        resizable: false,
        width: 800,
        height: 400,
        modal: true
    });

    //congratsPopup.html($('#congratsContent').html());
    //congratsPopup.find('#congratsContentScroll').css("height", "325px");
    congratsPopup.dialog('open').show('slide');
}

function LinkClicked(jqLink) {
    var lnkID = jqLink.attr('id');

    if (lnkID != null && $.trim(lnkID) != '') {
        var containerID = $.trim(lnkID) + "div";
        var othersContent = $('#othersContent');

        $('#homeContent').hide();
        othersContent.find('#accountIFrame').hide();
        othersContent.find('.subContainers').hide();
        if (othersContent.find('#' + containerID).length == 0) {
            othersContent.append("<div class='subContainers' id='" + containerID + "'></div>");
            $('#' + containerID).load(map[lnkID]);
        }
        else {
            othersContent.find('#' + containerID).show();
        }
    }
}

