/* -------------------------------------------



------------------------------------------- */
(function () {
    var easing = 0.25;
    var interval = 10;
    var d = document;
    var targetX = 0;
    var targetY = 0;
    var targetHash = '';
    var scrolling = false;
    var splitHref = location.href.split('#');
    var currentHref_WOHash = splitHref[0];
    var incomingHash = splitHref[1];
    var prevX = null;
    var prevY = null;
    addEvent(window, 'load', init);
	 
	 
	 //if( document.URL.indexOf('/blog/') > -1 ) return false;
	 

    function init()
	 {
        setOnClickHandler();
        if (incomingHash) {
            if (window.attachEvent && !window.opera) {} else {}
        }
    }
    function addEvent(eventTarget, eventName, func)
	 {
        if (eventTarget.addEventListener) {
            eventTarget.addEventListener(eventName, func, false)
        } else if (window.attachEvent) {
            eventTarget.attachEvent('on' + eventName, function () {
                func.apply(eventTarget)
            })
        }
    }
    function setOnClickHandler()
	 {
        var links = [];
        var temp = d.getElementById('pageTop').getElementsByTagName('a');
		  
		  for( var i = 0; i < temp.length; i++ )
		  {
            if( temp[i].getAttribute('href') != null && temp[i].getAttribute('href').indexOf('tab') == -1 )
				{
					links.push( temp[i] );
            }
        }
		  
        for( var i = 0; i < links.length; i++ )
		  {
            var link = links[i];
            var splitLinkHref = link.href.split('#');
				
				if( currentHref_WOHash == splitLinkHref[0] && d.getElementById( splitLinkHref[1] ) )
				{
                addEvent(link, 'click', startScroll)
            }
        }
    }
    function startScroll(event) {
        if (event) {
            event.preventDefault()
        } else if (window.event) {
            window.event.returnValue = false
        }
        setScroll(this.hash)
    }
    function setScroll(hash) {
        var targetEle = d.getElementById(hash.substr(1));
        if (!targetEle) return;
        var ele = targetEle;
        var x = 0;
        var y = 0;
        while (ele) {
            x += ele.offsetLeft;
            y += ele.offsetTop;
            ele = ele.offsetParent
        }
        var maxScroll = getScrollMaxXY();
        targetX = Math.min(x, maxScroll.x);
        targetY = Math.min(y, maxScroll.y);
        targetHash = hash;
        if (!scrolling) {
            scrolling = true;
            scroll()
        }
    }
    function scroll() {
        var currentX = d.documentElement.scrollLeft || d.body.scrollLeft;
        var currentY = d.documentElement.scrollTop || d.body.scrollTop;
        var vx = (targetX - currentX) * easing;
        var vy = (targetY - currentY) * easing;
        var nextX = currentX + vx;
        var nextY = currentY + vy;
        if ((Math.abs(vx) < 1 && Math.abs(vy) < 1) || (prevX === currentX && prevY === currentY)) {
            scrollTo(targetX, targetY);
            scrolling = false;
            location.hash = targetHash;
            prevX = prevY = null;
            return
        } else {
            scrollTo(parseInt(nextX), parseInt(nextY));
            prevX = currentX;
            prevY = currentY;
            setTimeout(function () {
                scroll()
            }, interval)
        }
    }
    function getDocumentSize() {
        return {
            width: Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
            height: Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)
        }
    }
    function getWindowSize() {
        var result = {};
        if (window.innerWidth) {
            var box = d.createElement('div');
            with(box.style) {
                position = 'absolute';
                top = '0px';
                left = '0px';
                width = '100%';
                height = '100%';
                margin = '0px';
                padding = '0px';
                border = 'none';
                visibility = 'hidden'
            }
            d.body.appendChild(box);
            var width = box.offsetWidth;
            var height = box.offsetHeight;
            d.body.removeChild(box);
            result = {
                width: width,
                height: height
            }
        } else {
            result = {
                width: d.documentElement.clientWidth || d.body.clientWidth,
                height: d.documentElement.clientHeight || d.body.clientHeight
            }
        }
        return result
    }
    function getScrollMaxXY() {
        if (window.scrollMaxX && window.scrollMaxY) {
            return {
                x: window.scrollMaxX,
                y: window.scrollMaxY
            }
        }
        var documentSize = getDocumentSize();
        var windowSize = getWindowSize();
        return {
            x: documentSize.width - windowSize.width,
            y: documentSize.height - windowSize.height
        }
    }
}());
/* -------------------------------------------



------------------------------------------- */
(function()
{
/* -------------------------------------------

	gNavi current

------------------------------------------- */
var gNaviCurrentFunc = {
	getURL : function()
	{
		var url = document.URL,
		link01 = document.getElementById('link01'),
		link02 = document.getElementById('link02'),
		link03 = document.getElementById('link03'),
		link04 = document.getElementById('link04'),
		link05 = document.getElementById('link05'),
		link06 = document.getElementById('link06');
		
		// url と 適用するCSSの値をセットしている
		if( url.indexOf('resume/') > -1 ){ this.changeNavi( link01, '0 100%' ); return false; }
		if( url.indexOf('longlife/') > -1 ){ this.changeNavi( link02, '-142px 100%' ); return false; }
		if( url.indexOf('hebel/') > -1 ){ this.changeNavi( link03, '-283px 100%' ); return false; }
		if( url.indexOf('lineup/') > -1 ){ this.changeNavi( link04, '-425px 100%' ); return false; }
		if( url.indexOf('customer/') > -1 ){ this.changeNavi( link05, '-567px 100%' ); return false; }
		
		// ------------------
		// blog
		// ------------------
		var newsBtn = $('.cat-item-13 a');
		var infoBtn = $('.cat-item-1 a');
		
		if( url.indexOf('blog/') > -1 ){ this.changeNavi( link06, '-709px 100%' ); }
		if( url.indexOf('blog/category/news/') > -1 ){ this.changeNavi( newsBtn.get(0), '100% 0' ); return false; }
		if( url.indexOf('blog/category/info/') > -1 ){ this.changeNavi( infoBtn.get(0), '100% 0' ); return false; }
	},
	changeNavi : function( val, position )
	{
		val.style.backgroundPosition = position;
	}
};
/* -------------------------------------------

	gNavi for IE
	
	// hideFocus

------------------------------------------- */
var hideForcusForIE = {
	get : function()
	{
		var target = document.getElementById('headerLink');
		var a = target.getElementsByTagName('a');
		
		a[0].setAttribute( 'hideFocus', 'true' );
		a[1].setAttribute( 'hideFocus', 'true' );
	}
};
/* -------------------------------------------

	fire!

------------------------------------------- */
window.onload = function()
{
	gNaviCurrentFunc.getURL();
	hideForcusForIE.get();
};

})();// capsule
