$(document).ready(function(){

	$('#inputField').bind("blur focus keydown keypress keyup", function(){recount();});
	$('input.submitButton').attr('disabled','disabled');

	$('#tweetForm').submit(function(e){

		tweet();
		e.preventDefault();

	});

});

function recount()
{
	var maxlen=800;
	var words='what are you up to';/*you must not submit this word*/
	/*var showmg='You have exceeded the limit of Text..not more then 800 words';error message*/
	var current= maxlen-$('#inputField').val().length;
	/*var error='text is too long';*/
	var message=$('#inputField').val();
	$('.counter').html(current);
	
	
	/*
     if(message==words){
	   $(".counter").remove();
	  $('input.submitButton').attr('disabled','disabled').addClass('inact');
	 
	 }*/
		
	if(current==maxlen||message==words||current<=0)
	{
		//$('.counter').css('color','#D40D12');
		$('.showerror').css('color','#D40D12');
		$('input.submitButton').attr('disabled','disabled').addClass('inact');
		 
	}
	else{
		$('input.submitButton').removeAttr('disabled').removeClass('inact');
     }
     if(current<10){
		$('.counter').css('color','#5C0002');
	}
	 else{
		$('.counter').css('color','#cccccc');
		
	}
}

$(function() {
$("#sendmafeeds").click(function() {

        //var element = $(this);
   
      //var receiverid= $(".useridname").val();
      var comment= $("#inputField").val();
	  var foundin = $('*:contains("what are you up to")');
      //var dataString = 'comment='+ comment + '&profid=' + receiverid;
	  var dataString = 'status='+ comment;
	  
	if(comment=='')
	{
	 
	alert("Please Enter Some Text to post status");
	
	}
	else
	{
	$("#showwhatareudoing").show();
	$("#showwhatareudoing").fadeIn(400).html('<img src="img/ajax-loader.gif" align="absmiddle">&nbsp;<span class="loading">Loading Update...</span>');
$.ajax({
		type: "POST",
        url: "submitwhatareudoing.php",
        data: dataString,
       cache: false,
      success: function(html){
     $("ol#myfeed").prepend(html);
     //$("ol#myfeed li:first").fadeIn(500);
	//$("ol#myfeed li:second").slideDown('slow')
	// $("ol#myfeed li:second").fadeOut(500);
	 $("ol#myfeeda li:first").fadeIn(500);
	 $("#showwhatareudoing").remove();
	 
     //$("ol#myfeed").fadeOut(500);

	  $('#sendmafeeds').attr('disabled','disabled').addClass('inact');
	  $("#inputField").val("");
  // document.getElementById('content').value='';
  // $('#content').value='';
  // $('#content').focus();
   //$("#loadplace").append(html);
    
  //$('#sendmafeeds').attr('disabled','disabled').addClass('inact');//disable the submit button
    
	//$("#expand_url").oembed(boxval);
	
  }
 });
}
	return false;
	});

	});

/*
function tweet()
{
	var submitData = $('#tweetForm').serialize();
	
	$('.counter').html('<img src="img/ajax_load.gif" width="16" height="16" style="padding:12px" alt="loading" />');
	
	$.ajax({
		type: "POST",
		url: "submitwhatareudoing.php",
		data: submitData,
		dataType: "html",
		success: function(msg){
			
			if(parseInt(msg)!=0)
			{
			     $("#close").remove();
				$('ul.statuses li:first-child').before(msg);
				$("ul.statuses:empty").append(msg);
				
				$('#lastTweet').html($('#inputField').val());
				
				$('#inputField').val('');
				$("#fortime").remove();
				$(".view_comments").remove();
				
				
				recount();
			}
		}
		
	});
}*/

/*video upload here*/
 $(function() {
$("#videopost").click(function() {

        //var element = $(this);
      var check=1;
      var videourl=$("#videourl").val();
      var title=$("#title").val();
	  var dataString = 'videourl='+ videourl + '&title=' + title +'&videopost=' + videopost+'&check=' + check;
	if(videourl==''||title=='')
	{
	alert("title or video url should not be empty");
	
	}
	else
	{
	$("#flash").show();
	$("#flash").fadeIn(400).html('<img src="img/ajax-loader.gif" align="absmiddle">&nbsp;<span class="loading">uploading video..</span>');
$.ajax({
		type: "POST",
        url: "uploadvideo.php",
        data: dataString,
       cache: false,
      success: function(html){
    $("#videosdisplay").append(html);
    $("#flash").hide();
	$("#videourl").val("");
     //location.reload();
    
	//$("#expand_url").oembed(boxval);
	
  }
 });
}

	return false;
	});

	});

