$( document ).ready( function(){
	$("#critique").submit( function(){
		if( $("#cirtique_is_login").val() == 0 && !$("#cirtique_on_login")[0].checked  ){
			alert( "您还没有登陆，请选登陆或匿名发表！" );
			return false;
		}
	});

});

var inLoad=0;
function addCollection( proId ){
	
	if( inLoad == 1 ){
		alert("请少等重试，上一个请求正在处理中！");
		return ;
	}else{
		inLoad = 1;
	}
	
	$( "#car_loading" ).css( "display", "block" );
	var carTop = document.documentElement.scrollTop + 20;
	$( "#car_loading" ).css( "top", carTop );
	
	$.getJSON('collection_ajax.php', {
    	id: proId,
	    active: "news"
	}, function( json ) {
		$( "#car_loading" ).css( "display", "none" );
		inLoad = 0;
		
		if( json.infoType == 2 ){
			$('#collInfoImage').attr( "src", "./images/car_show_wang.gif" );
			$('#wishlist_add_show_info').html( "收藏失败!" );
			$('#car_add_show').addClass("car_add_show_err");
		}else if( json.infoType == 3 ){
			$('#collInfoImage').attr( "src", "./images/car_show_wang.gif" );
			$('#wishlist_add_show_info').html( "您还没有登陆，请登陆后重试!" );
			$('#car_add_show').addClass("car_add_show_err");
		}else if( json.infoType == 4 ){
			$('#collInfoImage').attr( "src", "./images/car_show_wang.gif" );
			$('#wishlist_add_show_info').html( "您已经收藏过该文章!" );
			$('#car_add_show').addClass("car_add_show_err");
		}else{
			$('#carInfoImage').attr( "src", "./images/information.png" );
			$('#carInfo').html( "收藏成功!" );
			if( $('#car_add_show').css("background-color") == "#fdd" ){
				$('#car_add_show').removeClass("car_add_show_err");
			}
		}
		carInfoShow("#wishlist_add_show");
	});
	
}

//购物车信息显示
var carInfoTime; //time out var
var actionDiv;
function carInfoShow( divName ){
	if( actionDiv ){
		$( actionDiv ).css("display","none");
	}
	actionDiv = divName;
	
	$( divName ).show();
	var carTop = document.documentElement.scrollTop + 20 -130;
	clearTimeout( carInfoTime );
	carInfoDown( carTop, divName );
}

function carInfoDown( carTop, divName ){
	$(divName).css("top", carTop );
	if( carTop < document.documentElement.scrollTop+20 ){
		carInfoTime = setTimeout( "carInfoDown( "+(carTop+10)+", \""+ divName +"\" )", 10 );
	}else{
		carInfoTime = setTimeout( "carInfoHide(\""+ divName +"\")", 3000 );
	}
}

function carInfoHide(divName){
	
	var carTop = $(divName).css("top");
	carTop = carTop.substring( 0, carTop.length-2);
	clearTimeout( carInfoTime );
	carInfoUp( carTop, divName )
}

function carInfoUp( carTop, divName ){
	$(divName).css("top", carTop );
	if( carTop > document.documentElement.scrollTop-130 ){
		carInfoTime = setTimeout( "carInfoUp( "+(carTop-10)+", \""+ divName +"\" )", 10 );
	}else{
		clearTimeout( carInfoTime );
		$(divName).hide();
	}
}

function aegis( id ){
	$.get('critique_ajax.php', {
    	id: id,
	    act: "aegis"
	});
	$( "#aegis_"+id ).html( "已支持" ).attr("href","javascript:void();");
	$( "#aegis_num_"+id ).html( parseInt( $( "#aegis_num_"+id ).html() ) + 1 );
}

function against( id ){
	$.getJSON('critique_ajax.php', {
    	id:id,
	    act:"against"
	}, function(data){
		alert(data+"aaa");
	});
	$( "#against_"+id ).html( "已反对" ).attr("href","javascript:void();");
	$( "#against_num_"+id ).html( parseInt( $( "#against_num_"+id ).html() ) + 1 );
}



