$(document).ready(function() {
	var topicsListHeight = $('#topicsList').height();
	var bannerListHeight = $('#bannerList').height();
	var topicsH;
	if(topicsListHeight >= bannerListHeight){
		topicsH = topicsListHeight - 50;
	} else {
		topicsH = bannerListHeight + 10;
	}
	var total = 0;
	var num = 0;
	var backnum = 0;
	var baf = 0;
	var total2 = 0;
	var num2 = 0;
	var backnum2 = 0;
	var baf2 = 0;
	var BtnSrc;
	var BtnSrc2;
	
	$('#topicsList').css({"height": "80px"});
	
	$('#pickUp').hide();
	
	$('#topicsList > dl', this.group).each(function(){
		
		var BODY = $('#topicsList > dl > dd.txt').filter(':eq('+total+')').html();
		if(BODY && BODY.length > 76){
			BODY = BODY.slice(0,76) + '...';
			$('#topicsList > dl > dd.txt').filter(':eq('+total+')').html(BODY);
		}
		var BODY2 = $('#topicsList > dl > dd.txt_i').filter(':eq('+total+')').html();
		if(BODY2 && BODY2.length > 76){
			BODY2 = BODY2.slice(0,76) + '...';
			$('#topicsList > dl > dd.txt_i').filter(':eq('+total+')').html(BODY2);
		}
		
		$(this).hide();
		$(this).css({"z-index": "0"});
		$(this).addClass('closed');
		total++;
	}).filter(':eq(0)').css({"z-index": "1"}).fadeIn("slow");
	
	if(total > 1){
		var tid = setInterval(newsF,4500);
	}
	$('#bannerList > li', this.group).each(function(){
		$(this).hide();
		$(this).css({"z-index": "0"});
		$(this).addClass('closed');
		total2++;
	}).filter(':eq(0)').css({"z-index": "1"}).fadeIn("slow");
	
	if(total2 > 1){
		var tid2 = setInterval(newsF2,4500);
	}
	
	function newsF(){
		if( num < (total - 1)){
			num++;
		} else {
			num = 0;
		}
		if(num == 0){
			backnum = (total-1);
			
		} else {
			backnum = (num-1);
		}
		$('#topicsList > dl', this.group).filter(':eq('+backnum+')').css({"z-index": "1"});
		$('#topicsList > dl', this.group).filter(':eq('+num+')').css({"z-index": "0"});
		$('#topicsList > dl', this.group).each(function(){
			$(this).fadeOut(250);
		}).filter(':eq('+num+')').fadeIn(1500, function(){
			$('#topicsList > dl', this.group).filter(':eq('+backnum+')').fadeOut(1500);
		});
	}
	
	function newsF2(){
		if( num2 < (total2 - 1)){
			num2++;
		} else {
			num2 = 0;
		}
		if(num2 == 0){
			backnum2 = (total2-1);
			
		} else {
			backnum2 = (num2-1);
		}
		$('#bannerList > li', this.group).filter(':eq('+backnum2+')').css({"z-index": "1"});
		$('#bannerList > li', this.group).filter(':eq('+num2+')').css({"z-index": "0"});
		$('#bannerList > li', this.group).each(function(){
			$(this).fadeOut(250);
		}).filter(':eq('+num2+')').fadeIn(1500, function(){
			$('#bannerList > li', this.group).filter(':eq('+backnum2+')').fadeOut(1500);
		});
	}
	
	$('.seeMore').toggle(
		function() {
			BtnSrc = $(this).children('img').attr('src').replace("_open", "_close");
			$(this).children('img').attr('src', BtnSrc);
			clearInterval(tid);
			clearInterval(tid2);
			$('#topicsList > dl', this.group).stop(false, true).each(function(){
				$(this).hide();
			});
			$('#bannerList > li', this.group).stop(false, true).each(function(){
				$(this).hide();
			});
			$('#topicsList').stop(true, false).animate({
				height: topicsH
			}, 300, function(){
				$('#pickUp').fadeIn("slow");
				$('#topicsList > dl', this.group).stop(false, true).each(function(){
					$(this).css({"z-index": "0"});
					$(this).removeClass('closed');
				}).fadeIn("slow");
				$('#bannerList > li', this.group).stop(false, true).each(function(){
					$(this).css({"z-index": "0"});
					$(this).removeClass('closed');
				}).fadeIn("slow");
			});
		},
		function(){
			BtnSrc2 = $(this).children('img').attr('src').replace("_close", "_open");
			$(this).children('img').attr('src', BtnSrc2);
			$('#pickUp').hide();
			$('#topicsList > dl', this.group).stop(false, true).each(function(){
				$(this).hide();
				$(this).css({"z-index": "0"});
				$(this).addClass('closed');
			});
			$('#bannerList > li', this.group).stop(false, true).each(function(){
				$(this).hide();
				$(this).css({"z-index": "0"});
				$(this).addClass('closed');
			});
			$('#topicsList').stop(true, false).animate({
				height: "80px"
			}, 300, function(){
				$('#topicsList > dl', this.group).filter(':eq('+num+')').css({"z-index": "1"}).fadeIn("slow");
				$('#bannerList > li', this.group).filter(':eq('+num2+')').css({"z-index": "1"}).fadeIn("slow");
				if(total > 1){
					tid = setInterval(newsF,4500);
				}
				if(total2 > 1){
					tid2 = setInterval(newsF2,4500);
				}
			});
		}
	);
	
	
	
	//tab
	var tabcnt = 0;
	var tabnum = 0;
	$('#tab > li > a', this.group).each(function(){
			var tabclass = ""+tabcnt;
			$(this).parent().addClass(tabclass);
			$(this).parent().css("cursor","pointer");
			$(this).parent().append($(this).html());
			$(this).remove();
			
			tabcnt++;
	});
	Src = $('#tab > li.0').children('img').attr('src').replace("_off.", "-on.");
	$('#tab > li.0').children('img').attr('src', Src);
	$('#tab > li.0').css("cursor","default");
	
	
	$('#tab_contents > li', this.group).each(function(){
		$(this).hide();
	}).filter(':eq(0)').fadeIn("slow");
	
	$('#tab > li').click(function() {
		tabnum = $(this).attr('class');
		$('#tab > li', this.group).each(function(){
			var Src2 = $(this).children('img').attr('src').replace("-on.", "_off.");
			$(this).children('img').attr('src', Src2);
			$(this).css("cursor","pointer");
		});
		
		$(this).css("cursor","default");
		var Src3 = $(this).children('img').attr('src').replace("_on.", "-on.");
		Src3 = Src3.replace("_off.", "-on.");
		$(this).children('img').attr('src', Src3);
		
		
		$('#tab_contents > li', this.group).each(function(){
			$(this).hide();
		}).filter(':eq('+tabnum+')').fadeIn("slow");
		
		smartRollover();
	});
	
	
	
	
});




