$(function(){


// グローバルナビ
    $('#globalNavi > ul li a').each(function () {
        var url = document.URL.split('/');
        var mapping = {
            'positioning': 'products',
            'eyecare': 'products',
            'finetech': 'products'
        };
        if (mapping[url[3]]) url[3] = mapping[url[3]];
        var href = $(this).attr('href').split('/');

        // hrefが絶対パスの場合href[3]にする必要があります(by 宮永)
        if (url[3] == href[1] && !$(this).hasClass('no-stay')) {
            var img = $(this).children('img').eq(0);
            if (img.length) {
                src = img.attr('src').replace(".gif", "_over.gif");
                img.attr('src', src);
                img.addClass('stay');
            }
        }
    });

// ポジショニングトップ
    $(('#topconarea > a') || ('#sokkiaarea > a')).each(function () {
        var url = document.URL.split('/');
        var mapping = {
            'positioning': 'products',
            'eyecare': 'products',
            'finetech': 'products'
        };
        if (mapping[url[3]]) url[3] = mapping[url[3]];
        var href = $(this).attr('href').split('/');

        // hrefが絶対パスの場合href[3]にする必要があります(by 宮永)
        if (url[3] == href[1] && !$(this).hasClass('no-stay')) {
            var img = $(this).children('img').eq(0);
            if (img.length) {
                src = img.attr('src').replace(".gif", "_over.gif");
                img.attr('src', src);
                img.addClass('stay');
            }
        }
    });


//ローカルナビゲーションに第2階層のフォルダ名をclassとして指定する
    $('div#localNav ul.level01 li').each(function(){
    var href = $(this).children().eq(0).attr('href').split('/');

    if(!href[4]){
$(this).addClass(href[3]);
    }
    if(!href[3]){
$(this).addClass(href[2]);
    }
if(!href[2]){
$(this).addClass(href[1]);
    }
if(href[0] == 'https:' && href[2] == 'www.topcon.co.jp'){
$(this).removeClass("www.topcon.co.jp");
$(this).addClass(href[3]);
    }
if(href[3] == 'policy'){
$(this).removeClass("policy");
$(this).addClass(href[2]);
    }
if(href[3] == 'disclose'){
$(this).removeClass("disclose");
$(this).addClass(href[2]);
    }
if(href[2] == 'qw108.qhit.net' && href[3] == 'topcon'){
$(this).addClass("sj_price");
$(this).attr('title','別ウィンドウで開きます');
    }


var durl = (document.URL).split('/');
if(href[1] == 'material' && !href[2] && href[1] == durl[3]){
if (!durl[4] || durl[4] == 'index.html') {
$(this).addClass("current");
}
}

if(href[1] == 'corporate' && !href[2] && href[1] == durl[3]){
if (!durl[4] || durl[4] == 'index.html') {
$(this).addClass("current");
}
}

    });



//パンくずに第2階層のフォルダ名をclassとして指定する
    $('ul#topicPath li').each(function(){
    var href = $(this).children().eq(0).attr('href').split('/');

    if(!href[5]){
$(this).addClass(href[4]);
    }
    if(!href[4]){
$(this).addClass(href[3]);
    }
    if(!href[3]){
$(this).addClass(href[2]);
    }
    });


//外部リンクに extRefを付与する
//    $(".section a[target='_blank']").addClass('extRef');
//$(".section a[target='_blank'] img").parent('a').removeClass('extRef');
//$(".section a[target='_blank'] img").parent('a').addClass('noneextRef');

//外部リンク改良版
jQuery (document).ready( function () {
jQuery (".section a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=www.topcon.co.jp]").not("[href*=www.topcon-saiyo.com]").not("[href*=positioning.topcon.co.jp]").attr("target","_blank");
jQuery (".section a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=www.topcon.co.jp]").not("[href*=www.topcon-saiyo.com]").not("[href*=positioning.topcon.co.jp]").addClass('extRef');
jQuery ("#calendar a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=www.topcon.co.jp]").not("[href*=www.topcon-saiyo.com]").not("[href*=positioning.topcon.co.jp]").attr("target","_blank");
jQuery ("#calendar a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=www.topcon.co.jp]").not("[href*=www.topcon-saiyo.com]").not("[href*=positioning.topcon.co.jp]").addClass('extRef');
jQuery ("#newsArea a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=www.topcon.co.jp]").not("[href*=www.topcon-saiyo.com]").not("[href*=positioning.topcon.co.jp]").attr("target","_blank");
jQuery ("#newsArea a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=www.topcon.co.jp]").not("[href*=www.topcon-saiyo.com]").not("[href*=positioning.topcon.co.jp]").addClass('extRef');
jQuery ("#eventArea a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=www.topcon.co.jp]").not("[href*=www.topcon-saiyo.com]").not("[href*=positioning.topcon.co.jp]").attr("target","_blank");
jQuery ("#eventArea a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=www.topcon.co.jp]").not("[href*=www.topcon-saiyo.com]").not("[href*=positioning.topcon.co.jp]").addClass('extRef');
jQuery ("#topicsArea a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=www.topcon.co.jp]").not("[href*=www.topcon-saiyo.com]").not("[href*=positioning.topcon.co.jp]").attr("target","_blank");
jQuery ("#topicsArea a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=www.topcon.co.jp]").not("[href*=www.topcon-saiyo.com]").not("[href*=positioning.topcon.co.jp]").addClass('extRef');
jQuery (".section a img").not("[href*="+location.hostname+"]").parent('a').not("[href*=www.topcon.co.jp]").not("[href*=www.topcon-saiyo.com]").not("[href*=positioning.topcon.co.jp]").removeClass('extRef');
jQuery (".section a img").not("[href*="+location.hostname+"]").parent('a').not("[href*=www.topcon.co.jp]").not("[href*=www.topcon-saiyo.com]").not("[href*=positioning.topcon.co.jp]").addClass('noneextRef');
})

//パンくずリストの最後の要素にclass="end"を付与する
$('ul#topicPath > li:last-child').addClass('end');

    // PDF へのリンクにアイコンを追加する
    jQuery('a').each (function () {
        if (this.href.match(/\.pdf$/) && !jQuery(this).children('img').length)
            jQuery(this).append('<img alt="PDF" class="pdfImg" src="/images/icon_pdf.gif">');
    });

})

$(document).ready(function(){

$(".mvPositioningContents").hide();
$(".mvEyecareContents").hide();
$(".mvFinetechContents").hide();

$(".mvPositioningButton").hover(function(){
if ($(".mvPositioningContents").css("display") == "none") {
 $(".mvPositioningContents").fadeIn("fast");
}
 $(".mvEyecareContents").fadeOut("fast");
 $(".mvFinetechContents").fadeOut("fast");
},function(){});

$(".mvEyecareButton").hover(function(){
 $(".mvPositioningContents").fadeOut("fast");
if ($(".mvEyecareContents").css("display") == 'none') {
 $(".mvEyecareContents").fadeIn("fast");
}
 $(".mvFinetechContents").fadeOut("fast");
},function(){});

$(".mvFinetechButton").hover(function(){
 $(".mvPositioningContents").fadeOut("fast");
 $(".mvEyecareContents").fadeOut("fast");
if ($(".mvFinetechContents").css("display") == 'none') {
 $(".mvFinetechContents").fadeIn("fast");
}
},function(){});


$("#mainVisual").hover(function(){
},function(){
 $(".mvPositioningContents").fadeOut("fast");
 $(".mvEyecareContents").fadeOut("fast");
 $(".mvFinetechContents").fadeOut("fast");
});

});

