$().ready(function() {
    var options = {
	callback:watchnickfind,//function(){ alert("changed search text"); },
        wait:750,          
	highlight:true,     // highlight text on focus
	enterkey:true     // allow "Enter" to submit data on INPUTs
    }
    
    function watchnickfind()
    {
//	alert('HH');
	$('#cover').show();
        $.post(URLFIND,{
	    reqlogin: $("#nickfind").attr('value')
         },function(txt){
//	 $('#tags'+$('.openedtab').attr('id').replace(/open/,''));
//	    $('#realtags').html(txt);
$('#tags'+$('.openedtab').attr('id').replace(/open/,'')).html(txt);
	    $('#cover').hide();
       });
    }
    
    $('#gonickfind').click(watchnickfind);
    $("#nickfind").typeWatch( options );
    defaultnickfind = $('#nickfind').attr('value');
	
    $('#nickfind').focus(function (){
        if ($(this).attr('value') == defaultnickfind)
            $(this).attr('value', '');
    }).blur(function (){
        if (!$(this).attr('value'))
            $(this).attr('value', defaultnickfind);
    });
    
    $('#nickfind').keypress(function (e){ if (e.which == 13)  $('#gonickfind').click(); });
			  
    $('#wantinvite').click(function() {    
	$('#coverglow').attr('src', '/images/blogs_invite_glow.png').attr('width', '154').attr('height', '113');
	$('#closecover').show();
	$('#cover').show();
	$('#invitecode').load(URLINVITE, {}, function() { 
	    $('#covertext').html(''); 
	});
	return false;
    });
    $('#closecover').click(function (){
	    $('#covertext').html('Loading...'); 
	    $('#coverglow').attr('src', '/images/blogs_glow2.png').attr('width', '87').attr('height', '113'); 
	    $('#closecover').hide(); 
	    $('#invitecode').text('');
	    return false;
    });
    $("a").click(function () {
       if ($(this).parent().attr('class') != 'tab') return true;
       tmpcurrid = $(this).attr('id');
       $(".tagstab").each(function (){
	var tgcurr = "#tags"+tmpcurrid.replace(/open/, '');

        if ($(this).css("display") == "block" && $(this).attr('id') != tgcurr.replace(/#/, ''))
	{
	$('#cover').show();
	$.post(URLTAGSTAB, { tab: tgcurr.replace(/#/, '') }, function (txt){
	    $(tgcurr).html(txt);
	    $('#cover').hide();
	});
//	      alert('#tab'+$(this).attr('id').replace(/tagstab/, '')+'open');
//	      alert("#tags"+tmpcurrid.replace(/open/, ''));
	    $("#"+tmpcurrid).toggleClass("openedtab");
	    $('#tab'+$(this).attr('id').replace(/tagstab/, '')+'open').toggleClass("openedtab");
	    $("#tags"+tmpcurrid.replace(/open/, '')).css("display","block");
            $(this).css("display","none");
	}
       });
       return false;
    });
									      
});
