var headline_id=0;
var is_changed=0;
var change_lock = 0;
var subject_id=0;
var max_headline_id = 3;


function head_line(now_id)
{
		$(".headline_btn").css('background','url(images_files/roll2.gif) no-repeat');
		$("#b"+now_id).css('background','url(images_files/roll1.gif) no-repeat');
		
		$(".headline_pic").hide();
		$("#headline_pic_"+now_id).show();

		$(".headline_title").hide();
		$("#headline_title_"+now_id).show();		

		$(".headline_description").hide();
		$("#headline_description_"+now_id).show();		

		$(".headline_related").hide();
		$("#headline_related_"+now_id).show();		
		
		headline_id=now_id;
}

function head_line2()
{
	if(is_changed=="2")
	{
		return false;
	}
	if(change_lock){
		setTimeout("head_line2()",3000);
		return false;
	}
	
	var now_id=headline_id;	
	now_id=parseInt(headline_id)+1;
    if(now_id>max_headline_id){now_id=0;}

	$(".headline_btn").css('background','url(images_files/roll2.gif) no-repeat');
	$("#b"+now_id).css('background','url(images_files/roll1.gif) no-repeat');

	$(".headline_pic").hide();
	$("#headline_pic_"+now_id).show();

	$(".headline_title").hide();
	$("#headline_title_"+now_id).show();		

	$(".headline_description").hide();
	$("#headline_description_"+now_id).show();		

	$(".headline_related").hide();
	$("#headline_related_"+now_id).show();		
	
	headline_id=now_id;
	change_lock = 1;
	setTimeout(function(){change_lock = 0;},5000);
	setTimeout("head_line2()",6000);
}

$(function(){
		max_headline_id = $('.headline_btn').length - 1;
		$('#forbes_trt').find('div.title').hover(function(){
			$('#forbes_trt').find('div.title').removeClass('selected');
			$(this).addClass('selected');
			var index = $('#forbes_trt').find('div.title').index($(this)) + 1;
			$('.rt_tab').hide();
			$('#rt_tab' + index).show();
		});
		$(".headline_btn").click(function()
		{
			var now_id=$(this).attr('param');	
			head_line(now_id);
		});
		
		$("#headline").hover(function(){
			is_changed = 2;
		},function(){
			is_changed = 0;
			setTimeout(function(){
				if(!is_changed){
					head_line2();}
			},3000);
		});
	
		$("#subject_btnl").click(function()
		{
			
			var str = $("#subject_box").find('.subject_content').last();
			$("#subject_box").find('.subject_content').last().remove();
			$("#subject_box").prepend(str);

			/*
			if(subject_id==0){return false;}
			
			$(".subject_content").hide();
			var subject_id1=parseInt(subject_id)-1;
			var subject_id2=parseInt(subject_id);
			var subject_id3=parseInt(subject_id)+1;

			$("#subject_content_"+subject_id1).show();
			$("#subject_content_"+subject_id2).show();
			$("#subject_content_"+subject_id3).show();
			subject_id=parseInt(subject_id)-1;
			*/


		})		
		
		$("#subject_btnr").click(function()
		{
			var str = $("#subject_box").find('.subject_content').first();
			$("#subject_box").find('.subject_content').first().remove();
			$("#subject_box").append(str);
			/*
			var str = $("#subject_btnl").next().html();
			$("#subject_btnl").next().remove();
			$("#subject_btnr").before(str);

			
			
			if(subject_id>=1){return false;}
			
			$(".subject_content").hide();
			var subject_id1=parseInt(subject_id)+1;
			var subject_id2=parseInt(subject_id)+2;
			var subject_id3=parseInt(subject_id)+3;
			
			$("#subject_content_"+subject_id1).show();
			$("#subject_content_"+subject_id2).show();
			$("#subject_content_"+subject_id3).show();
			subject_id=parseInt(subject_id)+1;
			*/

		})	
		
		$('#cls_cpt1,#cls_cpt2').hover(function(){
			$('div.caption_base').not(this).removeClass('caption_selected');
			$(this).addClass('caption_selected');
			$('div.caption_base').not(this).css('font-weight','normal');
			$(this).css('font-weight','bold');
			var i = $(this).attr('id').substr(7,1);
			$('#div_caption' + i).show();
			if(i== 1){
			  i = 2;	
			}else{
			  i = 1;
			}
			$('#div_caption' + i).hide();
		});
		
		$("#column_box .content").hover(function(){
			$(".cloumn_news_box").hide();
			$(".cloumn_news_box[name="+$(this).attr('name')+"]").show();
			$('.cpic').css('opacity','0.4');
			$(this).find(".cpic").css('opacity','1');
			$('.cpic').css('filter','alpha(opacity=40)');
			$(this).find(".cpic").css('filter','alpha(opacity=100)');
		});
		
		$("#column_btnr").click(function(){
			var flag = true;
			$("#column_btnl").css('background','url(images_files/column_btnl.jpg) no-repeat');
			$("#column_btnl").css('cursor','pointer');
			if($("#column_box").find(".content:visible:eq(2)").next().attr('class')=='content'){
				$('.cpic').each(function(){
					if($(this).css('opacity')=='1'&&flag){
						$('.cpic').css('opacity','0.4');
						$(this).parent().next().find('.cpic').css('opacity','1');
						$('.cpic').css('filter','alpha(opacity=40)');
						$(this).parent().next().find('.cpic').css('filter','alpha(opacity=100)');
						flag = false;
						$(".cloumn_news_box").hide();
						$(".cloumn_news_box[name="+$(this).parent().next().attr('name')+"]").show();
					} 
				 });
				$("#column_box").find('.content:visible:eq(0)').hide();
			}
			if($("#column_box").find(".content:visible:eq(2)").next().attr('class')!='content'){
				$("#column_btnr").css('background','none');
				$("#column_btnr").css('cursor','auto');
			}
		});
		
		$("#column_btnl").click(function(){
			var flag = true;
			$("#column_btnr").css('background','url(images_files/column_btnr.jpg) no-repeat');
			$("#column_btnr").css('cursor','pointer');
			if($("#column_box").find(".content:visible:eq(0)").prev().attr('class')=='content'){
				$("#column_box").find('.content:visible:eq(0)').prev().show();
				$('.cpic').each(function(){
					if($(this).css('opacity')=='1'&&flag){
						$('.cpic').css('opacity','0.4');
						$(this).parent().prev().find('.cpic').css('opacity','1');
						$('.cpic').css('filter','alpha(opacity=40)');
						$(this).parent().prev().find('.cpic').css('filter','alpha(opacity=100)');
						flag = false;
						$(".cloumn_news_box").hide();
						$(".cloumn_news_box[name="+$(this).parent().prev().attr('name')+"]").show();
					} 
				 });
			}
			if($("#column_box").find(".content:visible:eq(0)").prev().attr('class')!='content'){
				$("#column_btnl").css('background','none');
				$("#column_btnl").css('cursor','auto');
			}
		});
		
		$("#old_magazine").change(function(){
			$.post('/ajax/show_magazine.php',{'year':$("#old_magazine").val()},function(data){
				$("#show_magazine").html(data);
				$("#btnonline").removeAttr('href');
				$("#sq").removeAttr('href');
			});
		});
		
		$("#show_magazine").live('change',function(){
			if($("#show_magazine option:selected").attr('url')==''){
				$("#btnonline").removeAttr('href');
			}else{
				$("#btnonline").attr('href',$("#show_magazine option:selected").attr('url'));
			}
			if($("#show_magazine option:selected").val()==''){
				$("#jr").removeAttr('href');
			}else{
				$("#jr").attr('href','/magazine/'+$("#show_magazine option:selected").val());
			}
		});
		
		/*
		$("#sq").click(function(){
			if($("#sq").attr('name')!=''){
				$.post('/ajax/order_magazine.php',{'id':$("#sq").attr('name')},function(data){
					if(data=='wrong'){
						alert("请先登录再申请赠阅");
					}else if(data=='success'){
						alert("已申请，请等待管理员审批");
					}else if(data=='full'){
						alert("请不要重复申请");
					}
				});
			}
		})
		*/
		
});





setTimeout("head_line2()",5000);

