$(function(){


// グローバルナビ
    $('#globalNavi > ul li a').each(function () {
        var url = document.URL.split('/');
        var mapping = {
            'positioning': 'products',
            'eyecare': 'products',
            'finetech': 'products',
            '*source*': '*destination*'
        };
        if (mapping[url[3]]) url[3] = mapping[url[3]];
        var href = $(this).attr('href').split('/');
        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[2]){
$(this).addClass(href[1]);
    }else{
$(this).addClass(href[2]);
    if (href[0] == 'https:' && href[2] == 'www.topcon.co.jp') {
$(this).removeClass("www.topcon.co.jp");
$(this).addClass(href[3]);
}
if(href[2] == 'qw108.qhit.net' && href[3] == 'topcon'){
//$(this).removeClass("");
$(this).addClass("se_price");
$(this).children().eq(0).attr('title','Open in another window');
    }

//if (href[4] == 'movabletype') {
//$(this).hide();
//}
//if (href[4] == 'compar') {
//$(this).hide();
//}
    }
    });
    
//外部リンクに extRefを付与する
    $("#main a[target='_blank']").addClass('extRef');
//外部リンクに 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*=global.topcon.com]").attr("target","_blank");
jQuery (".section a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").addClass('extRef');
jQuery (".section h2 a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").removeClass('extRef');
jQuery (".section h2 a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").addClass('noneextRef');
jQuery ("#newsArea a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").attr("target","_blank");
jQuery ("#newsArea a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").addClass('extRef');
jQuery ("#eventArea a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").attr("target","_blank");
jQuery ("#eventArea a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").addClass('extRef');
jQuery ("#topicsArea a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").attr("target","_blank");
jQuery ("#topicsArea a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").addClass('extRef');
jQuery ("#calendar a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").attr("target","_blank");
jQuery ("#calendar a[href^=http]").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").addClass('extRef');
jQuery (".section a img").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").removeClass('extRef');
jQuery (".section a img").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").addClass('noneextRef');
jQuery ("#newsArea a img").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").removeClass('extRef');
jQuery ("#newsArea a img").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").addClass('noneextRef');
jQuery ("#eventArea a img").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").addClass('noneextRef');
jQuery ("#eventArea a img").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").addClass('noneextRef');
jQuery ("#topicsArea a img").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").addClass('noneextRef');
jQuery ("#topicsArea a img").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").addClass('noneextRef');
jQuery ("#MAP area[href^=http]").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").attr("target","_blank");
jQuery ("#MAP area[href^=http]").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").addClass('extRef');
jQuery (".section a img").not("[href*="+location.hostname+"]").not("[href*=global.topcon.com]").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+"]").not("[href*=global.topcon.com]").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">');
    });
})

//パンくずナビ2個目を非表示
$(function(){
var bread = $('ul#topicPath > li:nth-child(2) > a').text();


if($.trim(bread) == 'Global Gateway'){
$('ul#topicPath > li:nth-child(2)').css('display','none');
} else if($.trim(bread) == 'Investor Relations'){
$('ul#topicPath > li:nth-child(2)').css('display','none');
} else if($.trim(bread) == 'Area'){

$('ul#topicPath > li:nth-child(2)').css('display','none');
} else if ($.trim(bread) == 'Products') {

$('ul#topicPath > li:nth-child(2)').css('display','none');
}

var chkv = $('ul#topicPath > li:nth-child(3) > a').text();
if($.trim(chkv) == 'Announcements'){
$('ul#topicPath > li:nth-child(3)').css('display','none');
};


})




