$.preloadImages=function(){
	for(var i=0;i<arguments.length;i++){
		$("<img />").attr("src",arguments[i]);
	}
};








$.notify=function(text){
	var y=$('html').scrollTop()||document.body.scrollTop;

	if($("#notification").length){
		var n=$("#notification")
		var ca=n.find(".close a");

		n.stop(true).animate({top:y},3000,function(){
			ca.unbind("mouseenter",over);
			ca.unbind("mouseleave",out);
			ca.unbind("click",click);
		}).animate({top:y-83},400,function(){
			$(window).unbind("scroll",sc);
			n.remove();
		});
		n.find(".text").html(text);
		return;
	}else{
		var t=$('<span class="text png" />').append(text).width($(window).width()-140);
		var ca=$('<a href="#" tabindex="-1" class="hideText">閉じる</a>');
		var c=$('<span class="close png"></span>').append(ca);
		var n=$('<div id="notification"/>').append(t).append(c).click(function(e){
			ca.unbind("mouseenter",over);
			ca.unbind("mouseleave",out);
			ca.unbind("click",click);
			n.stop();
			n.animate({top:y-83},600,function(){
				$(window).unbind("scroll",sc);
				n.remove();
			});
		}).appendTo($("body"));
	}

	var sc=function(e){
		ca.unbind("mouseenter",over);
		ca.unbind("mouseleave",out);
		ca.unbind("click",click);
		$(window).unbind("scroll",sc);
		n.stop();
		n.remove();
	}

	$(window).bind("scroll resize",sc);

	var over=function(e){
		$(this).css("background-position","left bottom");
	}
	var out=function(e){
		$(this).css("background-position","left top");
	}
	var click=function(e){
		ca.unbind("mouseenter",over);
		ca.unbind("mouseleave",out);
		ca.unbind("click",click);
		n.stop();
		n.animate({top:y-83},600,function(){
			$(window).unbind("scroll",sc);
			n.remove();
		});
		return false;
	}
	ca.mouseenter(over).mouseleave(out).click(click);
	


	n.css("top",y-83+"px");
	n.animate({top:y},400).animate({top:y},3000,function(){
		ca.unbind("mouseenter",over);
		ca.unbind("mouseleave",out);
		ca.unbind("click",click);
	}).animate({top:y-83},400,function(){
		$(window).unbind("scroll",sc);
		n.remove();
	});
	
	return false;
};











$.setModalSheet=function(){

		$("[tabindex][tabindex!=-1]").each(function(){
			var me=$(this);
			me.attr("_tabindex",me.attr("tabindex"));
			me.attr("tabindex",-1);
		});

		var m=$('<div id="modal" />').appendTo($("body"));

		var remove=function(){
			$("[_tabindex]").each(function(){
				var me=$(this);
				me.attr("tabindex",me.attr("_tabindex"));
			});
			$(window).unbind("resize",resize);
			m.trigger("modalRemoved");
			m.remove();
		};

		var resize=function(e){

			var width;
			if($("body").width()>980){
				if(!window.innerWidth){//ie
					width=$("body").width();
				}else{
					width=$(window).width();
				}
			}else{
				width=980;
			}
			m.width(width+"px");

			var height=$("body").height();
			if(height<$(window).height()){
				m.height("100%");
			}else{
				m.height(height+"px");
			}
		};

		resize();
		$(window).resize(resize);

		return {sheet:m,remover:remove};
};











$.fn.enhanceBGOver=function(){
	return $(this).each(function(){
		var me=$(this);
		me.bind("mouseenter focus",function(e){
			me.css("background-position","left bottom");
		}).bind("mouseleave blur",function(e){
			me.css("background-position","left top");
		});
	});
};






$.fn.enhanceRollOver=function(){
	return $(this).each(function(){
		var me=$(this);
		me.bind("mouseenter focus",function(e){
			var src=me.attr("src");
			if(src.lastIndexOf("_on")==-1){
				var len=src.length;
				me.attr("src",src.substring(0,len-4)+"_on"+src.substring(len-4,len));
			}
		}).bind("mouseleave blur",function(e){
			var src=me.attr("src");
			if(src.lastIndexOf("_on")!=-1){
				var len=src.length;
				me.attr("src",src.substring(0,len-7)+src.substring(len-4,len));
			}
		});
	});
};








$.fn.focusKeyControl=function(){
	return function(e){
		if(e.which==13){
			$(this).trigger("click");
			e.preventDefault();
			e.stopPropagation();
		}
	};
};




$(document).ready(function(){
	$(".bgOver").enhanceBGOver();
	$(".rollover").enhanceRollOver();

	$("a img.logo").each(function(){
		var img=$(this);
		$(this).parent().focus(function(){
			var src=img.attr("src");
			if(src.lastIndexOf("_on")==-1){
				var len=src.length;
				img.attr("src",src.substring(0,len-4)+"_on"+src.substring(len-4,len));
			}
		}).blur(function(){
			var src=img.attr("src");
			if(src.lastIndexOf("_on")!=-1){
				var len=src.length;
				img.attr("src",src.substring(0,len-7)+src.substring(len-4,len));
			}
		});
	});


});

