$(document).ready(function($) {
	var postfix = '_ov';
	$('body a img').not('[src*="'+ postfix +'."]').each(function() {
		var img = $(this);
		if(img.attr('class')!="nonov"){
			var src = img.attr('src');
			var src_on = src.substr(0, src.lastIndexOf('.'))
			           + postfix
			           + src.substring(src.lastIndexOf('.'));
			
			var img2 = new Image();
			if(document.location.protocol == "https:"){
				img2.src = "https://tool.mface.jp" + src_on;
			}else{
				img2.src = "http://tool.mface.jp" + src_on;
			}
			img2.onerror = function(){
		    	//alert(img2.src);
		    }
		    
		    img2.onload = function(){
		        $('<img>').attr('src', src_on);
			
				img.hover(
					function() {
						img.attr('src', src_on);
					},
					function() {
						img.attr('src', src);
					}
				);
		    }
	    }
	});
	
	$("#nav-one li").hover(
		function(){ $("ul", this).fadeIn("fast"); }, 
		function() { } 
	);
	
	if (document.all) {
		$("#nav-one li").hoverClass ("sfHover");
	}
	
	$("#SearchIndex").change(function(){
		var sort = $("#SearchIndex option:selected").val();
		param = {"mm":"ajax","sort":sort}
		
		$.post(
		    "/am_ranking/getsort", 
		    param, 
		    function(data, status) {
		        if(data == ""){
		        	alert("パラメーターエラーですよ。");
		        }else{
		        	$("#sort_area").html(data);
		        }
		        
		        
		    },
		    "html"
		);
		
	});
	
	$("#id1_page_navi select").change(function(){

		$("#user_1_"+id1_page).hide();
		
		$("#user_1_"+$(this).val()).show();
		
		id1_page = $(this).val();
		
		location.href = "#main_cnt";
		location.href = "#result_txt";
		
	});
	
	$("#id2_page_navi select").change(function(){

		$("#user_2_"+id2_page).hide();
		
		$("#user_2_"+$(this).val()).show();
		
		id2_page = $(this).val();
		
		location.href = "#main_cnt";
		location.href = "#result_txt";
	});
	
	$("#common_page_navi select").change(function(){

		$("#user_common_"+common_page).hide();
		
		$("#user_common_"+$(this).val()).show();
		
		common_page = $(this).val();
		
		location.href = "#main_cnt";
		location.href = "#result_txt";
	});
	
	$("p.tw_icons a").mouseover(function(){
		
	});
});

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};

jQuery.preimg = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", "/img/" + arguments[i]);
	}
};
jQuery.preimg("menu01_ov.jpg", "menu01.jpg","menu02_ov.jpg", "menu02.jpg","menu03_ov.jpg", "menu03.jpg","menu04_ov.jpg", "menu04.jpg","menu05_ov.jpg", "menu05.jpg","header.jpg","back.jpg","title.jpg","main.jpg","bar.jpg");

function getfirstSort(){
	var sort = $("#SearchIndex option:selected").val();
		param = {"mm":"ajax","sort":sort}
		
		$.post(
		    "/am_ranking/getsort", 
		    param, 
		    function(data, status) {
		        if(data == ""){
		        	alert("パラメーターエラーですよ。");
		        }else{
		        	$("#sort_area").html(data);
		        }
		        
		        
		    },
		    "html"
		);
}
