/**	   
*
*   这里很乱。谢绝参观！
*   by leosio 2009-1-13	 
*
*/
	
	$().ready(function(){
		$('input,select,button,submit').not(':hidden').each(function(){
			$(this).addClass($(this).attr('type'));
		});
	});

	function getType(o) {
		var _t; return ((_t = typeof(o)) == "object" ? o==null && "null" || Object.prototype.toString.call(o).slice(8,-1):_t).toLowerCase();
	}

    function dump(obj){
		for(var i in obj){
			console.info(i+'=>'+obj[i]);
		}
    }

	function u(path){
		var loc = window.location;
		var url = "http://"+loc.hostname+"/";
		return url+path;
	}

	$(document).ready(function(){
		resizeimg();
		$('.comments').hover(
			function(){
				$(this).attr('id','showstatus');
			},
			function(){
				$(this).removeAttr('id');
			}
		);

		$('#screen-set').click(function(){
			var viewmode = $.cookie('viewmode');
			if(viewmode == 'fullwide'){
				$('#wrapper').animate({width:'960px'});
				viewmode = 'normal';
				$(this).html('全宽');
			}else{
				$('#wrapper').animate({width:'96%'});	
				viewmode = 'fullwide';	  
				$(this).html('正常');
			}
			$.cookie('viewmode', viewmode, {expires:365});
		});

	});

	$(window).resize(function(){
		resizeimg();
	});

	function log(msg) {
		if (window.console && window.console.log)
			window.console.log(msg);
	};

	function resizeimg(){
		var wid=$('.post').width();
		$('.post img').each(function(){
			var curw=$(this).width();
//			alert(curw+'@'+wid);
			if(curw>wid)
				$(this).width(wid).height(wid*$(this).height()/curw);
		});
	}
	function rate(aid, rate){
		$.post(u('Post/rate'),{rate:rate,aid:aid},function(res){
			if(res.suc)
			{
				var marktotal=curmark+rate;
				curmark=parseFloat(marktotal/(times+1)).toFixed(1);
				var intm=parseInt(curmark);
				$('.int').html(intm);
				$('.float').html('.'+parseInt((curmark-intm)*10));
				$('.current-rating').width(curmark*30);
				$('.starvote a').remove();
				$('.voteinfo').html('感谢您的打分!').addClass('ok');
				//alert(marktotal);
			}else{
				$('.voteinfo').html(res.msg).addClass('fail');
			}
		}, 'json');
	}


	function replay(id){
//		alert($('#com-'+id+' b').html());
		var t=$('textarea').val();
		$('textarea').val((t?t+'\n':'')+'[reply@'+$('#com-'+id+' b').html()+','+id+']\n').focus();
	}


	function ScrollTop(){
		var p = $().scrollTop();
		if(p>0){
			$().scrollTop(p*0.9);
			setTimeout(function(){ScrollTop()});
		}
	}
