﻿/*
* jQuery UI Notification Message
*
* Depends:
*	    ui.core.js
*/

(function($) {
    $.widget("ui.notificationmsg", {

        init: function() {
            $.ui.notificationmsg._bottompost = this.element.css("bottom");
            $.ui.notificationmsg._height = this.element.css("height");
        },

        show: function() {
            var o = this.options;
            if (this.element.is(":hidden")) {
                this.element.queue(function() { $.ui.notificationmsg.animations[o.animation](this, o); }).dequeue();
            }
        },

        hide: function() {
            this.element.stop(true);
            var o = this.options;
            if (this.element.is(":visible")) {
                this.element.queue(function() { $.ui.notificationmsg.animations[o.animation](this, o); }).dequeue();
            }
        }
    });
    $.ui.notificationmsg._bottompost = "0px";
    $.ui.notificationmsg._css;
    $.extend($.ui.notificationmsg, {
        defaults: {
            // provide a speed for the animation
            speed: 1000,
            // provide a period for the popup to keep showing
            period: 8000,
            // default the animation algorithm to the basic slide
            animation: 'slide'
        },
        animations: {
            slide: function(e, options) {
                if ($(e).is(":hidden")) {

                    //  animate
                    $anim = $(e).animate({ height: "show" }, options.speed)
   
                    if (options.period && options.period > 0) {
                        $anim.animate({ opacity: 1.0 }, options.period)
                        .animate({ height: "hide" }, options.speed);
                    }
                }
                else {
                    $(e).animate({ height: "hide" }, options.speed)
                }

                $(e).css("height", $.ui.notificationmsg._height);
            }
        }
    });
})(jQuery);

var _PageInfoCounter = 0;
var HideFromOnline = false;


function UpdatePageInfo(_my_member_id) {

  
   
    
    var PopUp_Visible = false; // FIX THIS AFTER YOU IMPLIMENT COLORBOX

    if (PopUp_Visible == false) { // FROM THICKBOX   + PageInfoCounter + "

        var animStyle = 'slide';
        Have_Email = $('div.MemberMenu .MailIcon').hasClass('Personal');

        _PageInfoCounter = _PageInfoCounter + 1;

        $.ajax({
            type: "POST",
            url: "/misc/PageAlerts.aspx/GetPageInfo",
            data: "{My_Member_ID:" + _my_member_id + ",Page_Counter:" + _PageInfoCounter + ",Have_Email:" + Have_Email + ",Hide_From_Online:" + HideFromOnline + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {

                if (msg.d.HaveFriend) {

                    $("#FriendTitle").html("Friends and Bookmarks");
                    $("#FriendBody").html(msg.d.FriendHTML);
                    $('#FriendAlerts').notificationmsg({ animation: animStyle });
                    $('#FriendAlerts').notificationmsg('show');

                } else if (!Have_Email && msg.d.HaveEmail) {

                    Have_Email = true;
                    $('div.MemberMenu .MailIcon').removeClass('Group');
                    $('div.MemberMenu .MailIcon').addClass('Personal');
                    $('div.MemberMenu .MailIcon a').attr('href', '/conversation.aspx?Pt=4');
                    
                    $('#EmailAlerts').notificationmsg({ animation: animStyle });
                    $('#EmailAlerts').notificationmsg('show');

                }


            },
            error: function(xhr, msg, e) {
                //  alert(msg);
            }
        });

    }
    if (_PageInfoCounter < 30 && (_PageInfoCounter < 6 || !Have_Email || !HideFromOnline)) {
    
        var t1 = setTimeout("UpdatePageInfo(" + _my_member_id + ")", 20 * 1000);
    }

    
}


function launchIM(to_user_id) {


    if (My_Member_ID == 0)
        alert("Need to login to chat (its free)");
    else if (HideFromOnline) 
         alert("You are currently hidden. Click on \"Voyer Mode\" to change your settings");
     else {

        $.ajax({
            type: "POST",
            url: "/misc/PageAlerts.aspx/AllowedToChat",
            data: "{My_Member_ID:" + My_Member_ID + ",Towho_ID:" + to_user_id + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
         
                switch (msg.d.Chat_Status) {
                    case 1: // COOL

                        jqcc.cometchat.chatWith(to_user_id);
                        break;
                    case 2: // OFF
                        alert("Sorry, the member's chat is not online");
                        break;
                    case 4: // FRIENDS ONLY
                        alert("Sorry, this member only accepts chats with friends");
                        break;
                    case 8: // MATCHED
                        alert("Sorry, this member only accepts chats from his/her matches");
                        break;
                }

            },
            error: function(xhr, msg, e) {
                  // alert(msg);
            }
        });
    } 
       
}