//Left showAuto
function showAuto(){
	var count = $("#f_imgDiv a").size();
	n = n >= (count - 1) ? 0 : ++n;
	$("#f_infoDiv li").eq(n).trigger('click.left');
}
function showAutoRight(){
	var count_r = $(".ryearImg a").size();
	str = str >= (count_r - 1) ? 0 : ++str;
	$(".ryearInfo td.number").eq(str).trigger('click.right');
}
$(function(){	
	var t = n = str =0;
	var count = $("#f_imgDiv a").size();
	$("#f_imgDiv a:not(:first-child)").hide();
		$(".qtonenews h2 a").html($("#f_imgDiv a:first-child").find("img").attr('title'));
		$(".qtonenews p").html($("#f_imgDiv a:first-child").find("img").attr('alt'));
		$("#f_infoDiv li:first-child").addClass("current");
		$(".qtonenews h2").click(function(){window.open($("#f_imgDiv a:first-child").attr('href'), "_blank")});

		$("#f_infoDiv li").unbind('click').bind('click.left',function() {
			var i = $(this).text() - 1;
				n = i;
				$(this).addClass("current").siblings().removeClass("current");
				$(".qtonenews h2 a").html($("#f_imgDiv a").eq(i).find("img").attr('title'));
				$(".qtonenews p").html($("#f_imgDiv a").eq(i).find("img").attr('alt'));
				$(".qtonenews h2").unbind().click(function(){window.open($("#f_imgDiv a").eq(i).attr('href'), "_blank")})
				$("#f_imgDiv a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
		});
		t = setInterval("showAuto()", 3500);
		$("#f_div").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", 3500);});
	
	//Label change
	$('.qtnews:first').css('display','block');
	$('.qtnewstitle li a:first').addClass('current')
	$('.qtnewstitle li a').each(function(i){
		$(this).mouseenter(function(){
			$('.qtnewstitle li a').removeClass('current');
			$(this).addClass('current');
			$('.qtnews').css('display','none');
			$('.qtnews').eq(i).css('display','block');
		})
	})
	//Left public company
	var Top=0;
	var Long=72;
	var Time=500;
	var List=$('.innerleftsidebar ul').height()-Long;
	var remain=List%Long;
	$("#nextbutton").click(function(){
		Top+=-Long;
		if (Top<=(-1)*(List))
		{
			Top=(-1)*List;
			$(this).css('background-position','right top')
		}else{
			$(this).css('background-position','right bottom')
			$('#prevbutton').css('background-position','left bottom')
		}
			$(".innerleftsidebar ul").animate({top: Top}, Time );
		});

	
	$("#prevbutton").click(function(){
		Top+=Long;
		if (Top>=-remain)
		{
			Top=0;
			$(this).css('background-position','left top')
		}else{
			$(this).css('background-position','left bottom')
			$('#nextbutton').css('background-position','right bottom')
		}
		$(".innerleftsidebar ul").animate({top: Top}, Time );
		});

	$('.leftCom_Img img:first').css('z-index','1');

	$('.leftCom li a').mouseover(function(){
		var comName = $(this).attr('name');
		$('.leftCom_Img img').each(function(){
			var comImg = $(this).attr('alt')
			if (comName == comImg)
			{
				$(this).css('z-index','1');
			}else{
				$(this).css('z-index','0');
			}
		})
	});
	//Right first
	$(".ryearImg a:not(:first-child)").hide();
	$(".ryearInfo td.number:first").addClass("current");

	$(".ryearInfo td.number").unbind('click').bind('click.right', function() {
		var i = $(this).text() - 1, str = i;
		$(this).addClass("current").siblings().removeClass("current");
		$(".ryearImg a").filter(":visible").fadeOut(300).parent().children().eq(i).fadeIn(600);
	});

	time = setInterval("showAutoRight()", 3500);
		$(".ryearImg").hover(function(){clearInterval(time)}, function(){time = setInterval("showAutoRight()", 3500);});

	$('.ryearInfo td#yearPre').click(function(){
		var num = $(this).parent().find('.current').text(), $item = $('.ryearInfo td.number');
		if (num <= 1)
		{
			num = 1;
			return false;
		}else{
			num--;
			currentNum = $item.parent().find('.current');
			$(".ryearImg a").filter(":visible").fadeOut(300).parent().children().eq(num-1).fadeIn(600);
			$(currentNum).removeClass('current').prev().addClass('current');
		}
	});

	$('.ryearInfo td#yearNext').click(function(){
		var num = $(this).parent().find('.current').text(), $item = $('.ryearInfo td.number');
		if (num >= $item.length)
		{
			num = $item.length;
			return false;
		}else{
			num++;
			currentNum = $item.parent().find('.current');
			$(".ryearImg a").filter(":visible").fadeOut(300).parent().children().eq(num-1).fadeIn(600);
			$(currentNum).removeClass('current').next().addClass('current');
		}
	});
	//Right second
	var  num = '', $item = $('.companyImg a');
	$(".companyImg a:first-child").addClass('current');
	$(".companyImg a:not(:first-child)").hide();
	$(".rcompanyText a").html($(".companyImg a:first-child").find("img").attr('alt'));
	$(".rcompanyText a").attr('href',$(".companyImg a:first-child").attr('href'));
	//$(".rcompanyText a").click(function(){window.open($(".companyImg a:first-child").attr('href'), "_blank")});

		$('.companyImg a').each(function(index){
				//var cur = $(this).hasClass('current')
				if ($(this).hasClass('current'))
				{
					num = index + 1;
				}
			})

	$("#companyPrev").click(function() {
		if (num <= 1)
		{
			num = 1;
			return false;
		}else{
			num--;
			currentNum = $item.parent().find('.current');
			$item.filter(":visible").fadeOut(300).parent().children().eq(num-1).fadeIn(300);
			$(".rcompanyText a").html(currentNum.prev().find("img").attr('alt'));
			$(".rcompanyText a").attr('href',currentNum.prev().attr('href'));
			currentNum.removeClass('current').prev().addClass('current');
			//$(".rcompanyText a").unbind().click(function(){window.open($(currentNum).prev().attr('href'), "_blank")});
		}
	});

	$("#companyNext").click(function() {
		if (num >= $item.length)
		{
			num = $item.length;
			return false;
		}else{
			num++;
			currentNum = $item.parent().find('.current');
			$item.filter(":visible").fadeOut(300).parent().children().eq(num-1).fadeIn(300);
			$(".rcompanyText a").html(currentNum.next().find("img").attr('alt'));
			$(".rcompanyText a").attr('href',currentNum.next().attr('href'));
			currentNum.removeClass('current').next().addClass('current');
			//$(".rcompanyText a").unbind().click(function(){window.open($(currentNum).next().attr("href"), "_blank")});
		}
	});

	//Right third
	$('.rbanner a:first').addClass('current');

	setInterval(function () {

		var temNum;
		$('.rbanner a').each(function (i,n) {
			if ($(this).hasClass('current'))	{
				temNum=i;
			}
		})			
		$('.rbanner a').eq(temNum).removeClass('current');			
		if (temNum==$('.rbanner a').length-1)	{
			temNum=-1;
		}
		$('.rbanner a').eq(temNum+1).addClass('current');

	},3500)


})

