// JavaScript Document
$(document).ready(function() {
	
	function Get_Cookie(name) {
					var a_ac=document.cookie.split( ';' ),a_tc='',cn='',cv='',b_cf=false;
					for ( i = 0; i < a_ac.length; i++ )
					{
						a_tc = a_ac[i].split( '=' );
						cn = a_tc[0].replace(/^\s+|\s+$/g, '');
						if ( cn == name )
						{
							b_cf = true;
							if ( a_tc.length > 1 )
							{
								cv = unescape( a_tc[1].replace(/^\s+|\s+$/g, '') );
							}
							return cv;
							break;
						}
						a_tc = null;
						cn = '';
					}
					if ( !b_cf )
					{
						return null;
					}
				}
				
	var pm='pMode1';

	$('#pMode a').each(function(){
		if($(this).attr('id')){
			var id=$(this).attr('id').substr(1);
			var tgt="pMode"+id;
			if($('#'+tgt).attr('class')!='hide'){pm=tgt}
			
			var file=new Array();
			file[1]="panel-wall.php";
			file[2]="panel-profile.php";
			file[3]="panel-logbook.php";
			var toLoad="internal/"+file[id]+"?id="+Get_Cookie('userIdPabi')+"&uid="+$(this).attr('href');
			
			$(this).click(function(){
				if(tgt!=pm){
					//$('#'+tgt).append('<div id="load"><div class="contentBox">Loading...</div><hr/></div>');
					$('#loading').fadeIn('normal')
					$('#'+pm).hide('normal',loadContent())
					$('#p'+(pm.substr(5))).removeClass();
					$('#p'+(tgt.substr(5))).addClass("selected");
					pm=tgt;
				}
				return false;
			})
			function loadContent() {
				if(tgt!='pMode1'){
				$('#'+tgt).load(toLoad,'',function(){
					$('#'+tgt).show('normal');
				})
				} else {
					$('#'+tgt).show('normal');
				}
				$('#loading').fadeOut('fast')
			}
			
		}
	})
	function logBook(){
		alert('ok')
	}
	$('#messageTo').change(function(){
		$('#messageTo2').html('');
		$('#messageTo2').append(' <small>loading...</loading>');
		$('#messageTo2').load('internal/message.php?pabi='+this.value);
	});
	$('#replay').click(function(){
		$(this).hide('fast');
		$('#replayForm').slideDown('normal',function(){$('#submit').focus()});
		return false;
	});
})