// JavaScript Document

$(document).ready(function(){

	/*ランキングスクロール*/
	$("div.r-prev").click(function () {
		$(this).next("div.r-main").children("ul").attr('id', 'active_scroll');
		$(this).next("div.r-main").children("ul").children("li:last-child").css("marginLeft",-127);
		$(this).next("div.r-main").children("ul").children("li:last-child").prependTo("#active_scroll");
		$(this).next("div.r-main").children("ul").children("li:first-child").animate({marginLeft: 0}, 800,"swing",
			(function(){
				$(this).parent("ul").attr('id', '');
			})
		);	
	});
	
	$("div.r-next").click(function () {
		$(this).prev("div.r-main").children("ul").attr('id', 'active_scroll');
		$("#active_scroll").children("li:first-child").animate({marginLeft: -127}, 800, "swing",
			(function(){
				$(this).appendTo("#active_scroll");
				$(this).css("marginLeft",0);
				$(this).parent("ul").attr('id', '');
			})
		);
	});
	
	/*menuツールチップ*/
	//$('div#menu ul li a').hover(menu_over(),menu_out());
	$('div#menu ul li').hover(
		function () {
			var menu_height = $(this).outerHeight();
			var menu_width = $(this).outerWidth();
			var menu_width_offset = ~~(menu_width/2);
			
			$(this).children("a").css({"background-position": "0 -45px"});
			$("#menu").css({"overflow": "visible", "z-index": "1600"});
			$("<div id=\"tip_head\"></div>").appendTo(this);
			$("div#tip_head").css({"width": menu_width, "top": menu_height, "display":"block"});
			
			id = $(this).attr("id");
			var tooltip_width = $("div#"+id+"_contents").outerWidth();
			var tooltip_offset = ~~(tooltip_width/2);
			$("div#"+id+"_contents").appendTo(this);
			//$("div#"+id+"_contents").css({"top": menu_height+10, "display":"block"});
			if ($(this).is(":first-child")){
				$(this).children("div#"+id+"_contents").css({"top": menu_height+10, "display":"block"});
			} else if ($(this).is(":last-child")){
				$(this).children("div#"+id+"_contents").css({"top": menu_height+10, "right": "0", "display":"block"});
			} else {
				$(this).children("div#"+id+"_contents").css({"top": menu_height+10, "left": menu_width_offset-tooltip_offset, "display":"block"});
			}
			/*var winWidth = $(window).width();
			var last_menu_pos = $("div#menu ul li:last").position();
			var tool_pos = $("div#menu").position();
			var menu_height = $("div#menu ul li").outerHeight();
			var menu_pos = $(this).parent("li").position();
		
			$("div#tip_head").css({"top": tool_pos.top+menu_height-10,"left": tool_pos.left+menu_pos.left+74,"display":"block"});
		
			
			var tip_width = $("div#"+id+"_contents").outerWidth();
			var tip_offset = ~~(tip_width/2);
		
			if ($(this).parent("li").is(":first-child")){
				$("div#"+id+"_contents").css({"top": tool_pos.top+menu_height,"left": menu_pos.left+tool_pos.left,"display":"block"});
			} else if ($(this).parent("li").is(":last-child")){
				$("div#"+id+"_contents").css({"top": tool_pos.top+menu_height,"right": winWidth-last_menu_pos.left,"display":"block"});
			} else {
				$("div#"+id+"_contents").css({"top": tool_pos.top+menu_height,"left": menu_pos.left+tool_pos.left-tip_offset+80,"display":"block"});
				$("div#"+id+"_contents").text( tip_width+","+tip_offset);
			}*/
		},
		function () {
			$(this).children("a").css({"background-position": "0 0"});
			$("div#"+id+"_contents").appendTo("body");
			$("div#tip_head").remove();
			$("#menu").css({"overflow": "hidden", "z-index": "1"});
			$("div#"+id+"_contents").css({"display":"none"});
			/*id = $(this).parent("li").attr("id");	
			$("div#"+id+"_contents").hover(
				function () {
					$("div#"+id+"_contents").css({"display":"block"});
				},
				function () {
					$("div#tip_head").css({"display":"none"});
					$("div.tooltip").css({"top": "","left": "","right": "","display":"none"});
				}
			)*/
		}
	);


});

