/*
This script has been edited and redone. We leave this copyright
notice only because some snippets of this script were used.
This script was redone for the use of ArcadeResort.com. If you
are interested in the script by Anant Grag, please visit his
website, as ArcadeResort.com claims copyright to some particular
functions in this file.

Plus, even if you did copy and paste this script - You don't
know the core PHP code, so you'd have no reason to do so ;)
Original copyright notice is at the end.
*/

var notifications_fade = 0;
var notifications_fade_id = 0;
var friends_icn_click_action = "";
var current_notifications_unread = 0;
function rand(l,u) {
        return Math.floor((Math.random() * (u-l+1))+l);
}
function bottomInbox() {
var inbox_icn = document.getElementById('inbox_icn_update');
        var ajaxRequest;
        try{
                ajaxRequest = new XMLHttpRequest();
        } catch (e){
                try{
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try{
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e){
                                alert("Your browser broke!");
                                return false;
                        }
                }
        }
        ajaxRequest.onreadystatechange = function(){
                if(ajaxRequest.readyState == 4){
                        var ajaxDisplay = document.getElementById('chatbar_tabpopup3_content');
                        ajaxDisplay.innerHTML = ajaxRequest.responseText;
                        var newInt = document.getElementById('inbox_new').value;
                        if(newInt == 0) {
                        inbox_icn.innerHTML = "0 new";
                        } else {
                        inbox_icn.innerHTML = "<b>"+newInt+" new</b>";
                        }
                        l('chatbar_inbox_icn','inbox',newInt);
                        inbox = setTimeout("bottomInbox()",30000);
                }
        }
        ajaxRequest.open("GET", "/community/autoUpdater.php?action=bottomInbox&"+ rand(1,100000), true);
        ajaxRequest.send(null);
}
var update_btm;
var init;
function btmBar_update(init) {
if(init == 1) {
init = 1;
} else {
init = 0;
}

$.ajax({
url: "/community/autoUpdater.php?action=btmbar_retrieveUpdates&init="+init,
cache: false,
dataType: "json",
error: function(request,error) {
//alert(request);
//alert(error);
//alert("Server connection error, could not connect to the update feed.\nRe-opening feed connection.");
btmBar_update(init);
},
success: function(data) {
if(data) {
if(init == 1) {
$('#main_notifications').html('<div id="notifications_messages_counter" onClick="mA(\'inbox\');" style="cursor:pointer;"><table border="0" width="100%"><tr><td valign="top"><img src="/images/check_inbox.png" style="width:24px;height:24px;"></td><td valign="middle"><a href="javascript:;"><span id="newMsgsNum_div">'+data.newMsgsNum+'</span> new messages - (Inbox)</a></td></tr></table></div><div id="notifications_friends_counter" onClick="mA(\'friends\');" style="cursor:pointer;"><table border="0" width="100%"><tr><td valign="top"><img src="/images/check_friends.png" style="width:24px;height:24px;"></td><td valign="middle"><a href="javascript:;"><span id="newFriendsNum_div">'+data.newFriendsNum+'</span> new friend requests - (Friends)</a></td></tr></table></div>');
$('#chatbar_tabpopup4_content').html('');
$.each(data.nOld, function(i,nOld) {
if(nOld) {
var addNotification = $('#main_notifications').html() +"<div id=\"notification_id_"+nOld.id+"\" style=\"border-top: 1px solid #EEEEEE;width: 97%;padding-bottom: 10px;text-align: left;\">"+nOld.txt+"</div>";
$('#main_notifications').html(addNotification);
}
});
if("not" == "now") {
$.each(data.favsList, function(i,favsList) {
if(favsList) {
var favsList_build = $('#chatbar_tabpopup4_content').html() +"<div style=\"padding-bottom: 10px;text-align: left;height: 32px;padding: 3px;\"><table border='0' width='100%' cellspacing='0'><tr><td valign='top' align='left' width='1%'><a href='"+favsList.url+"'><img src='/images/"+favsList.img+"' style='border:0px;height: 26px;height: 26px;'></a></td><td valign='middle' align='left' width='99%' style='padding-left: 4px;text-align: left;'><a href='"+favsList.url+"' style='font-size: 12px;'>"+favsList.name+"</a></td></tr></table></div>";
$('#chatbar_tabpopup4_content').html(favsList_build);
}
});
}
}

if(data.nNumNew != "0") {
addNotification = "";
$.each(data.nNew, function(i,nNew) {
if(nNew) {
if($('#notification_id_'+nNew.id).length < 1) {
addNotification = "<div id=\"notification_id_"+nNew.id+"\" style=\"border-top: 1px solid #EEEEEE;width: 97%;padding-bottom: 10px;text-align: left;\">"+nNew.txt+"</div>"+ addNotification;

if(data.nRec == 0) {
var doBounce = "yes";
} else {
var doBounce = "no";
}
notifications_fade = 1;
current_notifications_unread = current_notifications_unread*1 + 1;
l('chatbar_notifications_icn','notifications',data.nNumNew,doBounce);
}
}
});
if(notifications_fade == 1) {
if(notifications_fade_id == 0 || $('#notifications_fade_'+notifications_fade_id).attr('rel') == 'faded') {
notifications_fade_id = notifications_fade_id*1 + 1;
$('#main_notifications').html("<div id=\"notifications_fade_"+notifications_fade_id+"\" rel=\"unfaded\" style=\"background-color: #F6FF9B;\">"+addNotification +"</div>"+$('#main_notifications').html());
} else if($('#notifications_fade_'+notifications_fade_id).attr('rel') == 'unfaded') {
$('#notifications_fade_'+notifications_fade_id).html(addNotification + $('#notifications_fade_'+notifications_fade_id).html());
}
}
$.each(data.nAlert, function(i,nAlert) {
if(nAlert) {
$.Growl.show({
'message': nAlert.growl
});
}
});
}

if(data.nfo != "0") {
$('#friends_icn_update').html("<b>"+data.nfo+"</b>");
var update_friends = "";
$.each(data.ofl, function(i,ofl) {
if(ofl) {
friend_status_tmp = ofl.stts;
if(friend_status_tmp == "") {
friend_status_tmp = "No status written yet..";
}
update_friends = update_friends+"<div class=\"friends_chat_row\" onClick=\"a('"+ofl.uname+"','','"+ofl.pic+"','"+friend_status_tmp+"');\"><table border=\"0\" width=\"100%\" cellspacing=\"6\"><tr><td valign=\"top\" align=\"left\" width=\"1%\"><img src=\""+ofl.pic+"\" style=\"width: 20px;height: 20px;\"></td><td valign=\"middle\" align=\"left\" width=\"99%\">"+ofl.uname+" "+ofl.curr_act+"</td></td></tr></table></div>";
if($('#chatbar_chat_status_chatter-'+ofl.uname).length > 0) {
if(ofl.curr_act != "") {
$('#chatbar_chat_status_chatter-'+ofl.uname).html("<i>"+ofl.curr_act.replace('&rarr;','Playing')+"</i><br />"+friend_status_tmp);
} else {
$('#chatbar_chat_status_chatter-'+ofl.uname).html(friend_status_tmp);
}
}
}
});
$.each(data.ifl, function(i,ifl) {
if(ifl) {
friend_status_tmp = ifl.stts;
if(friend_status_tmp == "") {
friend_status_tmp = "No status written yet..";
}
update_friends = update_friends+"<div class=\"friends_chat_row\" onClick=\"a('"+ifl.uname+"','','"+ifl.pic+"','"+friend_status_tmp+"');\"><table border=\"0\" width=\"100%\" cellspacing=\"6\"><tr><td valign=\"top\" align=\"left\" width=\"1%\"><img src=\""+ifl.pic+"\" style=\"width: 20px;height: 20px;\"></td><td valign=\"middle\" align=\"left\" width=\"99%\">"+ifl.uname+" "+ifl.curr_act+"</td></td></tr></table></div>";
if($('#chatbar_chat_status_chatter-'+ifl.uname).length > 0) {
if(ifl.curr_act != "") {
$('#chatbar_chat_status_chatter-'+ifl.uname).html("<i>"+ifl.curr_act.replace('&rarr;','Playing')+"</i><br />"+friend_status_tmp);
} else {
$('#chatbar_chat_status_chatter-'+ifl.uname).html(friend_status_tmp);
}
}
}
});
$('#friends_chat').html(update_friends);
} else {
$('#friends_icn_update').html("0");
$('#friends_chat').html("<center>No online buddies available :(</center>");
}


$('#newMsgsNum_div').html(data.newMsgsNum);
$('#newFriendsNum_div').html(data.newFriendsNum);
$('#notifications_friends_counter').css('background-color','');
$('#notifications_messages_counter').css('background-color','');
$('#chatbar_notifications_icn').css('background-color','');
if(data.newMsgsNum > 0 || data.newFriendsNum > 0) {
$('#chatbar_notifications_icn').css('background-color','#FFF380');
if(data.newMsgsNum > 0) {
$('#notifications_messages_counter').css('background-color','#FFF380');
}
if(data.newFriendsNum > 0) {
$('#notifications_friends_counter').css('background-color','#FFF380');
}
}

//$('#top_exp').html(data.top_exp_html);
update_btm = setTimeout("btmBar_update(0);",5000);
}
}
});
}

function bottom_loadFeatures(mode,change,value) {
        var ajaxRequest;
        var ajaxRequest2;
        var ajaxRequest3;
        var ajaxRequest4;
        try{
                ajaxRequest = new XMLHttpRequest();
        } catch (e){
                try{
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try{
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e){
                                alert("Your browser broke!");
                                return false;
                        }
                }
        }
        try{
                ajaxRequest2 = new XMLHttpRequest();
        } catch (e){
                try{
                        ajaxRequest2 = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try{
                                ajaxRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e){
                                alert("Your browser broke!");
                                return false;
                        }
                }
        }
        try{
                ajaxRequest3 = new XMLHttpRequest();
        } catch (e){
                try{
                        ajaxRequest3 = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try{
                                ajaxRequest3 = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e){
                                alert("Your browser broke!");
                                return false;
                        }
                }
        }
        try{
                ajaxRequest4 = new XMLHttpRequest();
        } catch (e){
                try{
                        ajaxRequest4 = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try{
                                ajaxRequest4 = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e){
                                alert("Your browser broke!");
                                return false;
                        }
                }
        }
        ajaxRequest.onreadystatechange = function(){
        if(!mode) {
                if(ajaxRequest.readyState == 4){
                        var ajaxDisplay = document.getElementById('chatbar_tabpopup4_content');
                        ajaxDisplay.innerHTML = ajaxRequest.responseText;
                }
        } else if(mode == "edit_subscriptions") {
                if(ajaxRequest.readyState == 4){
                        var ajaxDisplay = document.getElementById('td_'+change);
                        ajaxDisplay.innerHTML = ajaxRequest.responseText;
                }
        } else if(mode == "get_notifications") {
                if(ajaxRequest.readyState == 4) {
                        var ajaxDisplay = document.getElementById('main_notifications');
                        ajaxDisplay.innerHTML = ajaxRequest.responseText;
                        var notifications_new = document.getElementById('notifications_new').value;
                        if(notifications_new > 0) {
                        if(document.getElementById('notifications_received').value == 0) {
                        var doBounce = "yes";
                        } else {
                        var doBounce = "no";
                        }
                        l('chatbar_notifications_icn','notifications',notifications_new,doBounce);
                        notifications_fade = 1;
                        }
                        notifications_timer = setTimeout("bottom_loadFeatures('get_notifications')",10000);
        }
        } else if(mode == "friends_chat") {
                        if(ajaxRequest.readyState == 4){
                        var ajaxDisplay = document.getElementById('friends_chat');
                        ajaxDisplay.innerHTML = ajaxRequest.responseText;
                        var friends_chat_num = document.getElementById('friends_chat_num').value;
                        if(friends_chat_num > 0) {
                        document.getElementById('friends_icn_update').innerHTML = "<b>"+ friends_chat_num +"</b>";
                        } else{
                        document.getElementById('friends_icn_update').innerHTML = "0";
                        }
                        var friends_chat_timer = setTimeout("bottom_loadFeatures('friends_chat')",3000);
                        if($('#chatbar_tabpopup2').css('display') == "block") {
                        friends_icn_click_action = "refresh";
                        $('#chatbar_friends_icn').click();
                        }
                        $('.friends_chat_row').hover(
                                function(){
                                        $(this).addClass('friends_chat_row_over');
                                },
                                function(){
                                        $(this).removeClass('friends_chat_row_over');
                                }
                        );
                }
        }
        }
        ajaxRequest2.onreadystatechange = function(){
        if(!mode) {
                if(ajaxRequest2.readyState == 4){
                        var ajaxDisplay2 = document.getElementById('edit_subscriptions_body');
                        ajaxDisplay2.innerHTML = ajaxRequest2.responseText;
                }
        }
        }
        ajaxRequest3.onreadystatechange = function(){
        if(!mode) {
                if(ajaxRequest3.readyState == 4){
                        var ajaxDisplay3 = document.getElementById('main_notifications');
                        ajaxDisplay3.innerHTML = ajaxRequest3.responseText;
                        var notifications_new = document.getElementById('notifications_new').value;
                        if(notifications_new > 0) {
                        l('chatbar_notifications_icn','notifications',notifications_new);
                        notifications_fade = 1;
                        }
                        notifications_timer = setTimeout("bottom_loadFeatures('get_notifications')",5000);
                }
        }
        }
                ajaxRequest4.onreadystatechange = function(){
        if(!mode) {
                if(ajaxRequest4.readyState == 4){
                        var ajaxDisplay4 = document.getElementById('friends_chat');
                        ajaxDisplay4.innerHTML = ajaxRequest4.responseText;
                        var friends_chat_num = document.getElementById('friends_chat_num').value;
                        if(friends_chat_num > 0) {
                        document.getElementById('friends_icn_update').innerHTML = "<b>"+ friends_chat_num +"</b>";
                        } else{
                        document.getElementById('friends_icn_update').innerHTML = "0";
                        }
                        if($('#chatbar_tabpopup2').css('display') == "block") {
                        friends_icn_click_action = "refresh";
                        $('#chatbar_friends_icn').click();
                        }
                        var friends_chat_timer = setTimeout("bottom_loadFeatures('friends_chat')",3000);
                        $('.friends_chat_row').hover(
                                function(){
                                        $(this).addClass('friends_chat_row_over');
                                },
                                function(){
                                        $(this).removeClass('friends_chat_row_over');
                                }
                        );
                }
        }
        }
if(!mode) {
        ajaxRequest.open("GET", "/community/autoUpdater.php?action=bottomFavGames&"+ rand(1,100000), true);
        ajaxRequest.send(null);
        ajaxRequest2.open("GET", "/community/autoUpdater.php?action=load_subscriptions&"+ rand(1,100000), true);
        ajaxRequest2.send(null);
        ajaxRequest3.open("GET", "/community/autoUpdater.php?action=get_notifications&"+ rand(1,100000), true);
        ajaxRequest3.send(null);
        ajaxRequest4.open("GET", "/community/autoUpdater.php?action=friends_chat&"+ rand(1,100000), true);
        ajaxRequest4.send(null);
} else if(mode == "edit_subscriptions") {
        document.getElementById('td_'+change).innerHTML = "<img src=\"/images/chat_icon_sending.gif\" style=\"height: 16px;width: 16px;\">";
        ajaxRequest.open("GET", "/community/autoUpdater.php?action=edit_subscriptions&change="+ change +"&value="+ value +"&"+ rand(1,100000), true);
        ajaxRequest.send(null);
} else if(mode == "get_notifications") {
        ajaxRequest.open("GET", "/community/autoUpdater.php?action=get_notifications&"+ rand(1,100000), true);
        ajaxRequest.send(null);
} else if(mode == "friends_chat") {
        ajaxRequest.open("GET", "/community/autoUpdater.php?action=friends_chat&"+ rand(1,100000), true);
        ajaxRequest.send(null);

}
}

$(document).ready(function() {
 $('#chatbar_notifications_iw').click(function(){
   $("#growlcontainer").html('');
  if($(this).hasClass('chatbar_icn2_click')){
   $('#chatbar_tabpopup').hide();
   $(this).removeClass('chatbar_icn2_click');
   if($(this).mouseover) {
    $(this).addClass('chatbar_icn2_over');
   }
   } else {
    var icnPos = $(this).offset();
    var icnWidth = parseInt($(this).width());
    var icnHeight = parseInt($(this).height());
    var winWidth = parseInt($('#chatbar_tabpopup').width());
    var winHeight = parseInt($('#chatbar_tabpopup').height());
    posLeft = icnPos.left + icnWidth - winWidth + 2 +"px";
    posTop = $(window).height() -  winHeight - 1 - icnHeight +"px";
    $('#chatbar_tabpopup').css('left',posLeft);
    $('#chatbar_tabpopup').css('top',posTop);
    $(this).addClass('chatbar_icn2_click');
    $('#chatbar_tabpopup2').hide();
    $('#chatbar_tabpopup3').hide();
    $('#chatbar_tabpopup4').hide();
    $('#chatbar_friends_iw').removeClass('chatbar_icn1_click');
    $('#chatbar_friends_iw').mouseout();
    $('#chatbar_inbox_iw').removeClass('chatbar_icn4_click');
    $('#chatbar_inbox_iw').mouseout();
    $('#chatbar_favgames_iw').removeClass('chatbar_icn3_click');
    $('#chatbar_favgames_iw').mouseout();
    $('#chatbar_tabpopup').show();
    if(notifications_fade > 0) {
    $('#new_notifications_div').animate({backgroundColor:'#FFFFFF'},3000);
    l('chatbar_notifications_icn','','0');
    notifications_fade = 0;
    $.post("/community/autoUpdater.php?action=read_notifications",{},function(data){
    });
    }
   }
 });
 $('#chatbar_notifications_icn').mouseout(function(){
  if(!$(this).hasClass('chatbar_icn2_click')){
   $(this).removeClass('chatbar_icn2_over');
  }
 });
 $('#chatbar_notifications_icn').mouseover(function(){
  if(!$(this).hasClass('chatbar_icon2_click')){
   $(this).addClass('chatbar_icn2_over');
  }
 });
 $('#chatbar_friends_iw').click(function(){
  if($(this).hasClass('chatbar_icn1_click') && friends_icn_click_action != "refresh"){
   $('#chatbar_tabpopup2').hide();
   $(this).removeClass('chatbar_icn1_click');
   if($(this).mouseover) {
    $(this).addClass('chatbar_icn1_over');
   }
   } else {
    var icnPos = $(this).offset();
    var icnWidth = parseInt($(this).width());
    var icnHeight = parseInt($(this).height());
    var winWidth = parseInt($('#chatbar_tabpopup2').width());
    var winHeight = parseInt($('#chatbar_tabpopup2').height());
    posLeft = icnPos.left+"px";
    posTop = $(window).height() -  winHeight - 1 - icnHeight +"px";
    $('#chatbar_tabpopup2').css('left',posLeft);
    $('#chatbar_tabpopup2').css('top',posTop);
    $(this).addClass('chatbar_icn1_click');
    $('#chatbar_tabpopup').hide();
    $('#chatbar_tabpopup3').hide();
    $('#chatbar_tabpopup4').hide();
    $('#chatbar_favgames_iw').removeClass('chatbar_icn3_click');
    $('#chatbar_favgames_iw').mouseout();
    $('#chatbar_inbox_iw').removeClass('chatbar_icn4_click');
    $('#chatbar_inbox_iw').mouseout();
    $('#chatbar_notifications_iw').removeClass('chatbar_icn2_click');
    $('#chatbar_notifications_iw').mouseout();
    $('#chatbar_tabpopup2').show();
   }
   friends_icn_click_action = "";
 });
  $('#chatbar_friends_iw').mouseout(function(){
   if(!$(this).hasClass('chatbar_icn1_click')){
    $(this).removeClass('chatbar_icn1_over');
   }
  });
  $('#chatbar_friends_iw').mouseover(function(){
  if(!$(this).hasClass('chatbar_icn1_click')){
   $(this).addClass('chatbar_icn1_over');
  }
 });

 $('#chatbar_inbox_iw').click(function(){
  mA('inbox');
  /*
  if($(this).hasClass('chatbar_icn4_click')){
   $('#chatbar_tabpopup3').hide();
   $(this).removeClass('chatbar_icn4_click');
   //inbox = setTimeout("bottomInbox()",30000);
   if($(this).mouseover) {
    $(this).addClass('chatbar_icn4_over');
   }
   } else {
    //clearTimeout(inbox);
    var icnPos = $(this).offset();
    var icnWidth = parseInt($(this).width());
    var icnHeight = parseInt($(this).height());
    var winWidth = parseInt($('#chatbar_tabpopup3').width());
    var winHeight = parseInt($('#chatbar_tabpopup3').height());
    posLeft = icnPos.left +"px";
    posTop = $(window).height() -  winHeight - 1 - icnHeight +"px";
    $('#chatbar_tabpopup3').css('left',posLeft);
    $('#chatbar_tabpopup3').css('top',posTop);
    $(this).addClass('chatbar_inbox_icn_click');
    $('#chatbar_tabpopup').hide();
    $('#chatbar_tabpopup2').hide();
    $('#chatbar_tabpopup3').hide();
    $('#chatbar_friends_iw').removeClass('chatbar_icn1_click');
    $('#chatbar_friends_iw').mouseout();
    $('#chatbar_favgames_iw').removeClass('chatbar_icn3_click');
    $('#chatbar_favgames_iw').mouseout();
    $('#chatbar_notifications_iw').removeClass('chatbar_icn2_click');
    $('#chatbar_notifications_iw').mouseout();
    $('#chatbar_tabpopup3').show();
   }
  */
 });
 $('#chatbar_inbox_iw').mouseout(function(){
  if(!$(this).hasClass('chatbar_icn4_click')){
   $(this).removeClass('chatbar_icn4_over');
  }
 });
 $('#chatbar_inbox_iw').mouseover(function(){
  if(!$(this).hasClass('chatbar_icn4_click')){
   $(this).addClass('chatbar_icn4_over');
  }
 });

 $('#chatbar_favgames_iw').click(function(){
  if($(this).hasClass('chatbar_icn3_click')){
   $('#chatbar_tabpopup3').hide();
   $(this).removeClass('chatbar_icn3_click');
   if($(this).mouseover) {
    $(this).addClass('chatbar_icn3_over');
   }
   } else {
    var icnPos = $(this).offset();
    var icnWidth = parseInt($(this).width());
    var icnHeight = parseInt($(this).height());
    var winWidth = parseInt($('#chatbar_tabpopup4').width());
    var winHeight = parseInt($('#chatbar_tabpopup4').height());
    posLeft = icnPos.left - winWidth + icnWidth + 29 +"px";
    posTop = $(window).height() -  winHeight - 1 - icnHeight +"px";
    $('#chatbar_tabpopup4').css('left',posLeft);
    $('#chatbar_tabpopup4').css('top',posTop);
    $(this).addClass('chatbar_icn3_click');
    $('#chatbar_tabpopup4').hide();
    $('#chatbar_tabpopup2').hide();
    $('#chatbar_tabpopup').hide();
    $('#chatbar_friends_iw').removeClass('chatbar_icn1_click');
    $('#chatbar_friends_iw').mouseout();
    $('#chatbar_inbox_iw').removeClass('chatbar_icn4_click');
    $('#chatbar_inbox_iw').mouseout();
    $('#chatbar_notifications_iw').removeClass('chatbar_icn2_click');
    $('#chatbar_notifications_iw').mouseout();
    $('#chatbar_tabpopup3').show();
   }
 });
 $('#chatbar_favgames_iw').mouseout(function(){
  if(!$(this).hasClass('chatbar_icn3_click')){
   $(this).removeClass('chatbar_icn3_over');
  }
 });
 $('#chatbar_favgames_iw').mouseover(function(){
  if(!$(this).hasClass('chatbar_icn3_click')){
   $(this).addClass('chatbar_icn3_over');
  }
 });
 $('#chatbar_chats_left').click(function(){
 if($.cookie('chatboxes_left') > 0) {
   d('left');
  }
 });
 $('#chatbar_chats_right').click(function(){
 if($.cookie('chatboxes_right') > 0) {
   d('right');
  }
 });
 originalTitle = document.title;
 $([window, document]).blur(function(){
 if(idle == false && username) {
  idleCheck = setTimeout("updateIdle('idle')", 10000);
  idleTiming = true;
 }
  idle = true;
  windowFocus = false;
 }).focus(function(){
  if(idle == true && username) {
  idle = false;
  updateIdle('active');
   if(idleTiming) {
    clearTimeout(idleCheck);
    idleTiming = false;
   }
  }
  windowFocus = true;
  document.title = originalTitle;
 });
});
var windowFocus = true;
var idle = false;
var idleCheck;
var idleTiming;
var username;
var opened;
var chatHeartbeatCount = 0;
var minChatHeartbeat = 1;
var maxChatHeartbeat = 3300000;
var chatHeartbeatTime = minChatHeartbeat;
var originalTitle;
var blinkOrder = 0;

var chatboxFocus = new Array();
var newMessages = new Array();
var newMessagesWin = new Array();
var chatBoxes = new Array();
var chatBoxes = new Array();
var visibleLimit = 4;
var busy = 0;
var recentSent = 0;
var chatHistory_buildUp = "";
var last_ar_chat_message = 0;
trackSent = new Array();
trackDone = new Array();
trackMsg = new Array();
trackTo = new Array();
newAlert_num = new Array();
sendQueue = new Array();
lastFrom = new Array();
userOpt_out = new Array();
var idleTimer_timeout;
var idleTimer_status = 0;
var currently_idle = 0;
/*
$('body').mouseover(function() {
if(idleTimer_status == 1) {
clearTimeout(idleTimer_timeout);
idletimer_status = 0;
}
if(currently_idle == 1) {
updateIdle('active');
currently_idle = 0;
}
idleTimer_timeout = setTimeout("updateIdle('idle');",10000);
idleTimer_status = 1;
});
*/
function updateIdle(m) {
        idleTiming = false;
        if(idleTimer_status == 1) {
                clearTimeout(idleTimer_timeout);
                idleTimer_status = 0;
        }
        if(m == 'idle') {
                currently_idle = 1;
        }
        $.post("/community/autoUpdater.php?action=updateIdle&"+ rand(1,100000), {mode: m} , function(data){
        });
}
function removeByElement(arrayName,arrayElement) {
    for(var i=0; i<arrayName.length;i++ )
     {
        if(arrayName[i]==arrayElement)
            arrayName.splice(i,1);
      }
}
function userOpt_hide(chatboxtitle) {
        if($('#chat_userOpt_'+chatboxtitle).css('display') == "block") {
                $('#chat_userOpt_'+chatboxtitle).css('display','none');
                clearTimeout(userOpt_out[chatboxtitle]);
        }
}
function a(chatboxtitle,mode,p_url,user_status) {
if(mode == "initialize") {
        if($('#chatbox_chat_foot_'+chatboxtitle).length == 0 && busy == 0) {
        $("#chatbar_chats_tr").append('<td id="chat_td_'+chatboxtitle+'" class="chatbar_chats_td"><div id="chatbox_chat_foot_'+chatboxtitle+'" class="chatbar_chat_foot" onClick="h(\''+chatboxtitle+'\');"><table border="0" width="100%" cellspacing="0"><tr><td valign="middle" align="left" width="15%"><img src="/images/chatbar_convo_icon.png" style="margin-left: -5px;padding-right:5px;height:18px;width:18px;"></td><td valign="top" align="left" width="70%"><div style="width: 100px;over-flow: hidden;"><a style="display: block;" style="color: #FFFFFF;">'+chatboxtitle+'</a></div></td><td valign="top" align="left" width="5%"><div class="chatbar_chat_foot_close"><span style="cursor:pointer;" onClick="m(\''+chatboxtitle+'\');"><b>x</b></span></span></div></td></tr></table></div></td>');
        $(" <div />" ).attr("id","chatbox_chat_body_"+chatboxtitle)
        .addClass("chatbar_chat_box")
        .html('<div class="chatbar_chat_head"><div class="chatbar_chat_title"><table border="0" width="100%"><tr><td valign="top" width="98%" align="left"><div class="chatbar_chat_username"><a href="/users/'+chatboxtitle+'/">'+chatboxtitle+'</a></td><td valign="top" align="right" width="1%"><span style="cursor:pointer;" onClick="h(\''+chatboxtitle+'\');"><b>--</b></span>&nbsp;&nbsp;</td><td valign="top" align="right" width="1%"><span style="cursor:pointer;" onClick="m(\''+chatboxtitle+'\');"><b>x</b></span>&nbsp;&nbsp;&nbsp;</td></tr></table></div></div></div><div class="chatbar_chat_bodywrap"><div class="chatbar_chat_body"><div class="chatbar_chat_user_status_block"><table border="0" width="100%" cellspacing="2"><tr><td valign="top" align="left" width="1%"><div class="chatbar_chat_userimage"><img src="'+p_url+'"></div><div class="chatbar_chat_userOpt" onMouseover="this.style.backgroundColor=\'#CECECE\';" onMouseout="this.style.backgroundColor=\'#DDDDDD\';"></div><div id="chat_userOpt_'+chatboxtitle+'" class="chatbar_chat_userOpt_list"><ul><li><a href="/users/'+chatboxtitle+'/">View Profile</a></li><li><a href="javascript:;" class="chat_userOpt_sharePage">Share This Page</a></li><li><a href="javascript:;" onClick="ech(\''+chatboxtitle+'\');">Clear Chat History</a></li></ul></div></td><td valign="top" align="left" width="99%"><div id="chatbar_chat_status_chatter-'+chatboxtitle+'" class="chatbar_chat_status">'+user_status+'</div></td></tr></table><div style="border-left: 1px solid #000000;border-right: 1px solid #000000;background-color: #EEEEEE;"><div class="chatbar_chat_head_bottom"></div></div></div><div class="chatbar_chat_main_content"><div class="chatboxcontent"></div><div class="chatboxinput"><textarea class="chatboxtextarea" onkeydown="return ci(this,event,\''+chatboxtitle+'\');"></textarea></div></div></div>')
        .appendTo($("body"));
        $("#chatbox_chat_body_"+chatboxtitle+" .chatbar_chat_userOpt, #chatbox_chat_body_"+chatboxtitle+" .chatbar_chat_userimage, ").click(function(){
        if($('#chat_userOpt_'+chatboxtitle).css('display') == "none") {
        $('#chat_userOpt_'+chatboxtitle).css('display','block');
        } else {
        $('#chat_userOpt_'+chatboxtitle).css('display','none');
        }
        return false;
        });
        $('#chat_userOpt_'+chatboxtitle).mouseover(function(){
        clearTimeout(userOpt_out[chatboxtitle]);
        }).mouseout(function(){
        userOpt_out[chatboxtitle] = setTimeout("userOpt_hide('"+chatboxtitle+"');",1000);
        });
        $("#chatbox_chat_body_"+chatboxtitle+" .chat_userOpt_sharePage").click(function(){
        $('#chat_userOpt_'+chatboxtitle).css('display','none');
        var chatboxTextarea_currentUserInput_preserve = $("#chatbox_chat_body_"+chatboxtitle+" .chatboxtextarea").val();
        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxtextarea").val('[SharePage] '+window.location.href);
        var chatboxTextarea_locateElement = '#chatbox_chat_body_'+chatboxtitle+' .chatboxtextarea';
        ci(chatboxTextarea_locateElement,'',chatboxtitle,'1');
        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxtextarea").val(chatboxTextarea_currentUserInput_preserve);
        });
        
        
        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxtextarea").blur(function(){
        chatboxFocus[chatboxtitle] = false;
        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxtextarea").removeClass('chatboxtextareaselected');
        }).focus(function(){
        chatboxFocus[chatboxtitle] = true;
        newMessages[chatboxtitle] = false;
        $("#chatbox_chat_foot_"+chatboxtitle+" .chatboxtextarea").addClass('chatboxtextareaselected');
        });
        $('#chatbox_chat_foot_'+chatboxtitle).mouseover(function(){
        if(!$('#chatbox_chat_foot_'+chatboxtitle).hasClass('chatbar_chat_foot_open')) {
        $('#chatbox_chat_foot_'+chatboxtitle).addClass('chatbar_chat_foot_over');
        }
        }).mouseout(function(){
        if($('#chatbox_chat_foot_'+chatboxtitle).hasClass('chatbar_chat_foot_over') && !$('#chatbox_chat_foot_'+chatboxtitle).hasClass('chatbar_chat_foot_open')) {
        $('#chatbox_chat_foot_'+chatboxtitle).removeClass('chatbar_chat_foot_over');
        }
        });
        chatBoxes.unshift(chatboxtitle);
        //b('silent_create',chatboxtitle);
        newAlert_num[chatboxtitle] = 0;
        $('#chatbox_chat_body_'+chatboxtitle).css('display','none');
        }
                        $.ajax({
                        url: "/IM/ar_chat.php?action=sendchat&to="+chatboxtitle+"&mode=create&"+ rand(1,100000),
                        cache: false,
                        dataType: "json",
                        success: function(data) {
                        $.each(data.response, function(i,response){
                        if (response) {
                        if(response.r != 2) {
                                $("#chatbox_chat_body_"+chatboxtitle+" .chatbar_chat_userimage").html('<a href="/users/'+chatboxtitle+'/"><img src="'+response.p+'"></a>');
                                //$("#chatbox_chat_body_"+chatboxtitle+" .chatbar_chat_status").html(response.status);
                        }
                        if(response.r == "1") {

                        } else if(response.r == "2") {
                                $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatbox_error">This user does not exist.</div>');
                        } else if(response.r == "3") {
                                $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatbox_error">You must be friends with this user to chat with them.<br /><a href="javascript:;" onClick="sendRequest(\''+response.i+'\',\'verify\',\''+chatboxtitle+'\');">Click here</a> to send them a friend request.</div>');
                        } else if(response.r == "4") {
                                $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatbox_error"><a href="/users/'+chatboxtitle+'/">'+ chatboxtitle +'</a> is currently offline.<br /><a href="javascript:;" onClick="mA(\'composeMessage\',\''+response.i+'\');">Click here</a> to send message.</div>');
                        }
                                $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").scrollTop(10000000);
                        }
                        });
                        }
                        });
} else {
        if($('#chatbox_chat_foot_'+chatboxtitle).length == 0 && busy == 0) {
        $("#chatbar_chats_tr").append('<td id="chat_td_'+chatboxtitle+'" class="chatbar_chats_td"><div id="chatbox_chat_foot_'+chatboxtitle+'" class="chatbar_chat_foot" onClick="h(\''+chatboxtitle+'\');"><table border="0" width="100%" cellspacing="0"><tr><td valign="middle" align="left" width="15%"><img src="/images/chatbar_convo_icon.png" style="margin-left: -5px;padding-right:5px;height:18px;width:18px;"></td><td valign="top" align="left" width="70%"><div style="width: 100px;over-flow: hidden;"><a style="display: block;" style="color: #FFFFFF;">'+chatboxtitle+'</a></div></td><td valign="top" align="left" width="5%"><div class="chatbar_chat_foot_close"><span style="cursor:pointer;" onClick="m(\''+chatboxtitle+'\');"><b>x</b></span></span></div></td></tr></table></div></td>');
        $(" <div />" ).attr("id","chatbox_chat_body_"+chatboxtitle)
        .addClass("chatbar_chat_box")
        .html('<div class="chatbar_chat_head"><div class="chatbar_chat_title"><table border="0" width="100%"><tr><td valign="top" width="98%" align="left"><div class="chatbar_chat_username"><a href="/users/'+chatboxtitle+'/">'+chatboxtitle+'</a></td><td valign="top" align="right" width="1%"><span style="cursor:pointer;" onClick="h(\''+chatboxtitle+'\');"><b>--</b></span>&nbsp;&nbsp;</td><td valign="top" align="right" width="1%"><span style="cursor:pointer;" onClick="m(\''+chatboxtitle+'\');"><b>x</b></span>&nbsp;&nbsp;&nbsp;</td></tr></table></div></div></div><div class="chatbar_chat_bodywrap"><div class="chatbar_chat_body"><div class="chatbar_chat_user_status_block"><table border="0" width="100%" cellspacing="2"><tr><td valign="top" align="left" width="1%"><div class="chatbar_chat_userimage"><img src="'+p_url+'"></div><div class="chatbar_chat_userOpt" onMouseover="this.style.backgroundColor=\'#CECECE\';" onMouseout="this.style.backgroundColor=\'#DDDDDD\';"></div><div id="chat_userOpt_'+chatboxtitle+'" class="chatbar_chat_userOpt_list"><ul><li><a href="/users/'+chatboxtitle+'/">View Profile</a></li><li><a href="javascript:;" class="chat_userOpt_sharePage">Share This Page</a></li><li><a href="javascript:;" onClick="ech(\''+chatboxtitle+'\');">Clear Chat History</a></li></ul></div></td><td valign="top" align="left" width="99%"><div id="chatbar_chat_status_chatter-'+chatboxtitle+'" class="chatbar_chat_status">'+user_status+'</div></td></tr></table><div style="border-left: 1px solid #000000;border-right: 1px solid #000000;background-color: #EEEEEE;"><div class="chatbar_chat_head_bottom"></div></div></div><div class="chatbar_chat_main_content"><div class="chatboxcontent"></div><div class="chatboxinput"><textarea class="chatboxtextarea" onkeydown="return ci(this,event,\''+chatboxtitle+'\');"></textarea></div></div></div>')
        .appendTo($("body"));
        $("#chatbox_chat_body_"+chatboxtitle+" .chatbar_chat_userOpt, #chatbox_chat_body_"+chatboxtitle+" .chatbar_chat_userimage, ").click(function(){
        if($('#chat_userOpt_'+chatboxtitle).css('display') == "none") {
        $('#chat_userOpt_'+chatboxtitle).css('display','block');
        } else {
        $('#chat_userOpt_'+chatboxtitle).css('display','none');
        }
        return false;
        });
        $('#chat_userOpt_'+chatboxtitle).mouseover(function(){
        clearTimeout(userOpt_out[chatboxtitle]);
        }).mouseout(function(){
        userOpt_out[chatboxtitle] = setTimeout("userOpt_hide('"+chatboxtitle+"');",1000);
        });
        $("#chatbox_chat_body_"+chatboxtitle+" .chat_userOpt_sharePage").click(function(){
        $('#chat_userOpt_'+chatboxtitle).css('display','none');
        var chatboxTextarea_currentUserInput_preserve = $("#chatbox_chat_body_"+chatboxtitle+" .chatboxtextarea").val();
        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxtextarea").val('[SharePage] '+window.location.href);
        var chatboxTextarea_locateElement = '#chatbox_chat_body_'+chatboxtitle+' .chatboxtextarea';
        ci(chatboxTextarea_locateElement,'',chatboxtitle,'1');
        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxtextarea").val(chatboxTextarea_currentUserInput_preserve);
        });
        
        $("#chatbox_chat_body_"+chatboxtitle+" .chatbar_chat_userimage").html('<a href="/users/'+chatboxtitle+'/"><img src="'+p_url+'"></a>');
        $("#chatbox_chat_body_"+chatboxtitle+" .chatbar_chat_status").html(user_status);
        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxtextarea").blur(function(){
        chatboxFocus[chatboxtitle] = false;
        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxtextarea").removeClass('chatboxtextareaselected');
        }).focus(function(){
        chatboxFocus[chatboxtitle] = true;
        newMessages[chatboxtitle] = false;
        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxtextarea").addClass('chatboxtextareaselected');
        });
        $('#chatbox_chat_foot_'+chatboxtitle).mouseover(function(){
        if(!$('#chatbox_chat_foot_'+chatboxtitle).hasClass('chatbar_chat_foot_open')) {
        $('#chatbox_chat_foot_'+chatboxtitle).addClass('chatbar_chat_foot_over');
        }
        }).mouseout(function(){
        if($('#chatbox_chat_foot_'+chatboxtitle).hasClass('chatbar_chat_foot_over') && !$('#chatbox_chat_foot_'+chatboxtitle).hasClass('chatbar_chat_foot_open')) {
        $('#chatbox_chat_foot_'+chatboxtitle).removeClass('chatbar_chat_foot_over');
        }
        });
                        $.ajax({
                        url: "/IM/ar_chat.php?action=sendchat&to="+chatboxtitle+"&mode=create&"+ rand(1,100000),
                        cache: false,
                        dataType: "json",
                        success: function(data) {
                        $.each(data.response, function(i,response){
                        if (response) {
                        var intialChat_html = "";
                        $.each(response.h, function(i,h) {
                                if(lastFrom[chatboxtitle] == h.f) {
                                        if(h.f == h.c) {
                                                var chatHistory_buildUp = chatHistory_buildUp +'<div class="chatboxmessage"><span class="chatboxmessagecontent">'+h.m+'</span></div>';
                                        } else {
                                                var chatHistory_buildUp = chatHistory_buildUp +'<div class="chatboxmessage"><span class="chatboxmessagecontent">'+h.m+'</span></div>';
                                        }
                                } else {
                                        if(h.f == h.c) {
                                                var chatHistory_buildUp = chatHistory_buildUp +'<div class="chatboxmessage"><span class="chatboxmessagefrom"><a href="/users/'+h.f+'/" style="color: #0000FF;">'+h.f+'</a>:&nbsp;&nbsp;</span><br /><span class="chatboxmessagecontent">'+h.m+'</span></div>';
                                        } else {
                                                var chatHistory_buildUp = chatHistory_buildUp +'<div class="chatboxmessage"><span class="chatboxmessagefrom2">'+h.f+':&nbsp;&nbsp;</span><br /><span class="chatboxmessagecontent">'+h.m+'</span></div>';
                                        }
                        }
                        lastFrom[chatboxtitle] = h.f;
                        });

                        chatHistory_buildUp = chatHistory_buildUp.replace('undefined','');

                        initialChat_html = $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").html();

                        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").html(chatHistory_buildUp + initialChat_html);

                        if(response.r != 2) {
                                $("#chatbox_chat_body_"+chatboxtitle+" .chatbar_chat_userimage").html('<a href="/users/'+chatboxtitle+'/"><img src="'+response.p+'"></a>');
                                //$("#chatbox_chat_body_"+chatboxtitle+" .chatbar_chat_status").html(response.status);
                        }
                        if(response.r == "1") {
                        //Success :)
                        } else if(response.r == "2") {
                                $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatbox_error">This user does not exist.</div>');
                        } else if(response.r == "3") {
                                $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatbox_error">You must be friends with this user to chat with them.<br /><a href="javascript:;" onClick="sendRequest(\''+response.i+'\',\'verify\',\''+chatboxtitle+'\');">Click here</a> to send them a friend request.</div>');
                        } else if(response.r == "4") {
                                $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatbox_error"><a href="/users/'+chatboxtitle+'/">'+ chatboxtitle +'</a> is currently offline.<br /><a href="javascript:;" onClick="mA(\'composeMessage\',\''+response.i+'\');">Click here</a> to send message.</div>');
                        }
                                $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").scrollTop(10000000);
                        }
                        });
                        }
                        });
        chatBoxes.unshift(chatboxtitle);
        newAlert_num[chatboxtitle] = 0;
        b('create',chatboxtitle);
        } else if($('#chatbox_chat_body_'+chatboxtitle).css('display') == "none" && busy == 0) {
        $('#chatbox_chat_body_'+chatboxtitle).css('display','block');
        b('goto',chatboxtitle);
        //chatBoxes.unshift(chatboxtitle);
        //b('create',chatboxtitle);
        } else {
                if(busy == 0) {
                        b('goto',chatboxtitle);
                }
        }
}

        lastFrom[chatboxtitle] = "";
}
function b(type,chatboxtitle) {
        if($('#chatbox_chat_foot_'+chatboxtitle).css('display') == 'block') {
                for(x in chatBoxes) {
                        if(chatBoxes[x] != chatboxtitle) {
                        $('#chatbox_chat_body_'+chatBoxes[x]).css('display','none');
                        $('#chatbox_chat_foot_'+chatBoxes[x]).removeClass('chatbar_chat_foot_opened');
                        }
        }
        d(type,chatboxtitle);
        }
}
function c(chatboxtitle) {
        chatFoot = $("#chatbox_chat_foot_"+chatboxtitle);
        chatBody = $("#chatbox_chat_body_"+chatboxtitle);
        chatBodyLeft = parseInt(chatFoot.offset().left - (chatBody.width() - chatFoot.width())) + 10 +"px";
        chatBody.css('left',chatBodyLeft);
        $('#chatbox_chat_foot_'+chatboxtitle).addClass('chatbar_chat_foot_opened');

        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxtextarea").focus();
        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").scrollTop(10000000000);
        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").scrollLeft(0);
        $.cookie('chatbox_opened',chatboxtitle);
        if(newAlert_num[chatboxtitle] != 0) {
                newAlert_num[chatboxtitle] = 0;
        }
        $.post("/IM/ar_chat.php?action=chatread&"+ rand(1,100000), { chatbox: chatboxtitle} , function(data){
        });
        busy = 0;
        d('refresh_arrows');
}
function d(type,chatboxtitle) {
//N();
left = parseInt($.cookie('chatboxes_left'));
right = parseInt($.cookie('chatboxes_right'));
if(left == null || !left) {
left = 0;
}
if(right == null || !right) {
right = 0;
}
var checkLimit1 = right+visibleLimit;
var checkLimit2 = chatBoxes.length - visibleLimit - left;
pos=0;
for(x in chatBoxes) {
var chatboxtitleID = chatBoxes[x];
pos++;
$.cookie('chatbox_'+ chatboxtitleID, pos);
}
var chatPos = $.cookie('chatbox_'+chatboxtitle);
if(type == "goto") {
if(chatPos > checkLimit1) {
howFarLeft = chatPos - checkLimit1;
var mode = "right";
oldLeft = left;
left = chatBoxes.length - checkLimit1 - howFarLeft;
right = chatBoxes.length - visibleLimit - left;
scrollAmt = left*132;
$('#chatbar_chats').scrollTo(scrollAmt,0,{duration:750,onAfter:function(){c(chatboxtitle);d('refresh_arrows');}});
} else if(chatPos <= checkLimit2) {
howFarRight = right - chatPos;
var mode = "left";
oldRight = right;
right = chatPos - 1;
left = chatBoxes.length - visibleLimit - right;
scrollAmt = left*132;
$('#chatbar_chats').scrollTo(scrollAmt,0,{duration:750,onAfter:function(){c(chatboxtitle);d('refresh_arrows');}});
} else {
c(chatboxtitle);
}
} else if(type == "create"|| type == "silent_create") {
d('refresh_arrows');
left = chatBoxes.length - visibleLimit;
right = 0;
scrollAmt = left*132;
if(chatBoxes.length > visibleLimit) {
if(type == "create") {
$('#chatbar_chats').scrollTo(scrollAmt,0,{duration:750,onAfter:function(){c(chatboxtitle);d('refresh_arrows');}});
} else if(type == "silent_create") {
$('#chatbar_chats').scrollTo(scrollAmt,0,{duration:750,onAfter:function(){d('refresh_arrows');}});
}
} else {
c(chatboxtitle);
}
} else if(type == "right") {
if(chatBoxes.length > (visibleLimit+left)) {
chatboxtitle = e();
g();
busy = 1;
left++;
right = right-1;
scrollAmt = left*132;
$('#chatbar_chats').scrollTo(scrollAmt,0,{duration:750,onAfter:function(){busy=0;f(chatboxtitle);d('refresh_arrows');}});
}
} else if(type == "left") {
if(chatBoxes.length > (visibleLimit+right)) {
chatboxtitle = e();
g();
busy = 1;
right++;
left = left-1;
scrollAmt = left*132;
$('#chatbar_chats').scrollTo(scrollAmt,0,{duration:750,onAfter:function(){busy=0;f(chatboxtitle);d('refresh_arrows');}});
}
} else if(type == "restructure") {
$('#chatbar_chats_left').css('display','none');
$('#chatbar_chats_right').css('display','none');
if(right > 0) {
right = right - 1;
var chat = e();
if(chat) {
a(chat);
}
d('refresh_arrows');
} else if(left > 0) {
left = left - 1;
var scrollAmt = document.getElementById('chatbar_chats').scrollLeft - 132;
$('#chatbar_chats').scrollTo(scrollAmt,0,{duration:750,onAfter:function(){var chat = e();if(chat) {a(chat);d('refresh_arrows');}}});
} else {
var chat = e();
if(chat) {
a(chat);
}
}
} else if(type == "refresh_arrows") {
alertLeft = 0;
alertRight = 0;
pos = 0;
for(x in chatBoxes) {
pos++;
if(pos > checkLimit1) {
if(newAlert_num[chatBoxes[x]] > 0) {
alertLeft = alertLeft + newAlert_num[chatBoxes[x]]
l('chatbox_chat_foot_'+chatBoxes[x],'chatbox',0,'no');;
}
} else if(pos <= checkLimit2) {
if(newAlert_num[chatBoxes[x]] > 0) {
alertRight = alertRight + newAlert_num[chatBoxes[x]];
l('chatbox_chat_foot_'+chatBoxes[x],'chatbox',0,'no');
}
} else {
l('chatbox_chat_foot_'+chatBoxes[x],'chatbox',newAlert_num[chatBoxes[x]],'no');
}
}
l('chatbar_chats_left','',alertLeft,'no');
l('chatbar_chats_right','',alertRight,'no');
}

$.cookie('chatboxes_left',left);
$.cookie('chatboxes_right',right);

if(type != "refresh_arrows") {
if(chatBoxes.length > visibleLimit) {
if(left > 0) {

$('#chatbar_chats_left').removeClass('chatbar_chats_left_inactive');
$('#chatbar_chats_left').addClass('chatbar_chats_left_active');
} else {
$('#chatbar_chats_left').removeClass('chatbar_chats_left_active');
$('#chatbar_chats_left').addClass('chatbar_chats_left_inactive');;
}
if(right > 0) {
$('#chatbar_chats_right').removeClass('chatbar_chats_right_inactive');
$('#chatbar_chats_right').addClass('chatbar_chats_right_active');
} else {
$('#chatbar_chats_right').removeClass('chatbar_chats_right_active');
$('#chatbar_chats_right').addClass('chatbar_chats_right_inactive');;
}
$('#chatbar_chats_left').css('display','block');
$('#chatbar_chats_right').css('display','block');
$('#chatbar_chats_left').html(left);
$('#chatbar_chats_right').html(right);
} else {
$('#chatbar_chats_left').css('display','none');
$('#chatbar_chats_right').css('display','none');
}
d('refresh_arrows');
}
}
function e() {
        for(x in chatBoxes) {
                if($('#chatbox_chat_body_'+chatBoxes[x]).css('display') == "block") {
                        return chatBoxes[x];
                }
        }
}
function f(chatboxtitle) {
left = parseInt($.cookie('chatboxes_left'));
right = parseInt($.cookie('chatboxes_right'));
if(left == null || !left) {
left = 0;
}
if(right == null || !right) {
right = 0;
}
var checkLimit1 = right+visibleLimit;
var checkLimit2 = chatBoxes.length - visibleLimit - left;
pos=0;
for(x in chatBoxes) {
var chatboxtitleID = chatBoxes[x];
pos++;
$.cookie('chatbox_'+ chatboxtitleID, pos);
}
var chatPos = $.cookie('chatbox_'+chatboxtitle);
if(chatPos < (checkLimit1 + 1) && chatPos > checkLimit2) {
a(chatboxtitle);
}
}
function g() {
        for(x in chatBoxes) {
                $('#chatbox_chat_body_'+chatBoxes[x]).css('display','none');
                $('#chatbox_chat_foot_'+chatBoxes[x]).removeClass('chatbar_chat_foot_opened');
        }

}

function h(chatboxtitle) {
if($('#chatbox_chat_foot_'+chatboxtitle).length != 0) {
        if($('#chatbox_chat_foot_'+chatboxtitle).hasClass('chatbar_chat_foot_opened')) {
                $('#chatbox_chat_body_'+chatboxtitle).css('display','none');
                $('#chatbox_chat_foot_'+chatboxtitle).removeClass('chatbar_chat_foot_opened');
                $.post("/IM/ar_chat.php?action=chatminimized&"+ rand(1,100000), { chatbox: chatboxtitle} , function(data){
                });
        } else {
                a(chatboxtitle);
        }
}
}

function ci(messageArea,event,chatboxtitle,sharePage_event) {
        if(event.shiftKey == 0 && event.keyCode == 13) {
                var isMessageToSend = 1;
        } else if(sharePage_event == 1) {
                var isMessageToSend = 1;
        } else {
                var isMessageToSend = 0;
        }
        if(isMessageToSend == 1){
                messageArea = $(messageArea);
                userMsg = messageArea.val();
                userMsg = userMsg.replace(/^\s+|\s+$/g, "").replace(/\n/g,"<br>");
                messageArea.css('height','17px');
                $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").css('height','233px');
                messageArea.val('');
                messageArea.focus();
                if (userMsg != "" && userMsg.replace(/ /g,'').replace(/\n/g,'') != "") {
                        userMsg = userMsg.replace(/<br>/g,"\n");
                        userMsg = userMsg.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");
                        userMsg = userMsg.replace(/\n/g,"<br>");
                        //userMsg = userMsg.replace(/\?/g,"[-QUESTION_MARK-]");

                        if(lastFrom[chatboxtitle] == username) {
                        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage" id="chatboxmessage_'+recentSent+'"><span class="chatboxmessagecontent">'+userMsg+'</span></div>');
                        } else {
                        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage" id="chatboxmessage_'+recentSent+'"><span class="chatboxmessagefrom2">'+username+':&nbsp;&nbsp;</span><br /><span class="chatboxmessagecontent">'+userMsg+'</span></div>');
                        }
                        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").scrollTop(1000000);
                        trackSent[recentSent] = setTimeout("checkIfSent('"+recentSent+"');",5000);
                        trackMsg[recentSent] = userMsg;
                        trackDone[recentSent] = 0;
                        trackTo[recentSent] = chatboxtitle;
                        sendQueue.push(recentSent);
                        lastFrom[chatboxtitle] = username;
                        var thisSent = recentSent;
                        recentSent++;
                        checkIfSent = function(id) {
                        if(trackDone[recentSent] == 0) {
                        $('#chatboxmessage_'+id).html($('#chatboxmessage_'+id).html() +"<div id=\"chatboxmessage_sending_"+id+"\">Resending...</div>");
                        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").scrollTop(1000000);
                        trackSent[recentSent] = setTimeout("checkIfSent('"+id+"');",1000);
                        } else {
                        if($('#chatboxmessage_sending_'+id).length > 0) {
                        $('#chatboxmessage_sending_'+id).remove();
                        }
                        }
                        }
                        if(sendQueue.length == 1) {
                        $.post("/IM/ar_chat.php?action=sendchat&to="+chatboxtitle+"&"+rand(1,100000), {message: userMsg}, function(data) {
                        //$.ajax({
                        //url: "/IM/ar_chat.php?action=sendchat&to="+chatboxtitle+"&message="+userMsg +"&"+ rand(1,100000),
                        //dataType: "json",
                        //success: function(data) {
                        $.each(data.response, function(i,response){
                        if (response) {
                        removeByElement(sendQueue,thisSent);
                        trackDone[thisSent] = 1;
                        //$('#chatboxmessage_'+thisSent).html($('#chatboxmessage_'+thisSent).html() +"<div id=\"chatboxmessage_sending_"+thisSent+"\"><br />[sent successfully]</div>");
                        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").scrollTop(1000000);

                        if(response.r != 2) {
                                //$("#chatbox_chat_body_"+chatboxtitle+" .chatbar_chat_userimage").html('<a href="/users/'+chatboxtitle+'/"><img src="'+response.p+'"></a>');
                                //$("#chatbox_chat_body_"+chatboxtitle+" .chatbar_chat_status").html(response.status);
                        }
                        if(response.r == "1") {
                        //Success :)
                        } else if(response.r == "2") {
                                $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatbox_error">This user does not exist.</div>');
                        } else if(response.r == "3") {
                                $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatbox_error">You must be friends with this user to chat with them.<br /><a href="javascript:;" onClick="sendRequest(\''+response.i+'\',\'verify\',\''+chatboxtitle+'\');">Click here</a> to send them a friend request.</div>');
                        } else if(response.r == "4") {
                                $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatbox_error"><a href="/users/'+chatboxtitle+'/">'+ chatboxtitle +'</a> is currently offline.<br /><a href="javascript:;" onClick="mA(\'composeNew\',\''+response.i+'\');">Click here</a> to send message.</div>');
                        }
                        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").scrollTop(1000000);


                        if(sendQueue.length > 0) {
                                ci2();
                        }

                }
        });
        },"json");
        }
        }

        return false;

}

        var adjustedHeight = messageArea.clientHeight;
        var maxHeight = 94;

        if (maxHeight > adjustedHeight) {
                adjustedHeight = Math.max(messageArea.scrollHeight, adjustedHeight);
                if (maxHeight) {
                        adjustedHeight = Math.min(maxHeight, adjustedHeight);
                }
                if (adjustedHeight > messageArea.clientHeight) {
                        $(messageArea).css('height',adjustedHeight +'px');
                }
                var newMsg_height = 250 - adjustedHeight +"px";
                //$("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").css('height',newMsg_height);
                $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").scrollTop(10000000);
        } else {
                $(messageArea).css('overflow','auto');
        }
}

function ci2() {
                        toSend = sendQueue[0];
                        thisSent = toSend;
                        userMsg2 = trackMsg[toSend];
                        chatboxtitle2 = trackTo[toSend];
                                $.ajax({
                                url: "/IM/ar_chat.php?action=sendchat&to="+chatboxtitle2+"&message="+userMsg2 +"&"+ rand(1,100000),
                                dataType: "json",
                                success: function(data) {
                                $.each(data.response, function(i,response){
                                if (response) {
                                removeByElement(sendQueue,thisSent);
                                trackDone[thisSent] = 1;
                                if(response.r == "1") {
                                        //$("#chatbox_chat_body_"+chatboxtitle2+" .chatbar_chat_userimage").html('<a href="/users/'+chatboxtitle2+'/"><img src="'+response.p+'"></a>');
                                        //$("#chatbox_chat_body_"+chatboxtitle2+" .chatbar_chat_status").html(response.status);
                                } else if(response.r == "2") {
                                        $("#chatbox_chat_body_"+chatboxtitle2+" .chatboxcontent").append('<div class="chatbox_error">This user does not exist.</div>');
                                } else if(response.r == "3") {
                                        $("#chatbox_chat_body_"+chatboxtitle2+" .chatboxcontent").append('<div class="chatbox_error">You must be friends with this user to chat with them.<br /><a href="/users/'+chatboxtitle2+'/">Click here</a> to send them a friend request.</div>');
                                } else if(response.r == "4") {
                                        $("#chatbox_chat_body_"+chatboxtitle2+" .chatboxcontent").append('<div class="chatbox_error">Sorry, but <a href="/users/'+chatboxtitle2+'/">'+chatboxtitle2+'</a> has gone offline.</div>');
                                }

                                $("#chatbox_chat_body_"+chatboxtitle2+" .chatboxcontent").scrollTop(1000000);
                                if(sendQueue.length > 0) {
                                ci2();
                                }

                                return false;
                                }
                        });
                        }
                        });
}
function j_ping() {
        $.ajax({
          url: "/i/gchat_inc/ar_chat_"+username+".txt",
          cache: false,
          success: function(data) {
                if((data*1) > (last_ar_chat_message*1)) {
                        last_ar_chat_message = data;
                        j();
                } else {
                        j_ping();
                }
          },
          error: function() {
                j_ping();
          }
        });
}

function j() {
        var itemsfound = 0;

        if (windowFocus == false) {

                var blinkNumber = 0;
                var titleChanged = 0;
                for (x in newMessagesWin) {
                        if (newMessagesWin[x] == true) {
                                ++blinkNumber;
                                if (blinkNumber >= blinkOrder) {
                                        document.title = "NEW MESSAGE FROM "+x;
                                        titleChanged = 1;
                                        break;
                                }
                        }
                }

                if (titleChanged == 0) {
                        document.title = originalTitle;
                        blinkOrder = 0;
                } else {
                        ++blinkOrder;
                }

        } else {
                for (x in newMessagesWin) {
                        newMessagesWin[x] = false;
                }
        }

        for (x in newMessages) {
                if (newMessages[x] == true) {
                        if ($('#chatbox_chat_body_'+x).css('display') == "none") {
                        }
                }
        }

        $.ajax({
          url: "/IM/ar_chat.php?action=chatheartbeat&"+ rand(1,100000),
          cache: false,
          dataType: "json",
          success: function(data) {

                $.each(data.items, function(i,item){
                        if (item)        {
                                chatboxtitle = item.f;
                                if ($("#chatbox_chat_body_"+chatboxtitle).length <= 0) {
                                        a(chatboxtitle);
                                }
                                if (item.s == 1) {
                                        item.f = username;
                                }
                                if (item.s == 2) {
                                        //$("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
                                } else {
                                        newMessages[chatboxtitle] = true;
                                        newMessagesWin[chatboxtitle] = true;
                                if (item.s == 2) {
                                        //$("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
                                } else {
                                if(lastFrom[chatboxtitle] == item.f) {
                                        if(item.f != username) {
                                                 $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagecontent">'+item.m+'</span></div>');
                                        } else {
                                                 $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagecontent">'+item.m+'</span></div>');
                                        }
                                } else {
                                        if(item.f != username) {
                                                 $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom"><a href="/users/'+item.f+'/" style="color: #0000FF;">'+item.f+'</a>:&nbsp;&nbsp;</span><br /><span class="chatboxmessagecontent">'+item.m+'</span></div>');
                                        } else {
                                                 $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom2">'+item.f+':&nbsp;&nbsp;</span><br /><span class="chatboxmessagecontent">'+item.m+'</span></div>');
                                        }
                                }
                                }
                                }

                                 $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").scrollTop(10000000);
                                 itemsfound += 1;
                        }
                lastFrom[chatboxtitle] = item.f;
                });

                chatHeartbeatCount++;

                if (itemsfound > 0) {
                                if ($("#chatbox_chat_body_"+chatboxtitle).css('display') == 'none') {
                                newAlert_num[chatboxtitle]++
                                l('chatbox_chat_foot_'+chatboxtitle,'chatbox',newAlert_num[chatboxtitle]);
                                d('refresh_arrows');
                                }
                                if ($("#chatbox_chat_body_"+chatboxtitle).css('display') == 'block') {
                                newAlert_num[chatboxtitle] = 0;
                                $.post("/IM/ar_chat.php?action=chatread", { chatbox: chatboxtitle} , function(data){
                                });
                                }
                        chatHeartbeatTime = minChatHeartbeat;
                        chatHeartbeatCount = 1;
                } else if (chatHeartbeatCount >= 10) {
                        chatHeartbeatTime *= 2;
                        chatHeartbeatCount = 1;
                        if (chatHeartbeatTime > maxChatHeartbeat) {
                                chatHeartbeatTime = maxChatHeartbeat;
                        }
                }

                //setTimeout('j();',chatHeartbeatTime);
                setTimeout('j_ping();',chatHeartbeatTime);
        }});
}

function k(mode){
        var itemsfound = 0;
        if (windowFocus == false) {

                var blinkNumber = 0;
                var titleChanged = 0;
                for (x in newMessagesWin) {
                        if (newMessagesWin[x] == true) {
                                ++blinkNumber;
                                if (blinkNumber >= blinkOrder) {
                                        document.title = "NEW MESSAGE FROM "+x;
                                        titleChanged = 1;
                                        break;
                                }
                        }
                }

                if (titleChanged == 0) {
                        document.title = originalTitle;
                        blinkOrder = 0;
                } else {
                        ++blinkOrder;
                }

        } else {
                for (x in newMessagesWin) {
                        newMessagesWin[x] = false;
                }
        }
        for (x in newMessages) {
                if (newMessages[x] == true) {
                        if (chatboxFocus[x] == false) {
                                //FIXME: add toggle all or none policy, otherwise it looks funny
                                if($('#chatbox_chat_body_'+x).css('display') == "none") {
                                newAlert_num[chatBoxes[x]]++;
                                l('chatbox_chat_foot_'+x,'chatbox',newAlert_num[chatBoxes[x]]);
                                d('refresh_arrows');
                                }
                        }
                }
        }
        $.ajax({
          url: "/IM/ar_chat.php?action=startchatsession&"+ rand(1,100000),
          cache: false,
          dataType: "json",
          error: function(request,error) {
alert(error);
},
          success: function(data) {
                username = data.username;
                opened = data.opened;
                $.each(data.items, function(i,item){
                        if (item)        {

                                chatboxtitle = item.c;
                                if ($("#chatbox_chat_foot_"+chatboxtitle).length <= 0) {
                                if(mode == "initialize") {
                                        a(chatboxtitle,'initialize',item.p,'testing 1 2 3');
                                } else {
                                        a(chatboxtitle,'',item.p,'testing 1 2 3');
                                }
                                }

                                if (item.s == 1) {
                                        item.f = username;
                                }
                                if (item.s == 2) {;
                                        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
                                } else {
                                if(lastFrom[chatboxtitle] == item.f) {
                                        if(item.f == item.c) {
                                                 $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagecontent">'+item.m+'</span></div>');
                                        } else {
                                                 $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagecontent">'+item.m+'</span></div>');
                                        }
                                } else {
                                        if(item.f == item.c) {
                                                 $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom"><a href="/users/'+item.f+'/" style="color: #0000FF;">'+item.f+'</a>:&nbsp;&nbsp;</span><br /><span class="chatboxmessagecontent">'+item.m+'</span></div>');
                                        } else {
                                                 $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom2">'+item.f+':&nbsp;&nbsp;</span><br /><span class="chatboxmessagecontent">'+item.m+'</span></div>');
                                        }
                                }
                                }
                        }
                lastFrom[chatboxtitle] = item.f;
                });

                for (i=0;i<chatBoxes.length;i++) {
                        chatboxtitle = chatBoxes[i];
                        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").scrollTop(10000000);
                        //setTimeout('$("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);', 100);
                }
                if(mode == "initialize") {
                d('initialize');
                //var opened = $.cookie('chatbox_opened');
                if(opened != "NaN" && opened != "" && opened != null) {
                        //a(opened);
                }
                if(opened != "") {
                        a(opened);
                }
                }
                setTimeout('j_ping();',chatHeartbeatTime);

        }});
}

function l(elementID,type,int1,bounce){
if($('#chatbar_alert_'+elementID).length == 0) {
$("#"+elementID).append('<div id="chatbar_alert_'+elementID+'" class="chatbar_alert"></div>');
var element = $('#'+elementID);
var alertID = $('#chatbar_alert_'+elementID);
if(type == "chatbox") {
if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
var chatbar_chats = $('#chatbar_chats');
var scrollAmt = 0 - chatbar_chats.scrollLeft();
var scrollAmt = (chatbar_chats.scrollLeft() - scrollAmt) / 2 - 30;
var scrollAmt = 0 - scrollAmt +"px";
alertID.css('margin-left',scrollAmt);
} else {
alertID.css('margin-left','30px');
}
}
if(type == "inbox") {
alertID.css('margin-left','50px');
}
if(type == "notifications") {
alertID.css('margin-left','11px');
}
}
var element = $('#'+elementID);
var alertID = $('#chatbar_alert_'+elementID);
oldInt = parseInt(alertID.html());
int1 = parseInt(int1);
if(int1 == 0) {
alertID.remove();
} else if(int1 != oldInt) {
if(bounce != "no") {
alertID.css('top','50px').animate({top:'-25px'},250).animate({top:'-10px'},250);}
} else {
alertID.css('top','-10px');
}
alertID.html(int1);
}

function m(chat) {
        $('#chatbox_chat_body_'+chat).remove();
        $('#chatbox_chat_foot_'+chat).remove();
        $('#chat_td_'+chat).remove();
        removeByElement(chatBoxes,chat);
        $.post("/IM/ar_chat.php?action=closechat&"+rand(1,100000), {chatbox: chat} , function(data){
        });
        var opened = $.cookie('chatbox_opened');
        if(opened == chat) {
        $.cookie('chatbox_opened', null);
        }
        d('restructure');

}

function N() {
        for(x in chatBoxes) {
                l('chatbox_chat_foot_'+chatBoxes[x],'',0);
                l('chatbar_chats_left','',0);
                l('chatbar_chats_right','',0);
        }
}

function ech(chatboxtitle) {
        $("#chatbox_chat_body_"+chatboxtitle+" .chatboxcontent").html('');
        $.post("/IM/ar_chat.php?action=clearchathistory&"+ rand(1,100000), { chatbox: chatboxtitle} , function(data){
        });
}

function x(mode) {
if(!mode) {
//bottomInbox();
//bottom_loadFeatures();
btmBar_update(1);
$.post("/IM/ar_chat.php?action=initialize", {} , function(data){
k('initialize');
});
} else if(mode == "logged_in") {
$('#chatbar_base_nologin').animate({bottom:'-30px'}, 1000);
//$('#chatbar_base_nologin').fadeOut(1000);
setTimeout("X_next1()",500);
}
}
function X_next1() {
$('#chatbar_base').fadeIn(1000);
$('#chatbar_base').animate({bottom:'0px'}, 1000);
setTimeout("X_next2()",1000);
}
function X_next2() {
//bottomInbox();
//bottom_loadFeatures();
btmBar_update(1);
$.post("/IM/ar_chat.php?action=initialize&"+ rand(1,100000), {} , function(data){
k('initialize');
});
}
function toggleNotifications() {
var editSubDiv = document.getElementById('edit_subscriptions');
var notificationsDiv = document.getElementById('main_notifications');
if(editSubDiv.style.display == "none") {
notificationsDiv.style.display = "none";
editSubDiv.style.display = "block";
} else if(editSubDiv.style.display == "block") {
editSubDiv.style.display = "none";
notificationsDiv.style.display = "block";
}
}


/*

Copyright (c) 2009 Anant Garg (anantgarg.com | inscripts.com)

This script may be used for non-commercial purposes only. For any
commercial purposes, please contact the author at
anant.garg@inscripts.com

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
