// JavaScript Document
$(document).ready(function() {
  $.base_url = 'http://localhost:8888/'; // Your website name
  var webcamtotal = 6;

  function updateImages() {
    var imgs = $('.ass'); //jQuery class selector 
    imgs.each(function() {
      var img = $(this);
      var width = img.width(); //jQuery width method 
      var height = img.height(); //jQuery height method 
      if (width < height) {
        img.addClass('portrait');
      } else {
        img.addClass('landscape');
      }
    })
  }
  $("a.timeago").livequery(function() {
    $(this).timeago();
  });
  $("span.timeago").livequery(function() {
    $(this).timeago();
  });
  $(".smcommenttime").livequery(function() {
    $(this).timeago();
  });
  $(".post-text, .whoc-co, .announcement").livequery(function() {
    $(this).linkify({
      target: "_blank"
    });
  });
  $(".post-text, .whoc-co, .notification_message_and_time").livequery(function() {
    $(this).emoticons();
  });
  $(".post-text, .whoc-co, .notification_message_and_time").livequery(function() {
    $(this).emoticonsM();
  });
  $(".tpy").tipsy({gravity: 's',live: true});
  /*Introdution Demo*/
  $('.icon-annonce-cancel').click(function() {
    var URL = $.base_url + 'annonce_ajax.php';
    var A = $(this).html();
    /*You can enable for Done button, right now it is working for both Skip and Done*/

    /*if(A=='Done')*/
    if (1) {
      var dataString = 'announcement_readed=' + A;
      $.ajax({
        type: "POST",
        url: URL,
        data: dataString,
        cache: false,
        success: function(html) {
          $('.annonce').addClass('fadeOutRightBig');

        }
      });
    }
  });
  /* Notification link */
  $("#notificationLink").on('click', function() {
    var URL = $.base_url + 'notification_created_ajax.php';
    $.ajax({
      type: "POST",
      url: URL,
      cache: false,
      success: function(html) {
        if (html) {

          if ($(".notification").is(':visible')) $(".notification").fadeOut(300);

          $(".notificationContainer").fadeToggle(300);
          $(".not_count").fadeOut('slow');
          $("#notifications_container").html(html);
        }
      }
    });

    return false;
  });
  /* Uploading timelineProfile  Image */
  $('body').on('change', '#profilephotoimg', function() {
    $("#profileimageform").ajaxForm({
      target: '#timelineProfilePic',
      beforeSubmit: function() {},
      success: function() {
        $("#profileimageform").hide();
        $(".previousImage").hide();
      },
      error: function() {

      }
    }).submit();
  });
  /* Uploading timeline Mini Profile  Image */
  $('body').on('change', '#miniprofilephotoimg', function() {
    $("#miniprofileimageform").ajaxForm({
      target: '#minitimelineProfilePic',
      beforeSubmit: function() {},
      success: function() {
        $("#miniprofileimageform").hide();
        $(".minipreviousImage").hide();
      },
      error: function() {

      }
    }).submit();
  });
  $('body').on('click', function(e) {
    if ($(e.target).closest('#notificationLink').length == 0 && $(e.target).closest('.notificationContainer').length == 0) {
      $(".notificationContainer").fadeOut(300);

    }
  });

  $(".ShowMessage").on('click', function() {
    $(".NotificationMessageContainer").fadeToggle(300);
    $("#messageSum").fadeOut('slow');
  });
  $('body').on('click', function(e) {
    if ($(e.target).closest('.ShowMessage').length == 0 && $(e.target).closest('.NotificationMessageContainer').length == 0) {
      $(".NotificationMessageContainer").fadeOut(300);
    }
  });
  // Post image Update
  $("#upload_images").click(function() {
    var updatevals = $("#annotations").val();
    var uploadvalues = $("#uploadvalues").val();
    var secret_option = $("input[name='secret_option_image']:checked").val();
    var Y = $('.webcam_preview, .gifshot-image-preview-section').attr('id');
    var M = $('.preview_img').attr('id');
    if (M) {
      var T = M + ',' + uploadvalues;
    } else if (Y) {
      var T = uploadvalues;
    } else {
      var T = 0;
    }
    var dataVV = 'supdate=' + updatevals + '&uploads=' + T + '&secret_option=' + secret_option;

    if (T == 0) {

      swal({
        title: "Bitte wählen Sie ein Bild aus !",
        text: "",
        timer: 5000
      });

    } else {
      $(".post_loader").fadeIn(100);
      $.ajax({
        type: "POST",
        url: $.base_url + "message_ajax.php",
        data: dataVV,
        cache: false,
        success: function(html) {
          $(".post_loader").fadeOut(100);
          $(".chated-poeople").prepend(html);
          $('.image_preview').html('');
          $(".wellcomenewsfeed").fadeOut(100);
          $('#uploadvalues').val('');
          $('#photoimg').val('');
          var c = $('#update_count').html();
          $('#update_count').html(parseInt(c) + 1);
        }
      });
      $(".image_preview").html();
      $('#imageupload').slideUp('fast');
    }
    return false;
  });
  // Uploading Image

  $('#photoimg').off('click').on('change', function() {
    var values = $("#uploadvalues").val();
    $("#imageform").ajaxForm({
      target: '.image_preview',
      beforeSubmit: function() {
        $(".post_loader").fadeIn();
        $("#imageloadstatus").show();
        $("#imageloadbutton").show();
      },
      success: function() {
		$(".post_loader").fadeOut();
        $("#imageloadstatus").hide();
        $("#imageloadbutton").show();
        var M = $('.preview_img').attr('id');
        var T = M + ',' + values;
        if (T != 'undefined,') {
          $("#uploadvalues").val(T);
        }
      },
      error: function() {
        $("#imageloadstatus").hide();
        $("#imageloadbutton").show();
      }
    }).submit();
  });
//Video Upload
$("#update_video").on('click',function() 
{
var A = $("#video_description").val();
var C=$("#videouploadvalues").val();
var secret_option=$("input[name='secret_option_video']:checked").val();
var X=$('.video-onizleme').attr('id');

var T = $.trim(C).length > 0 ? C : 0;
		var dataVideo = '';
		
		if($.trim(C).length == 0){
			swal({ title: "Bitte laden Sie ein Video.", text: "", timer: 3000 });
		} else { // we have a text or image or both
		
	        dataVideo = 'vupdate='+ A +'&video='+T+'&secret_option='+secret_option;
		
		}
	 
$(".paylasiliyor").fadeIn(100);
$.ajax({
type: "POST",
url: "message_video_ajax.php",
data: dataVideo,
cache: false,
success: function(html)
{
$("#webcam_container").slideUp('fast');
$(".post_loader").fadeOut(100);
$(".chated-poeople").prepend(html);
$('.video-onizleme').html('');
$('#videouploadvalues').val('');
$('#video_description').val('');
var c=$('#update_count').html();
$('#update_count').html(parseInt(c)+1);
}
 });
 $(".resim-onizleme").html();
$('#imageupload').slideUp('fast');

return false;
	});
//Video Yükle
$('#videop').off('click').on('change', function()	
{ 


var values=$("#videouploadvalues").val();
$("#previeww").html('<img src="wall_icons/loader.gif"/>');
$("#videoform").ajaxForm(
{
	target: '.video-onizleme',
    beforeSubmit:function(){  
		 $(".post_loader").show();
	}, 
	success:function(){ 
		$(".post_loader").hide();
		$(".d-p-v").hide();
		var X=$('.preview_img').attr('id'); 
		var C= X+','+values;
		if(C!='undefined,')	{
			$("#videouploadvalues").val(C);
		}
	}, 
	error:function(){ 
		 $(".post_loader").hide();
		 $(".post_loader").show();
	} 
}).submit();
});
  // Update Text and Link
  $("#update").focus();

  $("#update_button").click(function() {
    var updateval = $("#update").val();
    var secret_option = $("input[name='secret_option_text']:checked").val();
    var dataString = 'update=' + updateval + '&secret_option=' + secret_option;
    if ($.trim(updateval).length == 0) {
      swal({
        title: "Bitte schreiben Sie was !",
        text: "",
        timer: 5000
      });
    } else {
      $(".paylasiliyor").fadeIn(100);
      $.ajax({
        type: "POST",
        url: $.base_url + "postudatetext.php",
        data: dataString,
        cache: false,
        success: function(html) {
          $(window).load();
          $(".paylasiliyor").fadeOut(100);
          $(".chated-poeople").prepend(html);
          $(".wellcomenewsfeed").fadeOut(100);
          $('#update').val('');
        }
      });
    }
    return false;
  });
  // Delete Post
  $('.stdelete').live("click", function() {
    var ID = $(this).attr("id");
    var dataString = 'msg_id=' + ID;

    jConfirm('Sind sie sicher, Ihre Nachricht löschen zu wollen ?', '',
      function(r) {
        if (r == true) {

          $.ajax({
            type: "POST",
            url: $.base_url + "message_delete_ajax.php",
            data: dataString,
            cache: false,
            beforeSend: function() {
              $("#smbody" + ID).animate({
                'backgroundColor': '#323949'
              }, 300);
            },
            success: function(html) {
              swal({
                title: "Die Nachricht wurde erfolgreich gelöscht ",
                text: "",
                timer: 5000
              });
              $("#smbody" + ID).fadeOut(300, function() {
                $("#smbody" + ID).remove();
              });
              var c = $('#update_count').html();
              $('#update_count').html(parseInt(c) - 1);
            }
          });
        }
      });
    return false;
  });

  //Delete Comment

  $('.smcommentdelete').live("click", function() {
    var ID = $(this).attr("id");
    var dataString = 'com_id=' + ID;
    var URL = $.base_url + 'comment_delete_ajax.php';

    jConfirm('Sind sie sicher, das Sie ihr Kommentar löschen möchtet ?', '',
      function(r) {
        if (r == true) {

          $.ajax({
            type: "POST",
            url: URL,
            data: dataString,
            cache: false,
            beforeSend: function() {
              $("#smcommentbody" + ID).animate({
                'backgroundColor': '#f6f7f8'
              }, 300);
            },
            success: function(html) {
              $("#smcommentbody" + ID).fadeOut(300, function() {
                $("#smcommentbody" + ID).remove();
              });
            }
          });

        }
      });
    return false;
  });

  // Like and Unlike
  $('.like_button').live("click", function(event) {
    event.preventDefault();
    var KEY = parseInt($(this).attr("data"));
    var ID = $(this).attr("id");
    if (KEY == '1') {
      var sid = ID.split("likes");
    } else {
      var sid = ID.split("like");
    }
    var New_ID = sid[1];
    var REL = $(this).attr("rel");
    var URL = $.base_url + 'like_post.php';
    var dataString = 'msg_id=' + New_ID + '&rel=' + REL;
    $.ajax({
      type: "POST",
      url: URL,
      data: dataString,
      cache: false,
      success: function(html) {
        if (html) {
          if (REL == 'Like') {
            $("#elikes" + New_ID).show('slow').prepend("<span id='you" + New_ID + "' class='bbc'><a href='#'></a> Das Gefällt dir.</span>");
            $("#likes" + New_ID).prepend("<span id='you" + New_ID + "'><a href='#'>Sie</a>, </span>");
            $('#' + ID).html('<div class="icon-like-comment icon-heart-2"></div>').attr('rel', 'Unlike').attr('title', 'Unlike');
          } else {
            $("#elikes" + New_ID).hide('slow');
            $("#you" + New_ID).remove();
            $('#' + ID).attr('rel', 'Like').attr('title', 'Like').html('<div class="icon-like-comment icon-heart-empty-1"></div>');
          }
        }

      }
    });

    return false;
  });

  //Load More Comments
  $('.comment_button').live("click", function(event) {
    event.preventDefault();
    var ID = $(this).attr("id");
    var OID = $(this).attr("rel");
    var URL = $.base_url + 'comments.php';
	var sticker = $('.sm-sticker').attr('sticker');
	var comment = $(this).parents('.user-post').find("#ctextarea" + ID).val();
    var dataString = 'comment=' + comment + '&msg_id=' + OID;

    if ($.trim(comment).length == 0) {
      swal({
        title: "Bitte kommentieren Sie den Status !",
        text: "",
        timer: 5000
      });
    } else {
      $.ajax({
        type: "POST",
        url: URL,
        data: dataString,
        cache: false,
        success: function(html) {
          $("#commentload" + ID).append(html);
          $("#ctextarea" + ID).val('').css("height", "35px").focus();

        }
      });
    }
    return false;
  });
  $('.add-y-comment').bind('keydown', function(e) {
   if(e.keyCode==13) {
	  var ID = $(this).attr("data-msgid");
      var URL = $.base_url + 'comments.php';
	  var comment = $(this).val();
	  var sticker = $('.sm-stickerB').attr('sticker');
      var dataString = 'comment=' + comment + '&msg_id=' + ID;

      if ($.trim(comment).length == 0) {
        swal({
          title: "Bitte kommentieren Sie den Status !!",
          text: "",
          timer: 5000
        });
       } else {
          $.ajax({
          type: "POST",
          url: URL,
          data: dataString,
          cache: false,
          success: function(html) {
            $("#commentload" + ID).append(html);
            $("#ctextarea" + ID).val('').css("height", "35px").focus();
          }
        });
       }
    return false;
		}
  });
  // Comment Open
  $('.commentopen_button').on("click", function(event) {
    event.preventDefault();
    var ID = $(this).attr("id");
    $("#commentbox" + ID).slideToggle('fast');
    $("#ctextarea" + ID).focus();
    return false;

  });
  //Comment Like Unlike
  $('.commentlike').live("click", function(event) {
    event.preventDefault();
    $(this).toggleClass("active");
    var ID = $(this).attr("id");
    var sid = ID.split("clike");
    var New_ID = sid[1];
    var REL = $(this).attr("rel");

    var URL = $.base_url + 'like_comment.php';
    var dataString = 'com_id=' + New_ID + '&rel=' + REL;
    $.ajax({
      type: "POST",
      url: URL,
      data: dataString,
      cache: false,
      success: function(html) {

        if (REL == 'Like') {
          $('#' + ID).html('').attr('rel', 'Unlike').attr('title', 'Unlike');

          $("#count_container" + New_ID).fadeIn('slow');
          $(".comment_count" + New_ID).html(html);

        } else {
          $('#' + ID).attr('rel', 'Like').attr('title', 'Like').html('');
          if (html > 0) {
            $(".comment_count" + New_ID).html(html);
          } else {
            $("#count_container" + New_ID).fadeOut('slow');
          }
        }
      }
    });
    return false;
  });
  //Load More Post
  $('.morep').live("click", function(event) {
    event.preventDefault();
    var ID = $(this).attr("id");
    var P_ID = $(this).attr("rel");
    var URL = $.base_url + 'load_more_post.php';
    var dataString = "lastid=" + ID + "&profile_id=" + P_ID;

    if (ID) {
      $.ajax({
        type: "POST",
        url: URL,
        data: dataString,
        cache: false,
        beforeSend: function() {
          $("#more" + ID).html('<img src="wall_icons/ajaxloader.gif" />');
        },
        success: function(html) {
          $("div.chated-poeople").append(html);
          $("#more" + ID).remove();
        }
      });
    } else {
      $("#more").html('The End');

    }

    return false;
  });
  //Load More Profile Post
  $('.more').live("click", function(event) {
    event.preventDefault();
    var ID = $(this).attr("id");
    var P_ID = $(this).attr("rel");
    var URL = $.base_url + 'load_more_profile_post.php';
    var dataString = "lastid=" + ID + "&profile_id=" + P_ID;

    if (ID) {
      $.ajax({
        type: "POST",
        url: URL,
        data: dataString,
        cache: false,
        beforeSend: function() {
          $("#more" + ID).html('<img src="wall_icons/ajaxloader.gif" />');
        },
        success: function(html) {
          $("div.chated-poeople").append(html);
          $("#more" + ID).remove();
        }
      });
    } else {
      $("#more").html('The End');

    }

    return false;
  });
  // Load More Comment
  $(".view_comments").live("click", function(event) {
    event.preventDefault();
    var ID = $(this).attr("id");
    var OID = $(this).attr("rel");
    var URL = $.base_url + 'load_more_comment.php';
    $.ajax({
      type: "POST",
      url: URL,
      data: "msg_id=" + OID,
      cache: false,
      success: function(html) {
        $("#commentload" + ID).html(html);
      }
    });
    return false;
  });
  // Show status from right side
  $(".ShowStatus").live("click", function(event) {
    $('body').css('overflow', 'hidden');
    event.preventDefault();
    var id = $(this).data("id");
    $.ajax({
      url: $.base_url + "ShowStatus.php?msg_id=" + id,
      type: 'get',
      beforeSend: function() {
        $("#loader").fadeIn(100);
      },
    }).done(function(data) {
      $("#loader").fadeOut(100);
      $(".sidebar").fadeIn().find(".sidebar-content").animate({
        "right": 0
      }, 200).html(data);
      $(window).load();
    });

  });
  $(".sidebar, .icon-status-close").click(function(e) {
    var preventClick = $(".sidebar-content");

    if (!preventClick.is(e.target) && preventClick.has(e.target).length === 0) {
      $(".sidebar-content").animate({
        "right": "0%"
      }, 200, function() {
        $(".sidebar").fadeOut();
        $('body').css('overflow', 'auto');
      });
    };
  });
  //Image Delete
  $('.imageDelete').on('click', function() {
    var ID = $(this).attr("id");
    var dataString = 'msg_id=' + ID;

    jConfirm('Sind sie sich sicher, das Sie ihr Bild löschen möchtet ?', '',
      function(r) {
        if (r == true) {
          $.ajax({
            type: "POST",
            url: $.base_url + "message_delete_ajax.php",
            data: dataString,
            cache: false,
            beforeSend: function() {
              $("#imgbody" + ID).animate({
                'backgroundColor': '#004d40'
              }, 300);
            },
            success: function(html) {
              swal({
                title: "Ihr Bild wurde erfolgreich gelöscht !",
                text: "",
                timer: 5000
              });
              $("#imgbody" + ID).fadeOut(300, function() {
                $("#imgbody" + ID).remove();
              });

            }
          });
        }
      });
    return false;
  });
  // Follow
  $('.addbutton').live('click', function() {
    var vid = $(this).attr("id");
    var sid = vid.split("add");
    var ID = sid[1];
    var dataString = 'fid=' + ID;

    $.ajax({
      type: "POST",
      url: $.base_url + "friend_add_ajax.php",
      data: dataString,
      cache: false,
      beforeSend: function() {
        $("#friendstatus").html('<img src="wall_icons/ajaxloader.gif"  />');
      },
      success: function(html) {
        if (html) {
          $("#friendstatus").html('');
          $("#add" + ID).hide();
          $("#remove" + ID).show();
        }
      }
    });
    return false;
  });
  // Search User
  $("#searchinput").keyup(function() {
    var searchbox = $(this).val();
    var dataString = 'searchword=' + searchbox;

    if (searchbox.length > 0) {

      $.ajax({
        type: "POST",
        url: $.base_url + "search_ajax.php",
        data: dataString,
        cache: false,
        beforeSend: function() {
          $('.ajax-loading').addClass('active');
        },
        success: function(html) {
          $(".search-result-wrap").html(html).show();
        }
      }).complete(function() {
        $('.ajax-loading').removeClass('active');
      });
    }
    return false;
  });

  $(".search-result-wrap").mouseup(function() {
    return false;
  });

  $(document).mouseup(function() {
    $('.search-result-wrap').hide();
    $('#searchinput').val("");
  });
  // Unfollow
  $('.removebutton').live('click', function() {

    var vid = $(this).attr("id");
    var sid = vid.split("remove");
    var ID = sid[1];
    var dataString = 'fid=' + ID;

    $.ajax({
      type: "POST",
      url: $.base_url + "friend_remove_ajax.php",
      data: dataString,
      cache: false,
      beforeSend: function() {
        $("#friendstatus").html('<img src="wall_icons/ajaxloader.gif"  />');
      },
      success: function(html) {
        if (html) {
          $("#friendstatus").html('');
          $("#remove" + ID).hide();
          $("#add" + ID).show();
        }
      }
    });
    return false;
  });

  //Active Link
  $(".profile-buttons a").filter(function() {
    return this.href == location.href.replace(/#.*/, "");
  }).addClass("pactive");

  // Open Comment Area 
  $('.openCommentArea').die('click').live("click", function() {
    var ID = $(this).attr("id");
    $("#commentbox" + ID).slideToggle('fast');
    $("#ctextarea" + ID).focus();
    return false;
  });

  //Show More Photos

  $('body').on("click", '.nextphotos', function() {

    var ID = $(this).attr("id");
    var P_ID = $(this).attr("rel");
    var URL = $.base_url + 'more_photos_ajax.php';
    var dataString = "lastrmid=" + ID + "&profile_id=" + P_ID;
    if (ID) {
      $.ajax({
        type: "POST",
        url: URL,
        data: dataString,
        cache: false,
        beforeSend: function() {
          $(".post_loader").fadeIn(200);
        },
        success: function(html) {

          $(window).load();
          $("div.image-container").append(html).each(function() {});
          updateImages();
          $("#more" + ID).remove();
        }
      });
    } else {
      $("#more").html('The End');

    }

    return false;
  });
  updateImages();
  // Gönderiyi Şikayet Et
  $(function() {
    var i;
    $('.report_post').live('click', function() {
      $('.backbar').animate({
        'opacity': '.50'
      }, 300, 'linear');
      $('.report_wrap').animate({
        'opacity': '1.00'
      }, 300, 'linear');
      $('.backbar, .report_wrap').css('display', 'block');
      //get id
      i = $(this).attr('id');

    });
    //click .report button
    $('.send_this_report').click(function(e) {
      e.preventDefault();
      $.ajax({
        type: "POST",
        url: $.base_url + 'report_post.php',
        data: {
          id: i,
          report_type: $('input[name="report_type"]:checked').val()
        },
        beforeSend: function() {
          $("#posting").html('<img src="icons/ajaxloader.gif"/>');
        },
        success: function(html) {
          if (html.trim() === "1") {
            $('input[name="report_type"]').attr('checked', false);
            $('.backbar, .report_wrap').animate({
              'opacity': '0'
            }, 300, 'linear', function() {
              $('.backbar, .report_wrap').css('display', 'none');
            });
            swal({
              title: "Ihr Bericht wurde erfolgreich gesendet !",
              text: "Thanks",
              timer: 4000
            });
          } else {
            swal({
              title: "In ihrem Bericht ist ein Fehler aufgetreten (Ungültige Optionen)",
              text: ":o",
              timer: 4000
            });
          }
        }
      });
      return false;
    });
    $('.go').click(function() {
      close_box1();
    });
  });

  function close_box1() {
    $('.backbar, .report_wrap').animate({
      'opacity': '0'
    }, 300, 'linear', function() {
      $('.backbar, .report_wrap').css('display', 'none');
    });
    $('input[name="report_type"]').attr('checked', false);
  }

  function OpenReportForm(id) {
      $('backbar').animate({
        'opacity': '.50'
      }, 300, 'linear');
      $('backbar').css('display', 'block');
      //ToDo: Maybe show which report is clicked? 
      // Do Something with the ID 
      // maybe save it to a variable
    }
    /*//Paylaşım gizlilik ayarını değiştir
    $(function() {
      var i;
      $('.gizdznl').live('click', function() {
        $('.vduzalani').animate({
          'opacity': '.50'
        }, 300, 'linear');
        $('.gizliligi-degistir-alani').animate({
          'opacity': '1.00'
        }, 300, 'linear');
        $('.vduzalani, .gizliligi-degistir-alani').css('display', 'block');
        //get id
        i = $(this).attr('id');

      });
      //click .report button
      $('.gdeggistir').click(function(e) {
        e.preventDefault();
        $.ajax({
          type: "POST",
          url: 'gizlilik_ayarini_degistir.php',
          data: {
            id: i,
            gizlisecenek: $('input[name="gizlisecenek"]:checked').val()
          },
          beforeSend: function() {
            $("#posting").html('<img src="icons/ajaxloader.gif"/>');
          },
          success: function(html) {
            $('input[name="gizlisecenek"]').attr('checked', false);
            $('.vduzalani, .yorumu-sikayet-et-alani').animate({
              'opacity': '0'
            }, 300, 'linear', function() {
              $('.vduzalani, .yorumu-sikayet-et-alani').css('display', 'none');
            });
            swal({
              title: "Bildiriminiz Gönderildi!",
              text: "Teşekkür ederiz.",
              timer: 5000
            });
          }
        });
        return false;
      });
      $('.engelleme-iptal').click(function() {
        close_box22();
      });
    });

    function close_box22() {
      $('.vduzalani, .gizliligi-degistir-alani').animate({
        'opacity': '0'
      }, 300, 'linear', function() {
        $('.vduzalani, .gizliligi-degistir-alani').css('display', 'none');
      });
      $('input[name="gizlisecenek"]').attr('checked', false);
    } */

  /*Bildirimler*/
  /* Notification Scroll Apply
  $('#notifications').slimScroll({height: '380px'});
  var notification_content_height = 380;

  /* Notification Scroll Results 
  $('.notifications').scroll(function(eve){
  var a=0;
  var s=$(document).height() - notification_content_height;
  if(s>128)
  {
  s=128;
  }
  if ($('.notifications').scrollTop() >= s){

  var ID=$(".noti_stbody:last").attr("id");
  var dataString = 'last_time='+ ID ;
  if(a == 0)
  {
  $.ajax({
  type: "POST",
  url: $.base_url+"notifications_more_ajax.php",
  data: dataString,
  cache: false,
  success: function(html){

  if($.trim(html).length>46)
  {
  $("#notifications").append(html);
  }
  else
  {
  $("#notifications").append(html);
  $("#notifications").removeClass('notifications');
  }
  }
  });
  a = 1;
  }
  }
  });*/
// Change Language
  $(function() {
    var i;
    $('.change-language').on('click', function() {
      $('.backbar').animate({
        'opacity': '.50'
      }, 300, 'linear');
      $('.language_wrap').animate({
        'opacity': '1.00'
      }, 300, 'linear');
      $('.backbar, .language_wrap').css('display', 'block');
      //get id
      i = $(this).attr('id');

    });
    //click .report button
    $('.send_this_language').on('click',function(e) {
      e.preventDefault();
      $.ajax({
        type: "POST",
        url: $.base_url + 'change_language.php',
        data: {
          id: i,
          u_lang: $('input[name="u_lang"]:checked').val()
        },
        beforeSend: function() {
          $("#posting").html('<img src="icons/ajaxloader.gif"/>');
        },
        success: function(html) {
          if (html.trim() === "1") {
            window.location.reload();
          } else {
            swal({
              title: "Invalid language selection!",
              text: ":o",
              timer: 4000
            });
          }
        }
      });
      return false;
    });
    $('.go').click(function() {
      close_box11();
    });
  });

  function close_box11() {
    $('.backbar, .language_wrap').animate({
      'opacity': '0'
    }, 300, 'linear', function() {
      $('.backbar, .language_wrap').css('display', 'none');
    });
    $('input[name="report_type"]').attr('checked', false);
  }
  /* Total Notifications Scroll */
  $(window).scroll(function() {
    var X = $("#notification_check").val();
    if (parseInt(X)) {
      var a = 0;
      var B = $("#total_notifications").html();
      if (B.length > 12) {
        if ($(window).scrollTop() == $(document).height() - $(window).height()) {
          var ID = $(".noti_smbody:last").attr("id");
          var dataString = 'last_time=' + ID;
          if (a == 0) {

            $.ajax({
              type: "POST",
              url: $.base_url + "notifications_more_ajax.php",
              data: dataString,
              cache: false,
              success: function(html) {

                if ($.trim(html).length > 46) {
                  $("#total_notifications").append(html);
                } else {
                  $("#total_notifications").append(html);
                  $("#notification_check").val('0');
                }

              }
            });

            a = 1;
          }

        }

      }

    }

  });
  // Change Username text keyup
  $('.inlet_portion').on('keyup', function() {
    var textarea_value = $(".inlet_portion").val();
    if (textarea_value != '') {
      $('.save_button').fadeIn();
    } else {
      $('.save_button').fadeOut();
    }
  });

  $('#SaveUserName').on('click', function(event) {
    event.preventDefault();
    $.ajax({
      type: "POST",
      url: $.base_url + 'changefullname.php',
      data: {
        full_name: $('input[name="full_name"]').val()
      },
      beforeSend: function() {
        $("#posting").html('<img src="icons/ajaxloader.gif"/>');
      },
      success: function(html) {
        $('.UserFullName').show();
        $('.save_button').fadeOut();
        $('.fl').removeClass('ShowAccordion');
        swal({
          title: "Ihr Name wurde erfolgreich geändert !",
          text: "",
          timer: 5000
        });
      }
    });
    return false;
  });
  // Facebook
  $('.inlet_portionF').on('keyup', function() {
    var textarea_value = $(".inlet_portionF").val();
	$(this).val($(this).val().replace(/ +?/g, ''));
    if (textarea_value != '') {
      $('.save_buttonF').fadeIn();
    } else {
      $('.save_buttonF').fadeOut();
    }
  });

  $('#SaveFUserName').on('click', function(event) {
    event.preventDefault();
    $.ajax({
      type: "POST",
      url: $.base_url + 'changefbname.php',
      data: {
        s_fb: $('input[name="s_fb"]').val()
      },
      beforeSend: function() {
        $("#posting").html('<img src="icons/ajaxloader.gif"/>');
      },
      success: function(html) {
        $('.UserFullName').show();
        $('.save_button').fadeOut();
        $('.fl').removeClass('ShowAccordion');
        swal({
          title: "Wurde geändert ",
          text: "",
          timer: 5000
        });
      }
    });
    return false;
  });
  // Twitter
  $('.inlet_portiontwi').on('keyup', function() {
    var textarea_value = $(".inlet_portiontwi").val();
	$(this).val($(this).val().replace(/ +?/g, ''));
    if (textarea_value != '') {
      $('.save_buttontwi').fadeIn();
    } else {
      $('.save_buttontwi').fadeOut();
    }
  });

  $('#SaveTUserName').on('click', function(event) {
    event.preventDefault();
    $.ajax({
      type: "POST",
      url: $.base_url + 'changetwname.php',
      data: {
        s_tw: $('input[name="s_tw"]').val()
      },
      beforeSend: function() {
        $("#posting").html('<img src="icons/ajaxloader.gif"/>');
      },
      success: function(html) {
        $('.UserFullName').show();
        $('.save_buttontwi').fadeOut();
        $('.fl').removeClass('ShowAccordion');
        swal({
          title: "Wurde geändert ",
          text: "",
          timer: 5000
        });
      }
    });
    return false;
  });
  // Tumblr
    $('.inlet_portiontumb').on('keyup', function() {
    var textarea_value = $(".inlet_portiontumb").val();
	$(this).val($(this).val().replace(/ +?/g, ''));
    if (textarea_value != '') {
      $('.save_buttontumb').fadeIn();
    } else {
      $('.save_buttontumb').fadeOut();
    }
  });

  $('#SaveTUUserName').on('click', function(event) {
    event.preventDefault();
    $.ajax({
      type: "POST",
      url: $.base_url + 'changetumbname.php',
      data: {
        s_tumb: $('input[name="s_tumb"]').val()
      },
      beforeSend: function() {
        $("#posting").html('<img src="icons/ajaxloader.gif"/>');
      },
      success: function(html) {
        $('.UserFullName').show();
        $('.save_buttontumb').fadeOut();
        $('.fl').removeClass('ShowAccordion');
        swal({
          title: "Wurde geändert ",
          text: "",
          timer: 5000
        });
      }
    });
    return false;
  });
  // Google Plus
    $('.inlet_portiongp').on('keyup', function() {
    var textarea_value = $(".inlet_portiongp").val();
	$(this).val($(this).val().replace(/ +?/g, ''));
    if (textarea_value != '') {
      $('.save_buttongp').fadeIn();
    } else {
      $('.save_buttongp').fadeOut();
    }
  });

  $('#SaveGPUserName').on('click', function(event) {
    event.preventDefault();
    $.ajax({
      type: "POST",
      url: $.base_url + 'changegpid.php',
      data: {
        s_gp: $('input[name="s_gp"]').val()
      },
      beforeSend: function() {
        $("#posting").html('<img src="icons/ajaxloader.gif"/>');
      },
      success: function(html) {
        $('.UserFullName').show();
        $('.save_buttongp').fadeOut();
        $('.fl').removeClass('ShowAccordion');
        swal({
          title: "Wurde geändert ",
          text: "",
          timer: 5000
        });
      }
    });
    return false;
  });
  // Youtube
   $('.inlet_portionyout').on('keyup', function() {
    var textarea_value = $(".inlet_portionyout").val();
	$(this).val($(this).val().replace(/ +?/g, ''));
    if (textarea_value != '') {
      $('.save_buttonyout').fadeIn();
    } else {
      $('.save_buttonyout').fadeOut();
    }
  });

  $('#SaveYOUUserName').on('click', function(event) {
    event.preventDefault();
    $.ajax({
      type: "POST",
      url: $.base_url + 'changeyoutubeid.php',
      data: {
        s_yout: $('input[name="s_yout"]').val()
      },
      beforeSend: function() {
        $("#posting").html('<img src="icons/ajaxloader.gif"/>');
      },
      success: function(html) {
        $('.UserFullName').show();
        $('.save_buttonyout').fadeOut();
        $('.fl').removeClass('ShowAccordion');
        swal({
          title: "Wurde geändert ",
          text: "",
          timer: 5000
        });
      }
    });
    return false;
  });
  // Instagram
    $('.inlet_portioninst').on('keyup', function() {
    var textarea_value = $(".inlet_portioninst").val();
	$(this).val($(this).val().replace(/ +?/g, ''));
    if (textarea_value != '') {
      $('.save_buttoninst').fadeIn();
    } else {
      $('.save_buttoninst').fadeOut();
    }
  });

  $('#SaveINSUserName').on('click', function(event) {
    event.preventDefault();
    $.ajax({
      type: "POST",
      url: $.base_url + 'changeinstaid.php',
      data: {
        s_inst: $('input[name="s_inst"]').val()
      },
      beforeSend: function() {
        $("#posting").html('<img src="icons/ajaxloader.gif"/>');
      },
      success: function(html) {
        $('.UserFullName').show();
        $('.save_buttoninst').fadeOut();
        $('.fl').removeClass('ShowAccordion');
        swal({
          title: "Wurde geändert ",
          text: "",
          timer: 5000
        });
      }
    });
    return false;
  });
  // Change User Info
  $('.caseText').on('keyup', function() {
    var textarea_value = $(".caseText").val();
    if (textarea_value != '') {
      $('.save_buttonUI').fadeIn();
    } else {
      $('.save_buttonUI').fadeOut();
    }
  });
  $('#SaveUserCase').on('click', function(e) {
    e.preventDefault();
    $.ajax({
      type: "POST",
      url: $.base_url + 'case_ajax.php',
      data: {
        user_case: $('#case').val()
      },
      beforeSend: function() {
        $("#posting").html('<img src="icons/ajaxloader.gif"/>');
      },
      success: function(html) {
        $('.Ucase').show();
        $('.save_buttonUI').fadeOut();
        swal({
          title: "Ihre Informationen wurden aktualisiert !",
          text: "",
          timer: 5000
        });
      }
    });
    return false;
  });
  // User Birthday
  $(function() {
    $("#userbirthday, #usermounth, #useryear").on("change", function() {
      if ($(this).val() != '') {
        $("#SaveUserBirth").show();
      } else {
        $("#SaveUserBirth").hide();
      }
    });
  });
    $('#SaveUserBirth').on('click', function(e) {
    e.preventDefault();
    $.ajax({
      type: "POST",
      url: $.base_url + 'user_birthday.php',
      data: {
        b_day: $('#userbirthday').val(),
		u_month: $('#usermounth').val(),
		u_year: $('#useryear').val()
      },
      beforeSend: function() {
        $("#posting").html('<img src="icons/ajaxloader.gif"/>');
      },
      success: function(html) {
		  if(html.trim() === "1") {
					$.notifyBar({ html: "Wurde geändert ", position: "bottom" });
					$("#SaveUserBirth").fadeOut();
                    $('.set_parts').removeClass('ShowAccordion');
					} else{
						$.notifyBar({ html: "Wurde nicht geändert", position: "bottom" });
						$("#SaveUserBirth").fadeOut();
                        $('.set_parts').removeClass('ShowAccordion');
						}
				
        
        
      }
    });
    return false;
  });
  // Change Country
  $(function() {
    $("#usercity").on("change", function() {
      if ($(this).val() != '') {
        $("#SaveUserCity").show();
      } else {
        $("#SaveUserCity").hide();
      }
    });
  });
  $('#SaveUserCity').on('click', function(e) {
    e.preventDefault();
    $.ajax({
      type: "POST",
      url: $.base_url + 'usercity.php',
      data: {
        user_city: $('#usercity').val()
      },
      beforeSend: function() {
        $("#posting").html('<img src="icons/ajaxloader.gif"/>');
      },
      success: function(html) {
        $("#SaveUserCity").fadeOut();
        $('.set_parts').removeClass('ShowAccordion');
        swal({
          title: "Ihr Wohnort wurde geändert !",
          text: "",
          timer: 5000
        });
      }
    });
    return false;
  });
  //User Password
  $(document).on('click', '.OpenUserPassWordPorsion', function(event) {
      event.preventDefault();
      var ChangeUserFullName = $(this).data('change-name');
      $('.Upass').hide();
      $('.ShowSetPart' + ChangeUserFullName).addClass('ShowAccordion');
      $('#SaveUserPass').click(function(e) {
        e.preventDefault();
        $.ajax({
          type: "POST",
          url: $.base_url + 'ChangePassWord_ajax.php',
          data: {
            oldpassword: $('#oldpassword').val(),
            newpassword: $('#newpassword').val(),
            cpassword: $('#cpassword').val()
          },
          beforeSend: function() {
            $("#posting").html('<img src="icons/ajaxloader.gif"/>');
          },
          success: function(html) {
            $('.Upass').show();
            $('.set_parts').removeClass('ShowAccordion');
            swal({
              title: "Ihr Passwort wurde geändert !",
              text: "",
              timer: 5000
            });
          }
        });
        return false;
      });
    })
    .on('click', '.cpa', function(event) {
      event.preventDefault();
      $('.Upass').show();
      $(this).closest('.cps').removeClass('ShowAccordion');
    });
  $('.pr_icon').on('click', function(e) {
    // Change Post Privacy
    if ($(this).attr('class') == 'pr_icon first_click') {
      $('.first_click_content').children().show();

    } else {
      $('.second_click_content').children().show();
    }
  });
  // Follower Privacy
  $(function() {
    $('.secur').on('click', function() {
      $('.gkayt').hide();
      $('.gkiptl').hide();
      $(this).parents('.set_partsInput').find('.gkayt').show();
      $(this).parents('.set_partsInput').find('.gkiptl').show();

      $('.tagiz').click(function(e) {
        e.preventDefault();
        $.ajax({
          type: "POST",
          url: $.base_url + 'privacy_follower.php',
          data: {
            hide_followers: $('input[name="hide_followers"]:checked').val()
          },
          beforeSend: function() {
            $("#posting").html('<img src="icons/ajaxloader.gif"/>');
          },
          success: function(html) {
            if (html.trim() === "1") {
              $('.gkayt').hide();
              $('.gkiptl').hide();
              swal({
                title: "Ihre Datenschutzeinstellungen wurden gespeichert ",
                text: ":)",
                timer: 5000
              });
            } else {
              swal({
                title: "Privatsphäre-Einstellungen enthält ungültige Ausdrücke",
                text: ":o",
                timer: 5000
              });
            }
          }
        });
        return false;
      });
    });
    $('.gkiptl').on('click', function() {
      $(this).parents('.set_partsInput').find('.gkayt').hide();
      $(this).parents('.set_partsInput').find('.gkiptl').hide();
    });
  // Following Privacy
  $(function() {
      $('.secur').on('click', function() {
        $('.gkayt').hide();
        $('.gkiptl').hide();
        $(this).parents('.set_partsInput').find('.gkayt').show();
        $(this).parents('.set_partsInput').find('.gkiptl').show();

        $('.patagiz').on('click', function(e) {
          e.preventDefault();
          $.ajax({
            type: "POST",
            url: $.base_url + 'privacy_following.php',
            data: {
              hide_following: $('input[name="hide_following"]:checked').val()
            },
            beforeSend: function() {
              $("#posting").html('<img src="icons/ajaxloader.gif"/>');
            },
            success: function(html) {
              if (html.trim() === "1") {
                $('.gkayt').hide();
                $('.gkiptl').hide();
                swal({
                  title: "Ihre Datenschutzeinstellungen wurden gespeichert",
                  text: ":)",
                  timer: 5000
                });
              } else {
                swal({
                  title: "Privatsphäre-Einstellungen enthält ungültige Ausdrücke",
                  text: ":o",
                  timer: 5000
                });
              }
            }
          });
          return false;
        });
      });
      $('.gkiptl').on('click', function() {
        $(this).parents('.set_partsInput').find('.gkayt').hide();
        $(this).parents('.set_partsInput').find('.gkiptl').hide();
      });
    });
  // Photos Privacy
  $(function() {
      $('.secur').on('click', function() {
        $('.gkayt').hide();
        $('.gkiptl').hide();
        $(this).parents('.set_partsInput').find('.gkayt').show();
        $(this).parents('.set_partsInput').find('.gkiptl').show();

        $('.apagiz').on('click',function(e) {
          e.preventDefault();
          $.ajax({
            type: "POST",
            url: $.base_url + 'privacy_photos.php',
            data: {
              hide_photos: $('input[name="hide_photos"]:checked').val()
            },
            beforeSend: function() {
              $("#posting").html('<img src="icons/ajaxloader.gif"/>');
            },
            success: function(html) {
              if (html.trim() === "1") {
                $('.gkayt').hide();
                $('.gkiptl').hide();
                swal({
                  title: "Ihre Datenschutzeinstellungen wurden gespeichert",
                  text: ":)",
                  timer: 5000
                });
              } else {
                swal({
                  title: "Privatsphäre-Einstellungen enthält ungültige Ausdrücke",
                  text: ":o",
                  timer: 5000
                });
              }
            }
          });
          return false;
        });
      });
      $('.gkiptl').on('click', function() {
        $(this).parents('.set_partsInput').find('.gkayt').hide();
        $(this).parents('.set_partsInput').find('.gkiptl').hide();
      });
    });
  // Privacy May Know People
  $(function() {
      $('.secur').on('click', function() {
        $('.gkayt').hide();
        $('.gkiptl').hide();
        $(this).parents('.set_partsInput').find('.gkayt').show();
        $(this).parents('.set_partsInput').find('.gkiptl').show();

        $('.msagiz').on('click', function(e) {
          e.preventDefault();
          $.ajax({
            type: "POST",
            url: $.base_url + 'privacy_maynowpeople.php',
            data: {
              hide_maynow_people: $('input[name="hide_maynow_people"]:checked').val()
            },
            beforeSend: function() {
              $("#posting").html('<img src="icons/ajaxloader.gif"/>');
            },
            success: function(html) {
              if (html.trim() === "1") {
                $('.gkayt').hide();
                $('.gkiptl').hide();
                swal({
                  title: "Ihre Datenschutzeinstellungen wurden gespeichert",
                  text: ":)",
                  timer: 5000
                });
              } else {
                swal({
                  title: "Privatsphäre-Einstellungen enthält ungültige Ausdrücke",
                  text: ":o",
                  timer: 5000
                });
              }
            }
          });
          return false;
        });
      });
      $('.gkiptl').on('click', function() {
        $(this).parents('.set_partsInput').find('.gkayt').hide();
        $(this).parents('.set_partsInput').find('.gkiptl').hide();
      });
    });
  //people explore
  $('body').on("click", '.devamigs', function(event) {
      event.preventDefault();
      var ID = $(this).attr("id");
      var URL = $.base_url + 'explore_ajax.php';
      var dataString = "lastuid=" + ID;
      if (ID) {
        $.ajax({
          type: "POST",
          url: URL,
          data: dataString,
          cache: false,
          beforeSend: function() {
            $(".paylasiliyor").fadeIn(100);
          },
          success: function(html) {
            $("div.global-main-container").append(html);
            $(window).load();
            $("#more" + ID).remove();
          }
        });
      } else {
        $("#more").html('The End'); // no results

      }

      return false;
    });
  });  
  // Change Gender
  $('.changeGender').on('click', function(event){
	event.preventDefault();
	$.ajax({
		type: "POST",
		url: $.base_url + 'changeGender.php',
		data:{gender: $("input[name='gender']:checked").val()},
		beforeSend: function(){
			$.notifyBar({ html: ".....", position: "bottom" });
			},
			success:(function(html) {
				if(html.trim() === "1") {
					$.notifyBar({ html: "Wurde geändert ", position: "bottom" });
					} else{
						$.notifyBar({ html: "Wurde nicht geändert", position: "bottom" });
						}
				})
		});  
  });
  
});