

/*
===   TABS   ===
*/
function showTab(id, itemCount) {

    var objTab;
    var objContener;

    objTab = document.getElementById("Tab" + id);
    objContener = document.getElementById("Contener" + id);

    objTab.className = "selList";
    objContener.style.display = "block";

    for (i = 1; i <= itemCount; i++) {
        if (i != id) {
            document.getElementById("Tab" + i).className = "notSelList";
            document.getElementById("Contener" + i).style.display = "none";
        }
    }
}



/*
===   MODAL   ===
*/
function getWindowHeight() {
    var windowHeight;
    if (window.innerHeight && window.scrollMaxY) {
        windowHeight = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) {
        windowHeight = document.body.scrollHeight;
    } else {
        windowHeight = document.body.offsetHeight;
    }
    return windowHeight;
}



function clientHeight() {
    var y = 0;
    if (self.pageYOffset) {
        y = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {

        y = document.documentElement.scrollTop;
    }

    if (y == getWindowHeight())
    { return 0; }
    else
    { return y; }


}

function popUpClose() {

    var objModelWindow = document.getElementById("modal");
    objModelWindow.style.display = "none";
}


function openCloseFaq(id) {
    var objFAQ = document.getElementById("faq" + id);
    var eName = '#q' + id;

    if ($(eName).is(":hidden")) {
        objFAQ.style.backgroundImage = "url(/Images/SiteImages/faqBtnOpen.gif)";
        $(eName).slideDown("slow");
        
    } else {
     $(eName).hide();
    }
    return false;

    
}


function slowMove(id, X, Y) {
    var elementId = '#' + id;
    var position = $(elementId).position();
    var elementOldX = position.left;
    var elementOldY = position.top;
    var newY = position.top + Y + 'px';
    var newX = position.left + X + 'px';
    $(elementId).animate({
        left: newX,
        top: newY
    }, 1500, unlockButton);

}
/*NEW MOVING FUNCTIONS-----------------------------------------------------------------------------------------*/
/* place 1 reserved for bottom characters*/
var totalItemsList = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1);
var itemsLeftList = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1);
var initiationList = new Array(true, true, true, true, true, true, true, true);
var totalItemsLeft;
var totalItems;
function moveBlockDynamic(divId, scrollerId, itemCount, itemWidth, itemsToMove, itemsPerBlock, direction, coordinate) {
    if (initiationList[scrollerId] == true) {
        itemsLeftList[scrollerId] = itemCount - itemsPerBlock;
        totalItemsList[scrollerId] = itemCount;
        initiationList[scrollerId] = false;
    }
    if (itemCount >= itemsPerBlock) {
        if (itemCount > itemsToMove) {
            if (direction == -1) {

                if (itemsLeftList[scrollerId] < itemsToMove) {
                    if (coordinate == "X") {

                        slowMove(divId, itemsLeftList[scrollerId] * itemWidth * direction, 0);
                    }
                    else {
                        slowMove(divId, 0, itemsLeftList[scrollerId] * itemWidth * direction);
                    }
                    itemsLeftList[scrollerId] = 0;

                }
                else {
                    if (coordinate == "X") {

                        slowMove(divId, itemsToMove * itemWidth * direction, 0);
                    }
                    else {
                        slowMove(divId, 0, itemsToMove * itemWidth * direction);
                    }
                    itemsLeftList[scrollerId] = itemsLeftList[scrollerId] - itemsToMove;

                }

            }
            else {

                if (totalItemsList[scrollerId] > itemsLeftList[scrollerId] + itemsPerBlock) {
                    if (itemsLeftList[scrollerId] + itemsToMove + itemsPerBlock < totalItemsList[scrollerId]) {
                        if (coordinate == "X") {

                            slowMove(divId, itemsToMove * itemWidth * direction, 0);
                        }
                        else {
                            slowMove(divId, 0, itemsToMove * itemWidth * direction);
                        }

                        itemsLeftList[scrollerId] = itemsLeftList[scrollerId] + itemsToMove;
                    }
                    else {
                        if (coordinate == "X") {

                            slowMove(divId, (totalItemsList[scrollerId] - itemsLeftList[scrollerId] - itemsPerBlock) * itemWidth * direction, 0);
                        }
                        else {
                            slowMove(divId, 0, (totalItemsList[scrollerId] - itemsLeftList[scrollerId] - itemsPerBlock) * itemWidth * direction);
                        }
                        itemsLeftList[scrollerId] = itemCount - itemsPerBlock;
                    }
                }
            }

        }
    }
    lockButton(scrollerId);
}
function unlockButton() {
    /*   $("#next" + tempScrollerId).css({ 'opacity': 1.0 }).attr('disabled', false);
    $("#back" + tempScrollerId).css({ 'opacity': 1.0 }).attr('disabled', false);*/

    document.getElementById("next" + tempScrollerId).style.display = 'block';
    document.getElementById('tempnext' + tempScrollerId).style.display = 'none';
    document.getElementById("back" + tempScrollerId).style.display = 'block';
    document.getElementById('tempback' + tempScrollerId).style.display = 'none';
}
var tempScrollerId;
function lockButton(scrollerId) {
    tempScrollerId = scrollerId;
    /*   $("#next" + scrollerId).css({ 'opacity': 0.5 }).attr('disabled', true);
    //    $("#back" + scrollerId).css({ 'opacity': 0.5 }).attr('disabled', true);*/
    document.getElementById("next" + scrollerId).style.display = 'none';
    document.getElementById('tempnext' + scrollerId).style.display = 'block';
    document.getElementById("back" + scrollerId).style.display = 'none';
    document.getElementById('tempback' + scrollerId).style.display = 'block';

}

/*-------------------------------------------------------------------------------------------------------------*/
var opnewwinLinkConfig = new Array;
opnewwinLinkConfig["playBtn"] = new Array("playBtn", "width=350,height=90,top=1,left=1,scrollbars=no,resizable=no,status=no,toolbar=no,location=no,menubar=no");
window.onload = initPage;
function initPage() { initopnewwinLinks(); }

function initopnewwinLinks() {
    if (!document.getElementsByTagName) return true;
    var pageLinks = document.getElementsByTagName("a");
    for (var i = 0; i < pageLinks.length; i++) {
        if (((pageLinks[i].className != null) &&
         (pageLinks[i].className != "")) ||
        ((pageLinks[i].parentNode.className != null) &&
         (pageLinks[i].parentNode.className != ""))) {
            var linkClass = " " + pageLinks[i].className + " ";
            if ((linkClass == "  ") && (pageLinks[i].parentNode.className != "")) {
                linkClass = " " + pageLinks[i].parentNode.className + " ";
            }
            for (var theKey in opnewwinLinkConfig) {
                if (linkClass.indexOf(" " + theKey + " ") > -1) {
                    if ((pageLinks[i].target == "") || (pageLinks[i].target == null)) {
                        pageLinks[i].target = (opnewwinLinkConfig[theKey][0] != "") ? opnewwinLinkConfig[theKey][0] : theKey;
                    }
                    pageLinks[i].settings = opnewwinLinkConfig[theKey][1];
                    pageLinks[i].onclick = opnewwin;
                }
            }
        }
    }
    return true;
}

function opnewwin() {
    newWin = window.open(this.href, this.target, this.settings);
    newWin.focus();
    return false;
}

/*Birthday Series*/
var oldSelections = new Array();
var selectionComplete = 1;
var globalCounter = 0;
/*oldSelections[0] = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);*/
oldSelections[1] = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

function SelectItem(id, groupId) {
    var flag = 0; /*flag if there was selection for an option*/
    for (var i = 0; i < globalCounter; i++) {
        if (oldSelections[0][i] == groupId && oldSelections[1][i] > 0) {
            flag = 1;
        }
    }
    if (flag > 0) {
        for (var k = 0; k < globalCounter; k++) {
            if (oldSelections[0][k] == groupId) {
                document.getElementById("opt" + oldSelections[1][k] + "_" + groupId).className = "";
                document.getElementById("opt" + id + "_" + groupId).className = "selectedOption";
                oldSelections[1][k] = id;
                UpdateOptions();
            }
        }
    }
    else {
        for (var j = 0; j < globalCounter; j++) {
            if (oldSelections[0][j] == groupId) {
                oldSelections[1][j] = id;
                document.getElementById("opt" + id + "_" + groupId).className = "selectedOption";
                UpdateOptions();
                return;
            }
        }
    }
}

function UpdateOptions() {
    selectionComplete = 1;
    var optionsToServer = "";
    for (var i = 0; i < globalCounter; i++) {
        if (oldSelections[0][i] != 0) {
            optionsToServer += oldSelections[0][i] + "," + oldSelections[1][i] + ";";
            document.getElementById("bOptions").value = optionsToServer;
        }
        if (oldSelections[1][i] == 0) {
            selectionComplete = 0;
        }
    }
    if (selectionComplete != 0) {
        document.getElementById("inpCheck").style.display = "none";
        $("#_ctl0_mainContentHolder__ctl0_wizSteppes_btnContinue").removeClass("wizContinueDesabled");
        $("#_ctl0_mainContentHolder__ctl0_wizSteppes_btnContinue").addClass("wizContinue");
    }
}

function UpdateSelection(group, count) {
    globalCounter = count;
    oldSelections[0] = group;
}

function checking() {
    for (var i = 0; i < globalCounter; i++) {
        if (oldSelections[1][i] == 0) {
            selectionComplete = 0;
            alert("Please select an option for all four items!");
            return;
        }
    }
}


var newwindow;
function PopUpForIE(ElementId, CategoryId, url) {
    newwindow = window.open(url + '?iid=' + ElementId + "&cid=" + CategoryId, 'Gallery', 'height=600,width=490');
    if (window.focus) { newwindow.focus() }


}
function PopUpImagesForIE(ElementId, ProgramId, url) {
    newwindow = window.open(url + '?iid=' + ElementId + "&pid=" + ProgramId, 'Image', 'height=600,width=490');
    if (window.focus) { newwindow.focus() }


}


//Main function , assigns behaiviors to different elements , when document is ready 
$(document).ready(function() {
    
    $('.topMenuBlock').mouseenter(function() {
        var count =($(this).children('ul').children('li').size() * 28 + 25) + "px";
        $(this).animate({ top: count }, { queue: false, duration: 1000 });
        $(this).children('ul').show();

    }).mouseleave(function() {
        $(this).animate({ top: "0px" }, { queue: false, duration: 1000 });
        $(this).children('ul').hide();
    });
    //bottom menu
    $('.bottomPopup').mouseenter(function() {
        var multiplier = 35;
        if (jQuery.browser.msie) { multiplier = 20; }
        var count = $('#aboutInfo' + $(this).attr("id")).children('ul').children('li').size() * 18 * (-1) - multiplier + "px";
        var id = '#aboutInfo' + $(this).attr("id");
        $(id).css("margin-top", count);
        $(id).show();

    }).mouseleave(function() {
        var id = '#aboutInfo' + $(this).attr("id");
        $(id).hide();
    });
    
    //select all the a tag with name equal to modal
    $('a[name="modal"]').click(function(e) {
        if (jQuery.browser.msie) {
            if (parseInt(jQuery.browser.version) == 6) {
                if ($(this).attr('href') == "#subscribeModal" || $(this).attr('href') == "#sendToFriendModal") {
                }
                else
                    return false;
            }
        }
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = $(this).attr('href');

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect		
        $('#mask').fadeIn(500);
        $('#mask').fadeTo("fast", 0.2);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', (clientHeight() + 20));
        $(id).css('left', winW / 2 - $(id).width() / 2);

        //transition effect       
        $(id).fadeIn(500);

    });

    //if close button is clicked
    $('.popup .close').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .popup').hide();
    });

    //if mask is clicked
    $('#mask').click(function() {
        $(this).hide();
        $('.popup').hide();
    });

    $('#playLearnMenu ul li').animate({ opacity: 0.8 }, 100);

    $('#playLearnMenu ul li').mouseover(function() {
        $(this).animate({ opacity: 1.0 }, 100);
    });

    $('#playLearnMenu ul li').mouseleave(function() {
        $(this).animate({ opacity: 0.8 }, 100);
    });

});

//Scroll pane initialization
$(function() {
    $('#learningLinks').jScrollPane({ scrollbarWidth: 31, showArrows: true, scrollbarOnLeft: true });
});


//Learning Center
var infoFlag = 0;
function ShowInfo() {
    if (infoFlag == 0) {
        $('#infoDiv').show();
        $(function() {
            $('#infoHolder').jScrollPane({ scrollbarWidth: 31, dragMaxHeight: 98, showArrows: true, scrollbarOnLeft: true });
        });
        $('#learningActivities').hide();
        $('#frame').hide();
        infoFlag = 1;
        activityFlag = 0;
    }
    else {
        $('#infoDiv').hide();
        $('#frame').show();
        infoFlag = 0;
    }
}
var activityFlag = 0;
function ShowActivities() {
    if (activityFlag == 0) {
        $('#learningActivities').show();
        //Scroll pane initialization
        $(function() {
            $('#activitiesHolder').jScrollPane({ scrollbarWidth: 31, dragMaxHeight: 98, showArrows: true, scrollbarOnLeft: true });
        });
        $('#infoDiv').hide();
        $('#frame').hide();
        activityFlag = 1;
        infoFlag = 0;
    }
    else {
        $('#learningActivities').hide();
        $('#frame').show();
        activityFlag = 0;
    }
}

