﻿var dialog;
$(document).ready(function () {
    $("#btnlogin").live('click', function () {
        var emailid = $('#txtEmailID').val();
        var userpass = $('#txtPass').val();
        var remuser = $("#remme:checked").length > 0;

        $.post('/user/loginajax', { emailid: emailid, userpass: userpass, remuser: remuser },
            function (result) {
                if (result.result)
                    window.location.reload();
                else {
                    $("#loginerror").html(result.message);
                    $("#txtPass").val(null);
                }
            });
        return false;
    });

    $("a#login").click(function () {
        showLogin();
    });

    $("a#resetimages").click(function () {
        var id = $(this).parents(".articleadmin").attr('id').substr(3);

        $.post('/admin/resetpostimages/', { postid: id },
            function (res) {
                if (res.result)
                    alert("Images have been reset.");
                else
                    alert("Images could not be reset.");
            }, "json");

        return false;
    });

    $("div.singlequestion ul.questScore li.likes, img.iDn").click(function () {
        id = $("#question").val();
        var cur = $(this);
        if ($(this).hasClass('likes')) {
            $.post('/questions/vote', { vType: 1, qID: id }, function (result) {
                showQRating(result);
                cur.children().children().html(result.score);
                return false;
            });
        }
        else if ($(this).hasClass('iDn')) {
            $.post('/questions/vote', { vType: 2, qID: id }, function (result) {
                showQRating(result);
                cur.children().children().html(result.score);
                return false;
            });
        }
    });

    $("span.alike, img.aDn").live('click', function () {
        id = $(this).parents("div.userPic").parent().attr('id').substr(1);
        if ($(this).hasClass('alike')) {
            $.post('/answers/vote', { vType: 1, aID: id }, function (result) {
                showARating(result, id);
            });
        }
        else if ($(this).hasClass('aDn')) {
            $.post('/answers/vote', { vType: 2, aID: id }, function (result) {
                showARating(result, id);
            });
        }
        return false;
    });

    $("div.singlequestion ul.questScore li.addTofav,div.favc").click(function () {
        id = $("#question").val();
        $.post('/questions/fav', { qID: id }, function (result) {
            if (result.result == false) {
                showQRating(result);
            }
            else if (result.result == true) {
                if (result.votetype == 0)
                    $('.addTofav').removeClass('favy').addClass('favn');
                else if (result.votetype == 1)
                    $('.addTofav').removeClass('favn').addClass('favy');

                $('.favc').html(result.score);
            }
        });
        return false;
    });

    $("div.jlink").live('click', function () {
        id = $(this).parents("div.answer").attr('id');
        elem = $(this);

        $.post('/answers/accept', { aid: id.substr(1) }, function (result) {
            if (result.result === false) {
                alert(result.message);
            }
            else {
                if (elem.hasClass("yaccpt")) {
                    elem.removeClass('yaccpt');
                    elem.addClass('naccpt');
                }
                else {
                    $("div.yaccpt").removeClass("yaccpt").addClass("naccpt jlink");
                    elem.removeClass('naccpt');
                    elem.addClass('yaccpt');
                }
            }
        });
    });

    $('h3.qhd').hoverIntent({
        over: function () {
            var txt = $("<div class='txt'>" + $(this).attr('title') + "</div>");
            $(this).attr('title', '');
            $(this).after(txt);
            txt.hide();
            txt.fadeIn('slow');
            $(this).unbind('mouseover');
        }, senstivity: 3, interval: 300,
        out: function () {
            return;
        }
    });

    $("#ittagAdd").click(function () {
        $.post("/users/addusertagtodatabase/",
                { 'param1': $("#txtittags").val(), 'param2': 1 },
                function (data) {
                    if (data.result == true) {
                        $.post("/users/showuseraddedtagtodiv/",
                    { 'param1': $("#txtittags").val() }, function (data) {
                        $("#txtittags").html("");
                    });
                    }
                    else if (data.result == false) {
                        $("span#errortag").html(data.message);
                    }
                });
    });

    $('#txtigtags').autocomplete({
        source: '/tags/searchtags' + $('#txtigtags').val(),
        minLength: 2,
        delay: 500,
        select: function (event, ui) {
            var trm = getOnlyTag(ui.item.label);
            ui.item.value = trm;
        },
        focus: function (event, ui) {
            var trm = getOnlyTag(ui.item.label);
            ui.item.value = trm;
        }
    });

    function getOnlyTag(trm) {
        trm = trm.substr(0, trm.indexOf(' ['));
        return trm;
    }

    $("#tagIgnoredAdd").click(function () {
        var tg = $('#txtigtags').val();

        if (tg.indexOf(',') == -1) {
            $.post("/users/addignoredtag/", { 'param1': tg }, function (data) {
                if (data.result == true) {
                    $('ul#igtlist').append(data.content);
                }
                else {
                    $("span#errorignoredtag").html(data.message);
                }
            });
        }
        else {
            $("span#errorignoredtag").html("<br/>Commas are not not allowed.");
        }
    });

    $("#tagInterestingAdd").click(function () {
        var tg = $('#txtintags').val();

        if (tg.indexOf(',') == -1) {
            $.post("/users/addinterestingtag/", { 'param1': tg }, function (data) {
                if (data.result == true) {
                    $('ul#intlist').append(data.content);
                }
                else {
                    $("span#errorinttag").html(data.message);
                }
            });
        }
        else {
            $("span#errorinttag").html("<br/>Commas are not not allowed.");
        }
    });

    $('#txtintags').autocomplete({
        source: '/tags/searchtags' + $('#txtintags').val(),
        minLength: 2,
        delay: 500,
        select: function (event, ui) {
            var trm = getOnlyTag(ui.item.label);
            ui.item.value = trm;
        },
        focus: function (event, ui) {
            var trm = getOnlyTag(ui.item.label);
            ui.item.value = trm;
        }
    });

    $("img.deleteignoredtag, img.deleteinterestingtag").live('mouseover', function () {
        $(this).attr('src', '/img/cmtdelhvr.png');
    });

    $("img.deleteignoredtag, img.deleteinterestingtag").live('mouseout', function () {
        $(this).attr('src', '/img/cmtdel.png');
    });

    $("a.flagq").click(function () {
        if ($("#flagdialog").length > 0) {
            $("#flagdialog").remove();
        }

        var lnk = '/questions/flag/' + $("#question").val();
        dialog = $("<div></div>").load(lnk).dialog({ closeOnEscape: true, draggable: false, height: 'auto', width: 350, modal: true, position: 'center', resizable: false, title: "Flag this question", closeText: "" });
        return false;
    });

    $("a.aflag").click(function () {
        if ($("#flagdialog").length > 0) {
            $("#flagdialog").remove();
        }

        var lnk = '/questions/flaga/' + $(".answerDetail").attr('id').substr(4);
        dialog = $("<div></div>").load(lnk).dialog({ closeOnEscape: true, draggable: false, height: 'auto', width: 350, modal: true, position: 'center', resizable: false, title: "Flag this answer", closeText: "" });
        return false;

    });

    $("a.deleteq").live('click', function () {
        var choice = confirm("Do you really want to delete this question?");
        if (choice) {
            $.ajax({
                url: "/questions/deletequestion",
                global: false,
                type: "POST",
                data: ({ qID: qID }),
                dataType: "json",
                async: false,
                success: function (data) {
                    if (data.result) {
                        window.location = "/questions";
                    }
                    else {
                        alert(data.message);
                    }
                }
            });
        }
        return false;
    });
    $("a.adelete").click(function () {
        var ansID = $(this).attr('href').split('/')[3];
        var choice = confirm("Do you really want to delete this  answer?");
        if (choice) {
            $.ajax({
                url: "/answers/deleteanswer",
                global: false,
                type: "POST",
                data: ({ aid: ansID }),
                dataType: "json",
                async: false,
                success: function (data) {
                    if (data.result) {
                        window.location.reload(true);
                    }
                    else {
                        alert(data.message);
                    }
                }
            });
        }
        return false;
    });

    $("a.qclose").live('click', function () {
        var choice = confirm("Do you really want to close this question?");
        if (choice) {
            $.ajax({
                url: "/questions/closed",
                global: false,
                type: "POST",
                data: ({ qid: qID }),
                dataType: "json",
                async: false,
                success: function (data) {
                    if (data.result) {
                        window.location.reload(true);
                    }
                    else {
                        alert(data.message);
                    }
                }
            });
        }
        return false;
    });
    $("a.qopen").live('click', function () {
        var choice = confirm("Do you really want to open this question?");
        if (choice) {
            $.ajax({
                url: "/questions/opend",
                global: false,
                type: "POST",
                data: ({ qid: qID }),
                dataType: "json",
                async: false,
                success: function (data) {
                    if (data.result) {
                        window.location.reload(true);
                    }
                    else {
                        alert(data.message);
                    }
                }
            });
        }
        return false;
    });

    $('img.deleteignoredtag').live('click', function () {
        var id = $(this).attr('id').substr(2);
        var obj = $(this);

        $.post('/tags/delignored', { id: id }, function (result) {
            if (result.result) {
                obj.parent('li').remove();
            }
            else {
                alert(result.message);
            }
        });
    });

    $('img#.deleteinterestingtag').live('click', function () {
        var id = $(this).attr('id').substr(2);
        var obj = $(this);

        $.post('/tags/delinteresting', { id: id }, function (result) {
            if (result.result)
                obj.parent('li').remove();
            else
                alert(result.message);
        });
    });

    function createDialog(ttl, lnk) {
        dialog = $("<div></div>").load(lnk).dialog({ closeOnEscape: true, draggable: false, width: 400, modal: true, position: 'center', resizable: false, title: ttl });
    }

    $("#closdg").live("click", function () {
        closeDialog();
    });

    function closeDialog() {
        dialog.dialog("close");
    }

    $('#qaddComm').click(function () {
        if ($(this).hasClass('morecmt')) {
            var qid = $('div.question').attr('id').substr(1);

            $.post('/comments/moreqcmt', { param1: qid }, function (result) {
                if (result.result) {
                    $("#qclist").append(result.content)
                    $("#qcmt").removeClass('hidden');
                    $("div.qaddcom").addClass('hidden');
                }
            });
        }
        else {
            $(".cmtxt").val("");
            $("#qcmt").removeClass('hidden');
            $(".qaddComm").addClass('hidden');
        }
    });

    $('.adComm').click(function () {
        var id = $(this).attr('id').substr(2);

        if ($(this).hasClass('morecmt')) {
            $.post('/comments/moreacmt', { param1: id }, function (result) {
                if (result.result) {
                    $("#acl" + id).append(result.content);
                }

                $(".cmtxt").val("");
                $("#acmt" + id).removeClass('hidden');
                $("#ac" + id).addClass('hidden');
            });
        }
        else {
            $(".cmtxt").val("");
            $("#acmt" + id).removeClass('hidden');
            $("#aaddc" + id).addClass('hidden');
        }
    });

    $('#sbmtqcmt').click(function () {
        var id = $("#question").val();

        $.post('/questions/newcomment',
                {
                    qID: id,
                    txt: $("#qcmttxt").val()
                },
                    function (result) {
                        if (result.result) {
                            if ($('div.qcmts').hasClass('hidden'))
                                $('div.qcmts').removeClass('hidden');

                            $("#qclist").append(result.content);
                            $("#qcmt").addClass('hidden');
                        }
                        else {
                            alert("Error: " + result.message);
                        }
                    });
    });

    $('.smbtacmt').click(function () {
        id = $(this).attr('id').substr(3);

        $.post('/answers/newcomment',
                {
                    aID: id,
                    txt: $("#tacmt" + id).val()
                },
                function (result) {
                    if (result.result) {
                        if ($('div#acm' + id).hasClass('hidden'))
                            $('div#acm' + id).removeClass('hidden');

                        $("#acl" + id).append(result.content);
                        $("#acmt" + id).addClass('hidden');
                    }
                    else {
                        alert("Error: " + result.message);
                    }
                });
    });

    $('.nclose').live('click', function () {
        $(this).parents('li').fadeOut('slow', function () {
            mtop = parseInt($('body').css('margin-top').replace('px', ''));
            mtop -= 33; //Height of one notification
            $('body').css('margin-top', mtop + 'px');
        });
    });

    $("#delques").click(function () {
        if (confirm("Do you really want to delete this question.")) {
            id = $(this).parents("div.question").attr('id');
            $.post("/questions/deletequestion/",
                { 'qID': id.substr(1) }, function (data) {
                    if (data.result == true) {
                        window.location = "/";
                    }
                    else {
                        alert(data.message);
                    }
                }, "json");
        }
    });

    $("#delans").click(function () {
        if (confirm("Do you really want to delete this answer.")) {
            id = $(this).parents("div.answer").attr('id');
            $.post("/answers/deleteanswer/",
                { 'aID': id.substr(1) }, function (data) {
                });
        }
    });
    $(".delquescmt").click(function () {
        if (confirm("Do you really want to delete this comment.")) {
            id = $(this).attr('id');
            qID = $(this).parents("div.question").attr("id");
            alert(qID);
            $.post("/questions/deletecomment/",
                { 'qID': qID.substr(1), 'cmtID': id.substr(7) }, function (data) {
                });
        }
    });

    $(".delanscmt").click(function () {
        if (confirm("Do you really want to delete this comment.")) {
            id = $(this).attr('id');
            aID = $(this).parents("div.answer").attr("id");
            alert(aID);
            $.post("/answers/deletecomment/",
                { 'aID': aID.substr(1), 'cmtID': id.substr(6) }, function (data) {
                });
        }
    });

    $('#btnOffReward').click(function () {
        var qid = $('.question').attr('id').substr(1);
        var pty = $('#rewslider').slider('option', 'value');

        $.post('/questions/offerreward/',
        { quest: qid, points: pty },
        function (result) {
            if (result.result) {
                window.location.reload();
            }
            else {
                $('#rewerr').html(result.message);
            }
        });
    });

    $('a.qdrop').click(function () {
        return false;
    });

    $("a#logout").click(function () {
        $.post("/user/logoutajax", function (res) {
            if (res.result)
                window.location.reload(true);
        });

        return false;
    });

});
//End of document start

function messageModal(message, tmout) {
    $.get("/modal.htm", function (res) {
        $("body").append(res);
        $("#modaltxt").html(message);
        $("#modalmsg").fadeIn();

        setTimeout(function () {
            $('#modalmsg').fadeOut(function () { $('#modalmsg').remove(); });
        }, tmout);

    });
};

function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

function checkNewVisitor() {
    if (getCookie('qbmem') == "" && getCookie('nonewnotify') == "") {
        addNotification(newMemNoti, 0,
        function () {
            setCookie('nonewnotify', true, 100);
        });
    }
}

function checkNotifications() {
    $.post('/users/notifications/', function (result) {
        if (result.result) {
            for (i = 0; i < result.notis.length; i++) {
                addNotification(result.notis[i].text, result.notis[i].id,
                function (nID) {
                    $.post('/users/notificationseen', { id: nID }, null);
                });
            }
        }
    });
}

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function addNotification(txt, id, callMe) {
    if ($('#topnlist') == undefined) {
        var tl = $("<ul></ul>").attr('id', 'topnlist');
        $('body').prepend(tl);
    }

    $('<div class="ndiv">' + txt + '</div>')
    .hide()
    .append(
        $('<div class="nclose">x</div>').click(function () { callMe(id); })
    )
    .appendTo($('<li></li>')
    .appendTo('#topnlist'))
    .fadeIn('slow');

    //Top margin shifting
    mtop = parseInt($('body').css('margin-top').replace('px', ''));
    mtop += 33; //Height of one notification
    $('body').css('margin-top', mtop + 'px');
}

function showARating(result, id) {
    if (result.result == false) {
        if (result.reason == 'needlogin')
            showLogin();
        else
            $("#aacterr" + id).html(result.message).fadeIn().delay(4000).fadeOut();
    }
    else if (result.result == true) {
        $('li#a' + id + ' span.alike').html(result.score);
    }
}
function showQRating(result) {
    if (result.result == false) {
        if (result.reason == 'needlogin')
            showLogin();
        else
            $("#qacterr").html(result.message).fadeIn().delay(4000).fadeOut();
    }
    else if (result.result == true) {
        $('span#qlike').html(result.score);
    }
}

function showLogin() {
    dialog = $("<div></div>").load("/user/loginajax").dialog({ closeOnEscape: true, draggable: false, height: 'auto', width: 350, modal: true, position: 'center', resizable: false, title: "Login into your account", closeText: "" });
    return false;
}
function AddLike(qid) {
    var id = qid;
    var cur = $(this);
    if ($("ul.questScore li").hasClass('likes')) {
        $.post("/questions/vote", { vType: 1, qID: id }, function (data) {
            if (data.result) {
                showQRatingg(data);
                cur.children().children().html(data.score);
                document.location.reload();
            }
            else {
                alert("Sorry, you cannot like this question.");
            }
        }, "json");
    }
    else if ($(this).hasClass('iDn')) {
        $.post('/questions/vote', { vType: 2, qID: id }, function (result) {
            showQRating(result);
            cur.children().children().html(result.score);
            return false;
        });
    }
}

function AddToFav(qid) {
    var id = qid;
    $.post('/questions/fav', { qID: id }, function (result) {
        if (result.result == false) {
            showQRatingg(result);

        }
        else if (result.result == true) {
            if (result.votetype == 0)
                $('.addTofav').removeClass('favy').addClass('favn');
            else if (result.votetype == 1)
                $('.addTofav').removeClass('favn').addClass('favy');
            $('.favc').html(result.score);
            document.location.reload();
        }
    });
    return false;
}

function showQRatingg(result) {
    if (result.result == false) {
        if (result.reason == 'needlogin')
            showLoginn();
        else
            $("#qacterr").html(result.message).fadeIn().delay(4000).fadeOut();
    }
    else if (result.result == true) {
        $('span#qlike').html(result.score);
    }
}

Array.prototype.inArray = function (value, caseSensitive) {
    var i;
    for (i = 0; i < this.length; i++) {
        if (caseSensitive) {
            if (this[i].toLowerCase() == value.toLowerCase()) {
                return true;
            }
        } else {
            if (this[i] == value) {
                return true;
            }
        }
    }
    return false;
};

//JSON Parser
if (!this.JSON) { this.JSON = {}; }
(function () {
    function f(n) { return n < 10 ? '0' + n : n; }
    if (typeof Date.prototype.toJSON !== 'function') {
        Date.prototype.toJSON = function (key) {
            return isFinite(this.valueOf()) ? this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z' : null;
        }; String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function (key) { return this.valueOf(); };
    }
    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"': '\\"', '\\': '\\\\' }, rep; function quote(string) { escapable.lastIndex = 0; return escapable.test(string) ? '"' + string.replace(escapable, function (a) { var c = meta[a]; return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); }) + '"' : '"' + string + '"'; }
    function str(key, holder) {
        var i, k, v, length, mind = gap, partial, value = holder[key]; if (value && typeof value === 'object' && typeof value.toJSON === 'function') { value = value.toJSON(key); }
        if (typeof rep === 'function') { value = rep.call(holder, key, value); }
        switch (typeof value) {
            case 'string': return quote(value); case 'number': return isFinite(value) ? String(value) : 'null'; case 'boolean': case 'null': return String(value); case 'object': if (!value) { return 'null'; }
                gap += indent; partial = []; if (Object.prototype.toString.apply(value) === '[object Array]') {
                    length = value.length; for (i = 0; i < length; i += 1) { partial[i] = str(i, value) || 'null'; }
                    v = partial.length === 0 ? '[]' : gap ? '[\n' + gap +
partial.join(',\n' + gap) + '\n' +
mind + ']' : '[' + partial.join(',') + ']'; gap = mind; return v;
                }
                if (rep && typeof rep === 'object') { length = rep.length; for (i = 0; i < length; i += 1) { k = rep[i]; if (typeof k === 'string') { v = str(k, value); if (v) { partial.push(quote(k) + (gap ? ': ' : ':') + v); } } } } else { for (k in value) { if (Object.hasOwnProperty.call(value, k)) { v = str(k, value); if (v) { partial.push(quote(k) + (gap ? ': ' : ':') + v); } } } }
                v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
mind + '}' : '{' + partial.join(',') + '}'; gap = mind; return v;
        }
    }
    if (typeof JSON.stringify !== 'function') {
        JSON.stringify = function (value, replacer, space) {
            var i; gap = ''; indent = ''; if (typeof space === 'number') { for (i = 0; i < space; i += 1) { indent += ' '; } } else if (typeof space === 'string') { indent = space; }
            rep = replacer; if (replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) { throw new Error('JSON.stringify'); }
            return str('', { '': value });
        };
    }
    if (typeof JSON.parse !== 'function') {
        JSON.parse = function (text, reviver) {
            var j; function walk(holder, key) {
                var k, v, value = holder[key]; if (value && typeof value === 'object') { for (k in value) { if (Object.hasOwnProperty.call(value, k)) { v = walk(value, k); if (v !== undefined) { value[k] = v; } else { delete value[k]; } } } }
                return reviver.call(holder, key, value);
            }
            cx.lastIndex = 0; if (cx.test(text)) {
                text = text.replace(cx, function (a) {
                    return '\\u' +
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
                });
            }
            if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { j = eval('(' + text + ')'); return typeof reviver === 'function' ? walk({ '': j }, '') : j; }
            throw new SyntaxError('JSON.parse');
        };
    }
} ());


//Hover Intent
(function ($) { $.fn.hoverIntent = function (f, g) { var cfg = { sensitivity: 7, interval: 100, timeout: 0 }; cfg = $.extend(cfg, g ? { over: f, out: g} : f); var cX, cY, pX, pY; var track = function (ev) { cX = ev.pageX; cY = ev.pageY; }; var compare = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) { $(ob).unbind("mousemove", track); ob.hoverIntent_s = 1; return cfg.over.apply(ob, [ev]); } else { pX = cX; pY = cY; ob.hoverIntent_t = setTimeout(function () { compare(ev, ob); }, cfg.interval); } }; var delay = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); ob.hoverIntent_s = 0; return cfg.out.apply(ob, [ev]); }; var handleHover = function (e) { var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget; while (p && p != this) { try { p = p.parentNode; } catch (e) { p = this; } } if (p == this) { return false; } var ev = jQuery.extend({}, e); var ob = this; if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); } if (e.type == "mouseover") { pX = ev.pageX; pY = ev.pageY; $(ob).bind("mousemove", track); if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout(function () { compare(ev, ob); }, cfg.interval); } } else { $(ob).unbind("mousemove", track); if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout(function () { delay(ev, ob); }, cfg.timeout); } } }; return this.mouseover(handleHover).mouseout(handleHover); }; })(jQuery);

