/*-------------------------------------------------------------------
	loading fade
-------------------------------------------------------------------*/
$('head').append('<style type="text/css">#fade{display:block;height:' + $(window).height() + 'px}</style>');
	function windowFade(){
	    $('#fade').each(function(){
	        $('#fade').fadeOut(1000).height($('body').height());
	        $('a').click(function(){
	            var url = $(this).attr('href');
	            if( this.href.match(location.hostname) && $(this).attr("href").charAt(0) != "#" && !$(this).attr("rel") && !$(this).attr("target") ){
	                var LinkURL = $(this).attr("href");
	                $('#fade').fadeIn(1000,function(){
	                    location.href = LinkURL;
	                });
	                return false;
	            }
	        });
	    });
	};


$(window).load(function(){windowFade();});

window.onunload = function() {windowFade();};
/*-------------------------------------------------------------------
	google analytics
-------------------------------------------------------------------*/
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-5066332-3']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

/*-------------------------------------------------------------------
	back ground
-------------------------------------------------------------------*/
$(document).ready(function (){
	var scrollSpeed = 0.1;
	var imgWidth = 4000;
	var posX = 0;
	
	fadeTimer = setInterval(function(bgsky){//ループ処理
		if (posX >= imgWidth){//画像のサイズまで移動したら0に戻る。
			posX= 0;
		}
		posX += scrollSpeed;
		$('body').css("background-position",posX+"px 0");
	}, 1);
});

/*-------------------------------------------------------------------
	navigation 
-------------------------------------------------------------------*/
/*** btn roll over ***/
$(function(){
    $("img.over").mouseover(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
    }).mouseout(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
    }).each(function(){
        $("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
    })
})
/*** drop down list ***/
$(function(){
    $("nav ul.sub,.sub").hide();
    $("ul.navi li,#list01,#list02,#list03").hover(function(){
            $("ul:not(:animated)",this).slideDown("fast")
        },
        function(){
            $("ul",this).slideUp("fast");
    })
})

/*** slide contents ***/
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
            
           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);

 /*-------------------------------------------------------------------
	Tool tip 
-------------------------------------------------------------------*/
	jQuery.fn.rollover = function(suffix) {
	suffix = suffix || '_on';
	var check = new RegExp(suffix + '\\.\\w+$');
	return this.each(function() {
		var img = jQuery(this);
		var src = img.attr('src');
		if (check.test(src)) return;
		var _on = src.replace(/\.\w+/, suffix + '$&');
		jQuery('<img>').attr('src', _on);
		img.hover(
			function() { img.attr('src', _on); },
			function() { img.attr('src', src); }
		);
	});
};
















