$(function() {
	
	var gstep = 60;
	var tstep = 254;
	var loc = location.href;
	var current = 0;
	var gurl = new Array("about","contact","works","blog");
	for(i=0;i<gurl.length;i++) {
		if(loc.indexOf(gurl[i])>0) {
			current = i+1;
		};
	}
	$("#gnavi #"+gurl[current-1]+" a").remove();
	$("#gnavi li").prepend("<img src=\"/themes/new/images/hover.gif\" class=\"hover\" />");
	naviSprite(current);
	
	$("h2").each(function(){
		hSwap($(this));
	});
	$("h3").each(function(){
		if($(this).parent().attr("class")!="section blog") {
			hSwap($(this));
		}
	});
	$("#top h3").each(function(){
		hSwap($(this));
	});
	function hSwap(target) {
		var src = $(target).text();
		src = src.replace(/ /g,"_");
		$(target).css({"background":"url(/themes/new/images/h-"+src.toLowerCase()+".png) 5px 0 no-repeat","text-indent":"-5000px"});
	}
	
	$(".btnLeft a").mouseover(function() {
		$(this).css("background-position","0 -148px");
	});
	$(".btnLeft a").mouseout(function() {
		$(this).css("background-position","0 0");
	});
	$(".btnCenter a").mouseover(function() {
		$(this).css("background-position","-254px -148px");
	});
	$(".btnCenter a").mouseout(function() {
		$(this).css("background-position","-254px 0");
	});
	$(".btnRight a").mouseover(function() {
		$(this).css("background-position","-508px -148px");
	});
	$(".btnRight a").mouseout(function() {
		$(this).css("background-position","-508px 0");
	});
	
	$("#gnavi #about").mouseover(function() {
		naviOver(0);
	});
	$("#gnavi #contact").mouseover(function() {
		naviOver(1);
	});
	$("#gnavi #works").mouseover(function() {
		naviOver(2);
	});
	$("#gnavi #blog").mouseover(function() {
		naviOver(3);
	});
	$("#gnavi #about").mouseout(function() {
		naviOut(0);
	});
	$("#gnavi #contact").mouseout(function() {
		naviOut(1);
	});
	$("#gnavi #works").mouseout(function() {
		naviOut(2);
	});
	$("#gnavi #blog").mouseout(function() {
		naviOut(3);
	});
	if(current!=0) {
		$("#gnavi #"+gurl[current-1]).unbind("mouseover");
	}
	
	function naviOver(val) {
		$("#gnavi #"+gurl[val]+" .hover").stop(false,true);
		$("#gnavi #"+gurl[val]+" .hover").fadeIn(200);
	}
	function naviOut(val) {
		$("#gnavi #"+gurl[val]+" .hover").stop(false,true);
		$("#gnavi #"+gurl[val]+" .hover").fadeOut(500);
	}
	function naviSprite(val) {
		$("#gnavi").css("background-position","0 "+gstep*-val+"px");
	}
});