﻿$(document).ready(function(){
	  var init=function(){
	  	$('.a-info').each(function(){
		  		$(this).click(function(){
		  		p = $(this).parent().parent();
		  		$(p).find('.details').slideToggle('slow');
	  	  });
	    })
	    
	   
	   $('.autocomplete').keydown(function(e) {
            switch (e.keyCode) {
                case 13:
    
                    if (this.id == 'big-ass-search') {
                        var location = '/tag/' + this.value;
                        window.location = location;
                    }

                    return false;
                    break;
            }

        });
        
        $('.add_tags').keyup(function(){
       	  	 settweet();
       	})
       	  	
       $('#go-add-tags').click(function(){
       	  b=1;
       	  for(i=1;i<=3;i++){
       	  	$('#tag-'+i).click(function(){
       	  	  $(this).val('');
       	  	  $(this).parent().find('span').hide();	
       	  	})
       	  	
       	  	
       	    v = $('#tag-'+i).val();
       	    if($.trim(v)==''){
       	    	$('#tag-'+i).parent().find('span').show();
       	    	b=0;
       	    }
       	    else{
       	    	$('#tag-'+i).parent().find('span').hide();
       	    }		
       	  }
       	  if(b==0){
            return false;
          }
          
          vv = $('#add-tweet').val();
          if(vv && vv.length>140){
             alert('hey!tweet>140');
             return false;	
          }	
          
          
          return true;
       	
       })

	  }
	  
	  var settweet=function(){
	    o = $('#mytweet').val();
	    v1 = ' #'+$('#tag-1').val();
	    v2 = ' #'+$('#tag-2').val();
	    v3 = ' #'+$('#tag-3').val();
	    o = o +' 标签:'+v1+ v2+ v3
	    $('#add-tweet').attr('value',o);
	    
	  }
	  init();
	  settweet();
});