var TimeOut = 8000;
var chmvTimer = null;
var mvarr = new Array('#top_mv1','#top_mv2','#top_mv3','#top_mv4');
var currentMV = 0;

var chnewsTimer = null;
var newsarr = new Array('#top_news1','#top_news2','#top_news3','#top_news4','#top_news5','#top_news6','#top_news7','#top_news8','#top_news9','#top_news10');
var currentNews = 0;

var pickupqt = -4;
var curentpickup = 0;

var mvbutsbox = new Array('#top_mv_cb1','#top_mv_cb2','#top_mv_cb3','#top_mv_cb4');
var mvbutsoff = new Array('#top_mv_tcb1','#top_mv_tcb2','#top_mv_tcb3','#top_mv_tcb4');
var mvbutson = new Array('#top_mv_tcb1on','#top_mv_tcb2on','#top_mv_tcb3on','#top_mv_tcb4on');
var mvnoch = false;

jQuery.event.add(window, "load", function(){
	initTimer();
});

function initTimer() {
	$("#top_pickup_butl a").bind("click", function(){
		top_pickup_back();
		return false;
	});
	$("#top_pickup_butr a").bind("click", function(){
		top_pickup_next();
		return false;
	});
	$("#top_pickupin a").each(function(i) {
		$(this).hover(function() {
			$(this).animate({ opacity: "0.5" }, 120, function() { $(this).animate({ opacity: "1" }, 220) });
		},function(){});
		pickupqt++;
	});
	$("p.icon a img").each(function(i) {
		$(this).hover(function() {
			$(this).animate({ opacity: "0.5" }, 120, function() { $(this).animate({ opacity: "1" }, 220) });
		},function(){});
	});
	$("#top_sub img").each(function(i) {
		$(this).hover(function() {
			$(this).animate({ opacity: "0.5" }, 120, function() { $(this).animate({ opacity: "1" }, 220) });
		},function(){});
	});
	
	$("#top_sns_wrap div.ic a").each(function(i) {
		$(this).hover(function() {
			$(this).animate({ opacity: "0.5" }, 120, function() { $(this).animate({ opacity: "1" }, 220) });
		},function(){});
	});
	
	$("#top_news_t").hover(function() {
		$(this).animate({ opacity: "0.5" }, 220, function() { $(this).animate({ opacity: "1" }, 220) });
	});
	
	$("#top_mv_cbw").css("visibility","visible");
	$("#top_mv_cbw").css("opacity","0");

	$("#top_mv_loader").fadeOut(1000,function() {
		initMV('#top_mv1');
	});
	initNews();
}

function top_pickup_next() {
	if (pickupqt > curentpickup) {
		curentpickup++;
		var idw = curentpickup * 150;
		$("#top_pickupin").animate({ left: -idw}, 250,"swing");
	} else {
		curentpickup = 0;
		$("#top_pickupin").animate({ left: 0}, 250,"swing");
	}
}

function top_pickup_back() {
	if (curentpickup > 0) {
		curentpickup--;
		var idw = curentpickup * 150;
		$("#top_pickupin").animate({ left: -idw}, 250,"swing");
	}
}

function initMV(trg) {
	currentMV = 0;
	$("#top_mv").fadeOut(
		"slow",
		function() {
			$("#top_mv_cb1").html($("#top_mv_tcb1on").html());
			$(this).html($(trg).html());
			$(this).fadeIn();
			$("#top_mv_cbw").animate({ opacity: "1" }, 400);
		}
	);
	chmvTimer = setTimeout("cycleMV()", TimeOut);
}

function cycleMV() {
	if (mvnoch) {
		mvnoch = false;
	} else {
		changeMV(0);
	}
	chmvTimer = setTimeout("cycleMV()", TimeOut);
}

function changeMV(par) {
	$(mvbutsbox[currentMV]).html($(mvbutsoff[currentMV]).html());
	if (par != 0) {
		currentMV = par - 1;
		mvnoch = true;
	} else {
		currentMV++;
		if (currentMV > 3) {
			currentMV = 0;
		}
	}
	$("#top_mv").fadeOut(
		"slow",
		function() {
			$(mvbutsbox[currentMV]).html($(mvbutson[currentMV]).html());
			$(this).html($(mvarr[currentMV]).html());
			$(this).fadeIn();
		}
	);
}

function initNews() {
	currentNews = 0;
	$('#top_news_scr2').html($('#top_news1').html());
	$("#top_news_scr").animate({ left: -742}, 750,"swing");
	chnewsTimer = setTimeout("changeNews()", TimeOut);
}

function changeNews() {
	var oldNews = currentNews;
	currentNews++;
	if (currentNews > 9) {
		currentNews = 0;
	}
	$('#top_news_scr1').html($(newsarr[oldNews]).html());
	$('#top_news_scr2').html($(newsarr[currentNews]).html());
	$("#top_news_scr").css("left","0");
	$("#top_news_scr").animate({ left: -742}, 750,"swing");
	chnewsTimer = setTimeout("changeNews()", TimeOut);
}



