// JavaScript Document

	function shift() {
        var toShow = (i + showing) % count;
        $('#recent'+toShow).slideDown(1000, move(i));
        $('#recent'+i).slideUp(1000, move(i));
        i = (i + 1) % count;
        setTimeout('shift()', delay);
      }    
    
//////////////////////////////////////////////////////////////////////////////////////////
// code for  plurk functionalities 

 function expanddiv(el) {
 			//alert("expand div is called");
         	  el.style.height= 'auto';
			   el.style.width='auto';
		    el.style.overflow = "visible";
			
			
        }
 function compressdiv(el) {
 			//alert("compress div is called");
            el.style.overflow = "hidden";
			 el.style.height= '30px';
			 el.style.width='300px';
        }

function getMoreMicroblogs(uid,start,limit,addedin_type,read_status){
	//alert("working");
	 var calling_page='get_microblog.php';
	 if ( addedin_type === undefined ) {
     	addedin_type = 'all';
  	 }
	 if(read_status=='unread'){
		calling_page='get-unread-microblog.php';		 
	 }
	 //alert(calling_page);
	$.ajax({
	   type: "GET",
	   url: calling_page,
	   data: "uid="+uid+"&start="+start+"&limit="+limit+"&addedin_type="+addedin_type,
	   success: function(msg,addedin_type){
     		
			if(addedin_type=='my')
				$("#ui-tabs-2").html(msg);
			else if(addedin_type=='like')
					$("#ui-tabs-5").html(msg);
			else if(addedin_type=='contribute')
					$("#ui-tabs-4").html(msg);
			else if(addedin_type=='private')
				$("#ui-tabs-3").html(msg);
			else
				$("#ui-tabs-1").html(msg);
			  $('a[rel*=facebox]').facebox() ;	
			
  		}
	   
	 });
	
}

function like_unlike(uid,microblog_id,like_status,addedin_type){
	 if ( addedin_type === undefined ) {
     	addedin_type = 'all';
	}
	// this condition is to show and hide like icon immediately
	var added_tab=getAddedTab(addedin_type);
	$.ajax({
	   type: "GET",
	   url: "like_unlike_status.php",
	   data: "uid="+uid+"&microblog_id="+microblog_id+"&like_status="+like_status+"&addedin_type="+addedin_type,
	   success: function(msg){
     		//alert(addedin_type);
			$('#'+added_tab +' #like_unlike'+microblog_id).html(msg);
			if(like_status){
					$('#'+added_tab +' #like_icon'+microblog_id).show();	
				}else{
					$('#'+added_tab +' #like_icon'+microblog_id).hide();
				}
	  	}
	   
	 });
}

/*function getResponses(uid,microblog_id){

	$.ajax({
	   type: "GET",
	   url: "responses.php",
	   data: "uid="+uid+"&microblog_id="+microblog_id,
	   success: function(msg){
     		alert(msg);
			$("#mic_blog"+microblog_id).html(msg);
  		}
	   
	 });

}*/

function deleteMicroblog(microblog_id,added_type){
	var added_tab=getAddedTab(added_type);
	if(confirm("Are you sure you want to delete your Dialog?"))
	{
		$.ajax({
		   type: "GET",
		   url: "edit_microblog.php",
		   data: "action=deletion&microblog_id="+microblog_id,
		   success: function(msg){
			//	alert(msg);
				//$("#mic_blog"+microblog_id).html(msg);
				if(msg=='deleted')
					$('#'+added_tab +' #microblog_'+microblog_id ).hide(1000);
					
					
			}
		   
		 });
	}

}

function commentMicroblog(microblog_id,added_type){
	//alert("We are working on this section "+microblog_id);
	$('#'+getAddedTab(added_type) +' #comment_form'+microblog_id ).toggle();
	$('#'+getAddedTab(added_type)+' #comment_text'+microblog_id).focus();

}
function insertComment(microblog_id,added_type)
{
	var added_tab=getAddedTab(added_type);
	var comment=$('#'+added_tab+' #comment_text'+microblog_id).val();
	if(jQuery.trim(comment).length>0)
	{//alert("mid"+microblog_id+", comment"+comment);
		$.ajax({
			   type: "POST",
			   url: "edit_microblog.php",
			   data: "microblog_id="+microblog_id+"&comment="+escape(comment),
			   success: function(msg){
				//	alert(msg);
					$('#'+added_tab +' #comment_form'+microblog_id ).hide();
					$('#'+added_tab +' #microblog_'+microblog_id ).append(msg);
				}
			   
			 });
	 }else{
	 alert("please enter the text");
	 }
	return false;
}

function getAddedTab(added_type){
	switch(added_type)
	{
		case 'response':
			blog_container='ui-tabs-4 ';
			break;
		case 'like':
			blog_container='ui-tabs-5 ';
			break;
		case 'private':
			blog_container='ui-tabs-3';
			break;
		case 'my':
			blog_container='ui-tabs-2';
			break;
		default:
			blog_container='ui-tabs-1';
			break;
	}
	sPath = window.location.pathname;
	sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	if(sPage=='sample_home.php')
		return blog_container;
	else
		return 'ui-tabs-1';
}

function deleteComment(comment_id,added_type)
{
	//alert(comment_id);
	var added_tab=getAddedTab(added_type);
	$.ajax({
		   type: "POST",
		   url: "edit_microblog.php",
		   data: "comment_id="+comment_id+"&action=delete_comment",
		   success: function(msg){
			//	alert(msg);
				$('#'+added_tab +' #comment'+comment_id ).hide();
			//	$('#'+added_tab +' #microblog_'+microblog_id ).append(msg);
			}
		   
		 });

}

function showUserSuggestions(){
	
	
		$('#private_suggestions').toggle("slow");
	
}


function validate_micro(){
	var str=$('#comment_text_main').val();
	var len=str.length;
	
	if(len > 150 )
	{
		alert("150 characters are allowed");
		return false;
	}
	else if(jQuery.trim(str).length==0)
	{
		//alert("Please enter the text");
		return false;
	}
	
}
		
function showCountry(cnt_name,sel_item)
{
	//alert(cnt_name);
	$('#cnt_name').toggle();
	
}
function hide_dummy()
{
	$('.dummy').hide();
	$('.form_box2').show();
	$('#comment_text_main').focus();
}
function show_dummy()
{
	$('.dummy').show();
	$('.form_box2').hide();
}

function toggle_desc()
{
	$('#full_desc').toggle();
	
	//$('#short_desc').toggle();
}
// for toggle the div of contest section
function toggle_div1(div1,div2){
	document.getElementById(div2).style.display='none';
	if(document.getElementById(div1).style.display=='none'){
		$('#'+div1).animate({ opacity: 'toggle'	}, 1200);
	}
	document.getElementById(div1+'_a').className="current";
	document.getElementById(div2+'_a').className="";
}

