/*
* realtime notification js support
*/

     /*
     * NOTE: this wrapper is necessary because the cometchat js has used the query.noconflict and hijacked
     * the $ var
     */
    jqcc(document).ready(function($) {
      var $_UPDATE_URL = "notificationUpdate.php";
      var $_NOTIFICATIONS_UPDATE = 0;
      var $_NOTIFICATIONS_DELETE = 1;
      var $_FACEBOOK_LOGIN = 2;
      // Code using $ as usual goes here.
      $('#mailnotification').live('click', function() {
        if ($('#notification_window').css('display')=='block') {
            $('#notification_window').css('display','none');
            /* user has viewed notification, remove them
            */
            $.post($_UPDATE_URL, {uid:$_NOTIF_SESSION_USER,op:$_NOTIFICATIONS_DELETE}, function(d){ });

        }
        else {
            $('#notification_window').css('top',$('#mailnotification').position().top+30);
            $('#notification_window').css('left',$('#mailnotification').position().left);
            $('#notification_window').css('display','block');
        }
          return false;
        });
       /* this has to add the click rather than overwrite */
      //$('.notif_clickable').live('click', function() {
      //      $('#mailnotification').trigger('click');
      //      return false;
      //  });

      $('#notification_window #close_button').live('click', function() {
            $('#mailnotification').trigger('click');
            return false;
        });

        $("div#mailnotification").hover(
          function () { $(this).addClass('hover'); },
          function () { $(this).removeClass('hover'); }
        );
        $('div.close_button').live('mouseover', function(event) {$(this).addClass('hover');});
        $('div.close_button').live('mouseout', function(event) {$(this).removeClass('hover');});

        if (typeof($_NOTIF_SESSION_USER) ==='undefined') $u=0; else $u=$_NOTIF_SESSION_USER;
        $.PeriodicalUpdater({
              url : 'notificationUpdate.php',
              method: 'post',
              sendData: {uid:$u,op:$_NOTIFICATIONS_UPDATE},
              //sendData: {data: {op:'update',uid:$_NOTIF_SESSION_USER}},
              //sendData: {name: $_NOTIF_SESSION_USER, op: $_NOTIFICATIONS_UPDATE},
              type: 'json',
              minTimeout: 5000,
              maxTimeout: 50000,
              multiplier: 2
           },
           function(data){
              if (data['cnt']>0) {
                 $("div#mailnotification").css( {"background-image": "url(/images/mail_icon5.gif)", "background-repeat":"no-repeat"});
                 $("div#mailnotification").html(data['cnt']);
              }
              else  {
                 $("div#mailnotification").css( {"background-image": "url(images/mail_icon4_empty.gif)", "background-repeat":"no-repeat"});
                 $("div#mailnotification").html("");
              }
              $('#notification_window').html("<div id='close_button' class='close_button'></div>"+data['notifs']);

              if (data['fb_cnt']>0) {
                      /* determine if user is logged in first */
                     FB.getLoginStatus(function(response) {
                          if (response.session) {
                              // logged in and connected user, someone you know
                              postEventToFacebook(data['facebook_notifs']);
                          }
                      });
              }
           });

           /* this for the homepage joinnow button
           */
           $("#joinnowbtn").click(function(){
                //alert('click');
                window.location="http://www.velvetdeck.com/registerfb.php";
           });
        $("#joinnowbtn").hover(
          function () {
            $(this).css('background', 'url(/images/joinnowbtn1.gif)');
            $(this).css('cursor', 'pointer');
          },
          function () {
            $(this).css('background', 'url(/images/joinnowbtn.gif)');
            $(this).css('cursor', 'auto');
          }
        );
        $("#gettokenbutton").hover(
          function () {
            $(this).css('background', 'url(/images/GET TOKENS_0.bmp)');
            $(this).css('cursor', 'pointer');
          },
          function () {
            $(this).css('background', 'url(/images/GET TOKENS_1.bmp)');
            $(this).css('cursor', 'auto');
          }
        );

});     // jquery

