/*#	我的js	#*/

function btn_login_click(){
	username	 =	 $.trim( $('#username').val() )	;
	password	 =	 $.trim( $('#password').val() )	;
	
	if (username=='')
	{
		alert('请输入用户名')	 ;
	}else if (password=='')
	{
		alertr('请输入密码')	;
	}else {
		post_data	 =	 new Object()	;
		post_data.username	=	username	 ;
		post_data.password	=	password	 ;
		post_data.act				=	'login'	;

		$('#btn_login').attr('disabled','disabled')	 ;
		$('#btn_reset').attr('disabled','disabled')	;

		$.post(BASE_URL+'login.php',post_data,function(row){

			if ( $.trim(row.msg)!='' ) {
				alert(row.msg)	 ;
				$('#btn_login').attr('disabled','')	 ;
				$('#btn_reset').attr('disabled','')	;
			}else {
				alert('登录成功！')	 ;
				$('#not_login').css('display','none')	 ;
				$('#logined').css('display','block')	;
				$('#hide_js').html( row.js )	;
				$('#logined_user').text( row.name )	;

			}
		},'json')	;
	}
	
	return false	;
}//-- end of function `btn_login_click`

function btn_logout_click() {
	if ( confirm('确定要退出吗？') ) {
	
		post_data	=	new Object()	;
		post_data.act	=	'logout'	 ;

		$.post(BASE_URL+'login.php',post_data,function(result){
			alert('退出成功！')	 ;
			$('#logined').css('display','none')	;
			$('#not_login').css('display','block')	 ;
			$('#hide_js').html( result.js )	;

		},'json')	;

	}
}//-- end of function `btn_logout_click`

function reset_body_img() {

	//--------------------------------
	//	修正新闻图片宽度
	//--------------------------------
	$('.body').find('img').each(function(){
		w	=	$(this).width()	;
		if ( w>600 ) {
			$(this).width(600)	;
			$(this).height( 600/w*$(this).height() )	;
			$(this).click(function(){
				window.open($(this).attr('src'))	;
			})	;
			$(this).mouseover(function(){
				$(this).css('cursor','hand')	;
			})	;
		}
	})	;
}

$(function(){

	reset_body_img()	;

	//-------------------------------
	//	修正链接路径
	//-------------------------------
	$('a.fix').each(function(){
		if ( $(this).attr('href')=='#' )	{
			$(this).attr('href' , window.location+'#')	;
		}else {
			$(this).attr('href' , BASE_URL+$(this).attr('href'))	 ;
		}
	})	;

	//----------------------------------
	//	ajax读取文章内容
	//----------------------------------
	$('a.ld').each(function(){
		$(this).click(function(){
			url	=	BASE_URL+'load_data.php?id='+parseInt($(this).attr('refid'))	;
			$.get(url,function(html){
				$('#load_data').html( html )	;
				reset_body_img()	;
			})	;
		})	;
	})	;

	//------------------------------
	//	判断登录
	//------------------------------
	$.getJSON(BASE_URL+'login.php',function(data){
		id	=	parseFloat( data.id )	;
		if (id>0)	{
			$('#logined').css('display','block')	;
			$('#logined_user').text( data.name )	;
		}else {
			$('#not_login').css('display','block')	 ;
		}

	})	;

	$('#btn_login').click(function(){
		btn_login_click()	;
		return false;
	})	;
		
	$('#btn_logout').click(function(){
		btn_logout_click()	;
		return false;
	})	;

})	;
