
/*===   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;

    
}



/*-------------------------------------------------------------------------------------------------------------*/
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() {


    $('input.sliderNext,input.sliderBack').focus(function() {
        $(this).blur();
    });

    //top menu
    $('.topMenuBlock').mouseenter(function() {
        var count = $(this).children('ul').children('li').size() * 28 + 10 + "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();
    });

    $('.lng').mouseenter(function() {
        $('#languages').show();

    });
    $('#languages').mouseleave(function() {
        $('#languages').hide();
    });

    $('#logoImage').mouseenter(function() {
        $('#logoImage > p').show();

    });
    $('#logoImage').mouseleave(function() {
        $('#logoImage > p').hide();
    });
    $('div[title="birthdayTab"]').css({ 'display': 'none' });
    $('#Contener1').css({ 'display': 'block' });

    $('input.sliderBack').click(function(e) {
        var buttonClickedId = '#' + $(this).attr('id');
        var blockToMove = '#' + $(this).attr('name');
        var dir = $(blockToMove).css('direction');
        var currentOffset;
        var itemCount = $(blockToMove + '> ul > li').size();
        var timesToMove = itemCount / 5;
        var parentId = '#' + $(blockToMove).offsetParent().attr('id');
        var parentWidth = $(parentId).width();
        var desiredOffset;
        if (!jQuery.browser.msie) {
            $(this).animate({ opacity: .5 }, { queue: false, duration: 745, complete: function() { $(this).animate({ opacity: 1 }, { queue: false, duration: 745 }); } });
        }
        if (dir == 'ltr') {
            currentOffset = $(blockToMove).css('left');
            if (currentOffset != '0px' && (parseInt(currentOffset.replace('px', '')) + parentWidth < 0)) {
                $(this).attr('disabled', true);
                $(this).css('background-image', buttonImageToPut);
                desiredOffset = parseInt(currentOffset.replace('px', '')) + parentWidth + 'px';
                $(blockToMove).animate({ left: desiredOffset }, { queue: false, duration: 1500, complete: function() { $(buttonClickedId).removeAttr('disabled'); } });
            }
            else {
                $(this).attr('disabled', true);
                $(blockToMove).animate({ left: '0px' }, { queue: false, duration: 1500, complete: function() { $(buttonClickedId).removeAttr('disabled'); } });
            }
        }
        else {
            currentOffset = $(blockToMove).css('right');
            if ((currentOffset != '0px' && (parseInt(currentOffset.replace('px', '')) + parentWidth < 0))) {
                $(this).attr('disabled', true);
                desiredOffset = parseInt(currentOffset.replace('px', '')) + parentWidth + 'px';
                $(blockToMove).animate({ right: desiredOffset }, { queue: false, duration: 1500, complete: function() { $(buttonClickedId).removeAttr('disabled'); } });
            }
            else {
                $(blockToMove).animate({ right: '0px' }, { queue: false, duration: 1500, complete: function() { $(buttonClickedId).removeAttr('disabled'); } });
            }
        }

    });

    $('input.sliderNext').click(function(e) {
        var buttonClickedId = '#' + $(this).attr('id');
        var blockToMove = '#' + $(this).attr('name');
        var dir = $(blockToMove).css('direction');
        var currentOffset;

        if (!jQuery.browser.msie) {
            $(this).animate({ opacity: .5 }, { queue: false, duration: 745, complete: function() { $(this).animate({ opacity: 1 }, { queue: false, duration: 745 }); } });
        }
        var itemCount = $(blockToMove + '> ul > li').size();

        var timesToMove = itemCount / 5;
        var parentId = '#' + $(blockToMove).offsetParent().attr('id');
        var parentWidth = $(parentId).width();
        var desiredOffset;
        var offsetToMove;

        var itemLenght = $(blockToMove + '> ul > li').width() + parseInt($(blockToMove + '> ul > li').css('margin-left').replace("px", '')) + parseInt($(blockToMove + '> ul > li').css('margin-right').replace("px", '')) + parseInt($(blockToMove + '> ul > li').css('padding-right').replace("px", '')) + parseInt($(blockToMove + '> ul > li').css('padding-left').replace("px", '')) + parseInt($(blockToMove + '> ul > li').css('border-right-width').replace("px", '')) + parseInt($(blockToMove + '> ul > li').css('border-left-width').replace("px", ''));
        var abstractWidth = itemLenght * itemCount;
        var abstractOffset;
        if (dir == 'ltr') {
            currentOffset = $(blockToMove).css('left');
            desiredOffset = parseInt(currentOffset.replace('px', '')) - parentWidth * 2 + 'px';

            if (-parseInt(desiredOffset.replace('px', '')) < abstractWidth) {
                $(this).attr('disabled', true);
                $(blockToMove).animate({ left: desiredOffset }, { queue: false, duration: 1500, complete: function() { $(buttonClickedId).removeAttr('disabled'); } });
            }
            else {
                $(this).attr('disabled', true);
                abstractOffset = (-abstractWidth - parseInt(desiredOffset.replace('px', ''))) + 'px';
                $(blockToMove).animate({ left: abstractOffset }, { queue: false, duration: 1500, complete: function() { $(buttonClickedId).removeAttr('disabled'); } });
            }
        }
        else {

            currentOffset = $(blockToMove).css('right');
            desiredOffset = parseInt(currentOffset.replace('px', '')) - parentWidth * 2 + 'px';
            offsetToMove = parseInt(currentOffset.replace('px', '')) - parentWidth + 'px';

            if (-parseInt(desiredOffset.replace('px', '')) <= abstractWidth) {
                $(this).attr('disabled', true);
                $(this).css('fast', '0.5');
                $(blockToMove).animate({ right: offsetToMove }, { queue: false, duration: 1500, complete: function() { $(buttonClickedId).removeAttr('disabled'); } });
            }
            else {
                $(this).attr('disabled', true);
                abstractOffset = parentWidth + parseInt(offsetToMove.replace('px', '')) - (parseInt(abstractWidth) + parseInt(offsetToMove.replace('px', ''))) + 'px';
                $(blockToMove).animate({ right: abstractOffset }, { queue: false, duration: 1500, complete: function() { $(buttonClickedId).removeAttr('disabled'); } });
            }

        }

    });
    //select all the a tag with name equal to modal
    $('a[name="modal"]').click(function(e) {

        //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();



        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
        //Set the popup window to center
        $(id).css('top', '3%');
        $(id).css('right', winW / 2 - 238 + 'px');
        if (jQuery.browser.msie) {
            if (jQuery.browser.version == '6.0') {
                $(id).css('position', 'absolute');
                $('#galleryPopupBottom').css('margin-top', "180px");
                $('#galleryPopupImg').height(180);
                $('#galleryPopupImgBottom').css('margin-top', '130px');
            }
        }

        $(id).appendTo('body');
        //transition effect
        $(id).fadeIn(500);


        //Set height and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight, 'opacity': .2 });

        //transition effect		
        $('#mask').fadeIn(500);
        $('#mask').fadeTo("fast", 0.2);



    });

    //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();
    });

    if (!jQuery.browser.msie) {
        $('#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);
        });
    }




    $('#aShowList').mouseover(function() {
        $('#photoGalleryCategoriesListBlock').show();
    });

    $('#photoGalleryCategoriesListBlock').mouseleave(function() {
        $(this).hide();
    });


});

//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;
    }
}


