
var autoPlayTimeOutId;
//SlideRight
var currentPhIdx = 1;
var isSetPre = false;
var isSetNext = false;
//region UI common
function ReturnToMainHome() {
    window.external.ReturnToMainHome();
}
function ReturnToMainHomeByBrowsing() {
    StopAutoPlay();
    window.external.StoreBrowseProgress();
    window.external.NaviBack();
}
function BackHomeClick() {
    $(this).removeClass('divBackHomeH').addClass('divBackHomeA');
    window.external.NaviBack();
}
function BackHomeAndRecordProgressClick() {
    $(this).removeClass('divBackHomeH').addClass('divBackHomeA');
    window.external.StoreBrowseProgress();
    window.external.NaviBack();
}
function PlayAudioAnimate() {
    $('.imgAkiconBase').each(function () {
        var audio = $(this);
        audio.toggleClass('imgAkiconC imgAkiconH');
        setTimeout(function () { audio.toggleClass('imgAkiconC imgAkiconH'); }, 100);
    });
}
function FocusElement(id) {
    var ele = document.getElementById(id);
    if (ele) {
        ele.focus();
        ele.select();
    }
}
function fuzzPage() {
    $('body').css("filter", "alpha(opacity=30)");
}
function deFuzzPage() {
    $('body').css("filter", "");
}
//endregion
//region Mode Select page
function StudyModel() {
    if (window.external.ModelSelectedStudy()) {
        $('#divModelSlt').hide();
        $('#divLearn').show();
    }
}
function StartRandomView() {
    if (window.external.ModelSelectedRandomView()) {
        $('#divModelSlt').hide();
        $('#divRandomView').show();
    }
}
//endregion
function Hide1() {
    $('#divMemoryInfo').hide();
}
function Hide2() {
    $('#divEachUnit').hide();
}
function Show2() {
    $('#divEachUnit').show();
}
function Hide3() {
    $('#divStContent4').hide();
}
function Show3() {
    $('#divStContent4').show();
}
function DocReady() {
    $('.divleft').hover(
			function () {
			    $(this).css("background", "url(img/folder_BG.png) no-repeat");
			},
			function () {
			    $(this).css("background-image", "");
			}
		);
    $('.divleft').click(
        function () {
            var flag = window.external.SelectedVocabulary($(this).attr("id"));
            if (flag) {
                $('#divModelSlt').show();
                $('#divHome').hide();
            }
        }
    );
    $('.divNotebook').hover(
			function () {
			    $(this).css("background", "url(img/folder_BG.png) no-repeat");
			},
			function () {
			    $(this).css("background-image", "");
			}
		);
    $('.divNotebook').click(
        function () {
            var flag = window.external.SelectedNotebook($(this).attr("id"));
            if (flag) {
                $('#divModelSlt').show();
                $('#divHome').hide();
            }
        }
    );
    $('.divWDBook').hover(
			function () {
			    $(this).css("background", "url(img/folder_BG.png) no-repeat");
			},
			function () {
			    $(this).css("background-image", "");
			}
		);
    $('.divWDBook').click(
        function () {
            window.external.SelectWDAlbum($(this).attr("id"));
        }
        );
}
function showModelSlt() {
    $('#divModelSlt').show();
    $('#divHome').hide();
}
function cardFlip() {
    var f = window.external.GSFlipTime(600);
    if (!f) {
        return;
    }
    //$('.flashCard').quickFlipper();
    $('.flashCard').quickFlipperWithCallback(DeckCardDefiHeight);
    $('.headWord').html("");
    var arr = $('.definition');
    $(arr[1]).html("");
    $(arr[2]).html("");
    var arr1 = $('.headWord2');
    $(arr1[1]).html("");
    $(arr1[2]).html("");
    $('.flipBtn').hide();
    $('.judgeMe').show();
    window.external.ConvertToExp();
}
function RightAndWrong() {
    $('.rightBTN').attr("href", "javascript:responseRight();");
    $('.wrongBTN').attr("href", "javascript:responseWrong();");
}

function responseRight() {
    leftSlider(
        function () {
            window.external.KnowClick();
        },
        function () {
            $('.flipBtn').show();
            $('.judgeMe').hide();
        }
    );
}
function responseWrong() {
    leftSlider(
        function () {
            window.external.UnKnowClick();
        },
        function () {
            $('.flipBtn').show();
            $('.judgeMe').hide();
        }
    );
}
function makeFamiliar() {
    leftSlider(
        function () {
            window.external.SetFamiliarClick();
        },
        function () {
            $('.flipBtn').show();
            $('.judgeMe').hide();
        }
            );
}
function leftSlider(f1, f2) {
    var fl = window.external.GSFlipTime(500);
    if (!fl) {
        return;
    }
    var i = $('#divFlashCard1').offset().left;
    var j = $('#divFlashCard2').offset().left;
    if (i <= 30 && i >= 0) {
        $('#divFlashCard2').css({ left: "0px" });
        z = $('#divFlashCard1').css("z-index");
        z--;
        $('#divFlashCard2').css({ "z-index": z });
        window.external.SetSelectStudyCardIndex(true);
        f1();
        $('#divFlashCard1').animate({ left: "-390px" }, 500);
        z = z + 2;
        $('#divFlashCard1').css({ "z-index": z });
    }
    if (j <= 30 && j >= 0) {
        $('#divFlashCard1').css({ left: "0px" });
        z = $('#divFlashCard2').css("z-index");
        z--;
        $('#divFlashCard1').css({ "z-index": z });
        window.external.SetSelectStudyCardIndex(false);
        f1();
        $('#divFlashCard2').animate({ left: "-390px" }, 500);
        z = z + 2;
        $('#divFlashCard2').css({ "z-index": z });
    }

    f2();
}

function ModelStudyInit() {
    $(document).keydown(function () {
        if (event.keyCode == 116) {
            event.keyCode = 0;
            event.returnValue = false;
            return false;
        }
        else if (event.keyCode == 0 && !$('.flipBtn').is(":hidden")) {//enter
            event.keyCode = 0;
            event.returnValue = 0;
            cardFlip();
            
        }
        else if ($('.flipBtn').is(':hidden') && (event.keyCode == 89 || event.keyCode == 121)) {//y or Y
            event.keyCode = 0;
            event.returnValue = 0;
            responseRight();
        }
        else if ($('.flipBtn').is(':hidden') && (event.keyCode == 78 || event.keyCode == 110)) {//n or N
            event.keyCode = 0;
            event.returnValue = 0;
            responseWrong();
        }
        else if ($('.flipBtn').is(':hidden') && (event.keyCode == 77 || event.keyCode == 109)) {//m or M
            event.keyCode = 0;
            event.returnValue = 0;
            window.external.GetMoreDefForCurrentWord();
        }
        else if ($('.flipBtn').is(':hidden') && (event.keyCode == 80 || event.keyCode == 112)) {//p or P
            event.keyCode = 0;
            event.returnValue = 0;
            PlayAudioAnimate();
            window.external.PlayCurrentWord();
        }
    });
}
function initialFlip() {
    $('#divFlashCard1').quickFlip();
}
function initialRecom() {
    $('.recommand').click(function () {
        $('.snsShare').show();
    });
    $('.closeShare').click(function () {
        $('.snsShare').hide();
    });
}
function ReBindAutoAndPause() {
    autoAndpauseEvent();
}
function autoAndpauseEvent() {
    $('#autoBTN').removeClass().unbind();
    $('#pauseBTN').removeClass().unbind();

    clearTimeout(autoPlayTimeOutId);
    $('#autoBTN').addClass("divBTNBase divautoBTN");
    $('#autoBTN').mouseover(function () {
        $(this).removeClass("divautoBTN").addClass("divautoBTN1");
    }).mouseout(function () {
        $(this).removeClass("divautoBTN1").addClass("divautoBTN");
    }).mousedown(function () {
        $(this).removeClass("divautoBTN1").addClass("divautoBTN2")
    }).mouseup(function () {
        $(this).removeClass("divautoBTN2").addClass("divautoBTN");
    }).click(function () {
        AutoPlay();
        $(this).hide();
        $("#pauseBTN").show();
    });

    $('#pauseBTN').addClass("divBTNBase divpauseBTN");
    $('#pauseBTN').mouseover(function () {
        $(this).removeClass("divpauseBTN").addClass("divpauseBTN1");
    }).mouseout(function () {
        $(this).removeClass("divpauseBTN1").addClass("divpauseBTN");
    }).mousedown(function () {
        $(this).removeClass("divpauseBTN1").addClass("divpauseBTN2")
    }).mouseup(function () {
        $(this).removeClass("divpauseBTN2").addClass("divpauseBTN");
    }).click(function () {
        StopAutoPlay();
        $(this).hide();
        $("#autoBTN").show();
    });
    $("#pauseBTN").hide();
}
function preBTNEventNotValid() {
    $('#preBTN').unbind();
    $('#preBTN').removeClass().addClass("divBTNBase divpreBTN3");
}
function preBTNEvent() {
    $('#preBTN').removeClass("divpreBTN3").addClass("divpreBTN");
    $('#preBTN').mouseover(function () {
        $(this).removeClass("divpreBTN").addClass("divpreBTN1");
    }).mouseout(function () {
        $(this).removeClass("divpreBTN1").addClass("divpreBTN");
    }).mousedown(function () {
        $(this).removeClass("divpreBTN1").addClass("divpreBTN2");
    }).mouseup(function () {
        $(this).removeClass("divpreBTN2").addClass("divpreBTN");
    });
}
function nextBTNEvent() {
    isSetNext = true;
    $('#nextBTN').addClass("divBTNBase divnextBTN");
    $('#nextBTN').mouseover(function () {
        $(this).removeClass("divnextBTN").addClass("divnextBTN1");
    }).mouseout(function () {
        $(this).removeClass("divnextBTN1").addClass("divnextBTN");
    }).mousedown(function () {
        $(this).removeClass("divnextBTN1").addClass("divnextBTN2")
    }).mouseup(function () {
        $(this).removeClass("divnextBTN2").addClass("divnextBTN");
    });
}

var SiteMap = {
    amsn: 'http://profile.live.com/badge?url={0}',
    asina: 'http://v.t.sina.com.cn/share/share.php?title={1}...{0}',
    atsohu: 'http://t.sohu.com/third/post.jsp?url={0}&title={1}&content=utf-8',
    adouban: 'http://www.douban.com/recommend/?url={0}&title={1}',
    a163: 'http://t.163.com/article/user/checkLogin.do?info={1}+{0}',
    atianya: 'http://share.tianya.cn/openapp/restpage/activity/appendDiv.jsp?ccTitle={1}&ccUrl={0}',
    arenren: 'http://share.xiaonei.com/share/buttonshare.do?link={0}',
    akaixin: 'http://www.kaixin001.com/~repaste/repaste.php?rtitle={1}&rurl={0}'
};
var cnts = {
    url: "http://dict.bing.msn.cn/",
    ctent: '我正在使用必应背单词，记忆曲线模型记单词，还可以按照词频，后缀，乱序记单词，很有效哦！'
};

function SendShareMsg(el, wsite, isEncode) {
    u = SiteMap[wsite];
    en = encodeURIComponent;
    el.href = isEncode ? fmt(u, en(cnts.url), en(cnts.ctent)) : fmt(u, cnts.url, cnts.ctent);

}
function fmt(src, ag1, ag2) {
    return src.replace("{0}", ag1).replace("{1}", ag2);
}
function iShare() {
    $('#amsn').click(function () { SendShareMsg(this, this.id, '1'); $('.snsShare').hide(); }).attr("target", "_blank");
    $('#asina').click(function () { SendShareMsg(this, this.id, '1'); $('.snsShare').hide(); }).attr("target", "_blank");
    $('#atsohu').click(function () { SendShareMsg(this, this.id, '1'); $('.snsShare').hide(); }).attr("target", "_blank");
    $('#adouban').click(function () { SendShareMsg(this, this.id, '1'); $('.snsShare').hide(); }).attr("target", "_blank");
    $('#a163').click(function () { SendShareMsg(this, this.id, '1'); $('.snsShare').hide(); }).attr("target", "_blank");
    $('#atianya').click(function () { SendShareMsg(this, this.id, '1'); $('.snsShare').hide(); }).attr("target", "_blank");
    $('#arenren').click(function () { SendShareMsg(this, this.id); $('.snsShare').hide(); }).attr("target", "_blank");
    $('#akaixin').click(function () { SendShareMsg(this, this.id, '1'); $('.snsShare').hide(); }).attr("target", "_blank");
}
function iShareForStartPage() {
    $('#amsn').click(function () { SendShareMsg(this, this.id, '1'); }).attr("target", "_blank");
    $('#asina').click(function () { SendShareMsg(this, this.id, '1'); }).attr("target", "_blank");
    $('#atsohu').click(function () { SendShareMsg(this, this.id, '1'); }).attr("target", "_blank");
    $('#adouban').click(function () { SendShareMsg(this, this.id, '1'); }).attr("target", "_blank");
    $('#a163').click(function () { SendShareMsg(this, this.id, '1'); }).attr("target", "_blank");
    $('#atianya').click(function () { SendShareMsg(this, this.id, '1'); }).attr("target", "_blank");
    $('#arenren').click(function () { SendShareMsg(this, this.id); }).attr("target", "_blank");
    $('#akaixin').click(function () { SendShareMsg(this, this.id, '1'); }).attr("target", "_blank");
}
function SetRightSlider() {
    $("#nextBTN").click(
        function () {

            vid = currentPhIdx + "card";
            currentPhIdx++;
            vid2 = currentPhIdx + "card";
            $('#' + vid).animate({ left: "-360px" }, 600);
            $('#' + vid2).animate({ left: "0px" }, 600);

            if (!isSetPre) {
                preBTNEvent();
                isSetPre = true;
            }
        });
    }

function setPreBTNNotValid() {
    isSetPre = false;
    preBTNEventNotValid();
}
function setPreBTNValid() {
    var api = $('.scroll-pane').data('jsp');
    preBTNEvent();
    $('#preBTN').unbind('click');
    $('#preBTN').bind('click', function () {
        SetPreviousButton(api);
    });
    isSetPre = true;
}
function destroyJSP() {
    var api = $('.scroll-pane').data('jsp');
    api.destroy();
    window.external.SetEndUnitCnt();
    isSetNext = false;
}
function unitLinkClick(obj, idx) {
    if (!$(obj).hasClass("current")) {
        $('.unitPav .current').removeClass();
        $(obj).addClass("current");
        window.external.GetUnitWordsByLink(idx);
    }
}
function GotoNextUnit() {
    $('.unitPav .current').removeClass();
    window.external.SetNextUnitCnt();
}
function GotoPreUnit() {
    $('.unitPav .current').removeClass();
    window.external.SetPreUnitCnt();
}
function pageLinkClick(obj, idx) {
    if (!$(obj).hasClass("current")) {
        window.external.GetUnitPages(idx);
    }
}
function setScrollWidth1(obj) {
    $('#scroll').css({ width: obj });
    var api = $('.scroll-pane').data('jsp');
    api.reinitialise();
    api.scrollToX(0);
}
function SetNextButton(api) {
    xy = api.getContentPositionX();
    yy = xy % 360;
    if (yy != 0) {
        xy = xy - yy + 360;
    }
    if (xy == 0) {
        var w = api.getContentPane().css("width");
        if (w != "360px") {
            api.scrollToX(360);
        }
    }
    else {
        api.scrollToX(xy + 360);
    }

    xy = api.getContentPositionX();
    yy = xy % 360;
    if (yy != 0) {
        xy = xy - yy + 360;
    }
    var i = xy / 360;

    if (!isSetPre) {
        preBTNEvent();
        $('#preBTN').bind('click', function () {
            SetPreviousButton(api);
        });
        isSetPre = true;
    }

    var j = window.external.SetPhIdxInUnitByButton(true);
    if (j != i + 2) {
        j--;
        api.scrollToX(j * 360);
    }
    return false;
}
function SetPreviousButton(api) {
    xy = api.getContentPositionX();
    yy = xy % 360;
    if (yy != 0) {
        xy = xy - yy + 360;
    }
    api.scrollToX(xy - 360);
    x = api.getContentPositionX();
    if (x <= 360) {
        isSetPre = false;
        preBTNEventNotValid();
    }
    xy = api.getContentPositionX();
    yy = xy % 360;
    if (yy != 0) {
        xy = xy - yy + 360;
    }
    var i = xy / 360;
    var j = window.external.SetPhIdxInUnitByButton(false);
    if (j != i) {
        j--;
        api.scrollToX(j * 360);
    }
    //clear timer
    StopAutoPlay();
    return false;
}
function AutoPlay() {
    clearTimeout(autoPlayTimeOutId);
    autoPlayTimeOutId = setTimeout(function () {
        window.external.SetAutoPlayStatus(true);
        SetAutoPlayToActive();
    }, "300");
}
function StopAutoPlay() {
    if (autoPlayTimeOutId != undefined && autoPlayTimeOutId != null) {
        clearTimeout(autoPlayTimeOutId);
        window.external.SetAutoPlayStatus(false);
        $("#autoBTN").show();
        $("#pauseBTN").hide();
    }
}

function SetAutoPlayToActive() {
    $('#nextBTN').click();
    clearTimeout(autoPlayTimeOutId);
    autoPlayTimeOutId = setTimeout(SetAutoPlayToActive, "5000");
}
function MOver() {
    if (autoPlayTimeOutId != undefined && autoPlayTimeOutId != null) {
        clearTimeout(autoPlayTimeOutId);
        window.external.SetAutoPlayStatus(false);
    };
}
function MOut() {
    var tempx = event.clientX - document.body.scrollLeft;
    var tempy = event.clientY - document.body.scrollTop;
    if (tempx < 26 || tempx > 360 || tempy < 41 || tempy > 239) {
        autoPlayTimeOutId = setTimeout(function () {
            if ($('#pauseBTN').is(":visible") == true) {
                window.external.SetAutoPlayStatus(true);
                SetAutoPlayToActive();
            }
        }, "400");
    }
}
function PlayWord(headword) {
    var hash = window.external.GetHeadwordHash(headword);
    var url = "http://dict.bing.com.cn/ah/" + hash + ".mp3";
    //var audioPlayer = document.getElementById("_aplayer");
    //audioPlayer.Settings.PlayCount = 1;
    //audioPlayer.URL = url;
    var audioPlayer = document.getElementById("_aplayer");
    try
    {
        audioPlayer.SetVariable("hash", url);
        audioPlayer.GotoFrame(2); // Stop potentially any playing sounds
        audioPlayer.GotoFrame(1);
    }
    catch (e)
    {
        if (audioPlayer.Settings)
        {
            audioPlayer.Settings.PlayCount = 1; //Call Settings.PlayCount especially to draw an exception if this is not present
            audioPlayer.URL = url;
        }
    }
}
function fixPNG(myImage) {
    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
        var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
        var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
        var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' ";
        var imgStyle = "display:inline-block;" + myImage.style.cssText;
        var strNewHTML = "<span " + imgID + imgClass + imgTitle

      + " style=\"" + "width:" + myImage.width

      + "px; height:" + myImage.height

      + "px;" + imgStyle + ";"

      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"

      + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
        myImage.outerHTML = strNewHTML;
    }
}
function CleanCardDefiHeight() {
    $('.definition').each(function () {
        $(this).css("overflow", "visible");
        $(this).parent().find('.omitMard').hide();
    });
}
function DeckCardDefiHeight() {
    $('.definition').each(function () {
        if ($(this).height() > parseInt($(this).css("max-height"))) {
            $(this).css("overflow", "hidden");
            $(this).parent().find('.omitMard').show();
        }
    }
        );
}
//region SelectView
function UnitCntView() {
    isSetPre = false;
    $('.scroll-pane').jScrollPane(
		{
		    clickOnTrack: false,
		    animateScroll: true,
		    horizontalDragMinWidth: 20
		});
    var api = $('.scroll-pane').data('jsp');

    $('#preBTN').unbind('click');
    $('#nextBTN').unbind('click');
    $('#nextBTN').bind('click', function () {
        SetNextButton(api);
    });
    $(document).keydown(function () {
        if (event.keyCode == 116 || event.keyCode == 13) {
            event.keyCode = 0;
            event.returnValue = false;
        }
        else if (event.keyCode == 37 && isSetPre) {//<-
            event.keyCode = 0;
            event.returnValue = 0;
            $('#preBTN').click();
        }
        else if (event.keyCode == 39 && isSetNext) {//->
            event.keyCode = 0;
            event.returnValue = 0;
            $('#nextBTN').click();
        }
        else if (event.keyCode == 32) {//space
            event.keyCode = 0;
            event.returnValue = 0;
            if (!$("#pauseBTN").is(":hidden")) {
                StopAutoPlay();
                $('#autoBTN').show();
                $("#pauseBTN").hide();
            }
            else {
                AutoPlay();
                $('#autoBTN').hide();
                $("#pauseBTN").show();
            }
        }
        else if (event.keyCode == 34) {//page down
            event.keyCode = 0;
            event.returnValue = 0;
            GotoNextUnit();
        }
        else if (event.keyCode == 33) {//page up
            event.keyCode = 0;
            event.returnValue = 0;
            GotoPreUnit();
        }
        else if (event.keyCode == 77 || event.keyCode == 109) {//m or M
            event.keyCode = 0;
            event.returnValue = 0;
            window.external.GetMoreDefForCurrentWord();
        }
        else if (event.keyCode == 80 || event.keyCode == 112) {//p or P
            event.keyCode = 0;
            event.returnValue = 0;
            PlayAudioAnimate();
            window.external.PlayCurrentWord();
        }
        else if ($('.againBTN').length && (event.keyCode == 82 || event.keyCode == 114)) {//r or R
            event.keyCode = 0;
            event.returnValue = 0;
            window.external.ReBrowsingUnit();
        }
        else if (!$('.nextUnit').length && event.keyCode == 34) {//page down
            event.keyCode = 0;
            event.returnValue = 0;
            GotoNextUnit();
        }
        return false;
    });
}
function ScrollToZero() {
    $('.jspPane').css("left", "0px");
    $('.jspDrag').css("left", "0px");
}
function ScrollToJSPWithDelay(oIdx) {
    setTimeout(function () {
        var api = $('.scroll-pane').data('jsp');
        var idx = parseInt(oIdx);
        idx = (idx - 1) * 360;
        api.scrollToX(idx);
        if (idx != 0) {
            setPreBTNValid();
        }
    },
    100 //dasons: add 100ms delay to wait function setScrollWidth finish reinitialise operations
    );
}
function ScrollToJSP(oIdx) {
    var api = $('.scroll-pane').data('jsp');
    var idx = parseInt(oIdx);
    idx = (idx - 1) * 360;
    api.scrollToX(idx);
    if (idx != 0) {
        setPreBTNValid();
    }
}
function setScrollWidth(obj) {

    $('#scroll').css({ width: obj });

    var api = $('.scroll-pane').data('jsp');
    //    api.reinitialise();
    var throttleTimeout;
    if ($.browser.msie) {
        if (!throttleTimeout) {
            throttleTimeout = setTimeout(
								function () {
								    api.reinitialise();
								    throttleTimeout = null;
								},
								50  //dasons: doesn't know why this 50ms needed, but maybe a previous bug, just let them stay here.
							);
        }
    }
    ScrollToZero();
}
//endregion
//region RandomView
function UnitRandomViewInit() {
    isSetPre = false;
    sliderMutex = true;

    $('#preBTN').unbind('click');
    $('#nextBTN').unbind('click');
    $('#nextBTN').bind('click', function A() {
        if (!sliderMutex) {
            return;
        }

        $('#nextBTN').unbind('click');
        //        isSetNext = false;
        leftSliderForRandomView(
        function () {
            window.external.RandomViewNextClick();
        },
        function () {
            $('#nextBTN').bind('click', A);
            //isSetNext = true;
            //alert("bind");
        }
        );
    });
    isSetNext = true;

    $(document).keydown(function () {
        if (event.keyCode == 116 || event.keyCode == 13) {
            event.keyCode = 0;
            event.returnValue = false;
        }
        else if (event.keyCode == 37 && isSetPre) {//<-
            event.keyCode = 0;
            event.returnValue = 0;
            $('#preBTN').click();
        }
        else if (event.keyCode == 39 && isSetNext) {//->
            event.keyCode = 0;
            event.returnValue = 0;
            $('#nextBTN').click();
        }
        else if (event.keyCode == 77 || event.keyCode == 109) {//m or M
            event.keyCode = 0;
            event.returnValue = 0;
            window.external.GetMoreDefForCurrentWord();
        }
        else if (event.keyCode == 80 || event.keyCode == 112) {//p or P
            event.keyCode = 0;
            event.returnValue = 0;
            PlayAudioAnimate();
            window.external.PlayCurrentWord();
        }
        return false;
    });
}
function nextBTN_RV_Event() {
    isSetNext = true;
    $('#nextBTN').addClass("divBTNRandomviewBase divNextBTNRVC");
    $('#nextBTN').mouseover(function () {
        $(this).removeClass("divNextBTNRVC").addClass("divNextBTNRVH");
    }).mouseout(function () {
        $(this).removeClass("divNextBTNRVH").addClass("divNextBTNRVC");
    }).mousedown(function () {
        $(this).removeClass("divNextBTNRVH").addClass("divNextBTNRVA")
    }).mouseup(function () {
        $(this).removeClass("divNextBTNRVA").addClass("divNextBTNRVC");
    });
}
function preBTNEvent_RV_NotValid() {
    $('#preBTN').unbind();
    $('#preBTN').removeClass().addClass("divBTNRandomviewBase divPreBTNRVF");
}
function setPreBTN_RV_NotValid() {
    isSetPre = false;
    preBTNEvent_RV_NotValid();
}
function preBTN_RV_Event() {
    $('#preBTN').removeClass("divPreBTNRVF").addClass("divPreBTNRVC");
    $('#preBTN').mouseover(function () {
        $(this).removeClass("divPreBTNRVC").addClass("divPreBTNRVH");
    }).mouseout(function () {
        $(this).removeClass("divPreBTNRVH").addClass("divPreBTNRVC");
    }).mousedown(function () {
        $(this).removeClass("divPreBTNRVH").addClass("divPreBTNRVA");
    }).mouseup(function () {
        $(this).removeClass("divPreBTNRVA").addClass("divPreBTNRVC");
    });
}
var sliderMutex = true;
function leftSliderForRandomView(f1, f2) {
    sliderMutex = false;
    var fl = window.external.GSFlipTime(500);
    if (!fl) {
        return;
    }
    var i = $('#divFlashCard1').offset().left;
    var j = $('#divFlashCard2').offset().left;
    if (i <= 30 && i >= 0) {
        $('#divFlashCard2').css({ left: "0px" });
        z = $('#divFlashCard1').css("z-index");
        z--;
        $('#divFlashCard2').css({ "z-index": z });
        window.external.SetSelectStudyCardIndex(true);
        f1();
        $('#divFlashCard1').animate({ left: "-390px" }, 500, function () {
            sliderMutex = true;
            z = z + 2;
            $('#divFlashCard1').css({ "z-index": z });
            f2();

        }
        );

    }
    if (j <= 30 && j >= 0) {
        $('#divFlashCard1').css({ left: "0px" });
        z = $('#divFlashCard2').css("z-index");
        z--;
        $('#divFlashCard1').css({ "z-index": z });
        window.external.SetSelectStudyCardIndex(false);
        f1();
        $('#divFlashCard2').animate({ left: "-390px" }, 500, function () {
            sliderMutex = true;
            z = z + 2;
            $('#divFlashCard2').css({ "z-index": z });
            f2();

        }
        );
    }
}
function rightSliderForRandomView(f1, f2) {
    sliderMutex = false;
    var fl = window.external.GSFlipTime(500);
    if (!fl) {
        return;
    }
    var i = $('#divFlashCard1').offset().left;
    var j = $('#divFlashCard2').offset().left;
    if (i <= 30 && i >= 0) {
        $('#divFlashCard2').css({ left: "0px" });
        z = $('#divFlashCard1').css("z-index");
        z--;
        $('#divFlashCard2').css({ "z-index": z });
        window.external.SetSelectStudyCardIndex(true);
        f1();
        $('#divFlashCard1').animate({ left: "390px" }, 500, function () {
            sliderMutex = true;
            z = z + 2;
            $('#divFlashCard1').css({ "z-index": z });
            f2();

        });
    }
    if (j <= 30 && j >= 0) {
        $('#divFlashCard1').css({ left: "0px" });
        z = $('#divFlashCard2').css("z-index");
        z--;
        $('#divFlashCard1').css({ "z-index": z });
        window.external.SetSelectStudyCardIndex(false);
        f1();
        $('#divFlashCard2').animate({ left: "390px" }, 500, function () {
            sliderMutex = true;
            z = z + 2;
            $('#divFlashCard2').css({ "z-index": z });
            f2();

        });
    }
}
function setpreBTNValidForRandomView() {
    if (!isSetPre) {
        preBTN_RV_Event();

        $('#preBTN').bind('click', function B() {
            if (!sliderMutex) {
                return;
            }

            $('#preBTN').unbind('click');
            rightSliderForRandomView(
        function () {
            //$('#preBTN').unbind('click');
            //isSetPre = false;
            window.external.RandomViewPreviousClick();
        }
        ,
        function () {
            //isSetPre = true;
            $('#preBTN').bind('click', B);
        }
        );
        });
    }
    isSetPre = true;
}
//endregion