$().ready(function(){
//global current ///////////////////////////////
var thisURL = location.href;
$('#globalNavi a').each(function(){
var linkURL = $(this).attr('href');
if (thisURL.match(linkURL)){
var thisSRC = $(this).children('img').attr('src').replace('.gif','_over.gif');
$(this).children('img').attr('src',thisSRC);
$(this).children('img').removeClass();
}
});

//menu current ///////////////////////////////
$('.parent a').each(function(){
var linkURL = $(this).attr('href');
if (thisURL.match(linkURL)){
$(this).parent('li').children('ul').show();
var thisSRC = $(this).children('img').attr('src').replace('.gif','_current.gif');
$(this).addClass('default');
$(this).children('img').attr('src',thisSRC);
$(this).children('img').removeClass();
}
});

//menu accordion ///////////////////////////////////////////

$('#acc1').children('a').click(function(){
$(this).blur().addClass('default');;
$(this).children('img').attr('src','/common/images/menu/menu02_00_current.gif');
$(this).parent('li').children('ul').slideDown({easing:"easeInSine", duration:500});
$('#acc2').children('ul').slideUp({easing:"easeInSine", duration:500});
$('#acc2').children('a').children('img').attr('src','/common/images/menu/menu03_00.gif');
$('#acc2').children('a').removeClass('default');
return false;
});
$('#acc2').children('a').click(function(){
$(this).blur().addClass('default');
$(this).children('img').attr('src','/common/images/menu/menu03_00_current.gif');
$(this).parent('li').children('ul').slideDown({easing:"easeInSine", duration:500});
$('#acc1').children('ul').slideUp({easing:"easeInSine", duration:500});
$('#acc1').children('a').children('img').attr('src','/common/images/menu/menu02_00.gif');
$('#acc1').children('a').removeClass('default');
return false;
});

//Header Counter ////////////////////////////////////
$('#counterNum').load('/counter.txt');

//biggerLink ////////////////////////////////////////

$('a[target="_blank"]').click(function(){
	window.open(this.href);
	return false;
});

$('a[rel="external"]').click(function(){
	window.open(this.href);
	return false;
});

$('.linkBox').biggerlink();


//Footer Copyright Year////////////////////////////////////////
$('address span').text(new Date().getFullYear());


//categoryIndex bigger Link ///////////////////////////////////
$('.idx2').bind('mouseenter',function(){
var thisIMG = $(this).children('dt').children('a').children('img');
var thisIMG2 = $(this).children('dd').children('.photo').children('img');
thisIMG.attr( 'src', PEPS.rollover.newimage(thisIMG.attr('src')) );
thisIMG2.attr( 'src', PEPS.rollover.newimage(thisIMG2.attr('src')) );
});
$('.idx2').bind('mouseleave',function(){
var thisIMG = $(this).children('dt').children('a').children('img');
var thisIMG2 = $(this).children('dd').children('.photo').children('img');
thisIMG.attr( 'src', PEPS.rollover.oldimage(thisIMG.attr('src')) );
thisIMG2.attr( 'src', PEPS.rollover.oldimage(thisIMG2.attr('src')) );
});


//operation bigger Link ///////////////////////////////////
$('.idx:even').addClass('mr10').css('clear','left');
$('.idx').bind('mouseenter',function(){
var thisIMG = $(this).children('dt').children('a').children('img');
thisIMG.attr( 'src', PEPS.rollover.newimage(thisIMG.attr('src')) );
});
$('.idx').bind('mouseleave',function(){
var thisIMG = $(this).children('dt').children('a').children('img');
thisIMG.attr( 'src', PEPS.rollover.oldimage(thisIMG.attr('src')) );
});


//IE6 Round Border Fix////////////////////////////
if ($.browser.msie && $.browser.version <= 6){
$('.round').each(function(){
var roundHeight = $(this).height();
if( roundHeight % 2 == 0){}
else { $(this).height(roundHeight + 1); }
});

var roundWidth = $('.wrapper').width() - 428;
if( roundWidth % 2 == 0){ $("#contents").css('margin-right','210px'); }
else { $("#contents").css('margin-right','209px'); }
$(window).resize(function(){
var roundWidth = $('.wrapper').width() - 428;
if( roundWidth % 2 == 0){ $("#contents").css('margin-right','210px'); }
else { $("#contents").css('margin-right','209px'); }
});
}

function iefix() {
if ($.browser.msie && $.browser.version <= 6){
$('.round').each(function(){
$(this).height('1%');
var roundHeight = $(this).height();
if( roundHeight % 2 == 0){}
else { $(this).height(roundHeight + 1); }
});
}
}


//tab switch//
$('.tab.menu a').click(function(){										 
$('.tab.menu').hide();
$('.menuCont').hide();
$('.tab.machine').show();
$('.machineCont').show();
iefix();
});
$('.tab.machine a').click(function(){										 
$('.tab.machine').hide();
$('.machineCont').hide();
$('.tab.menu').show();
$('.menuCont').show();
iefix();
});

$('.tab.topics a').click(function(){										 
$('.tab.topics').hide();
$('.topicsCont').hide();
$('.pressCont').show();
$('.tab.press').show();
iefix();
});
$('.tab.press a').click(function(){										 
$('.tab.press').hide();
$('.pressCont').hide();
$('.tab.topics').show();
$('.topicsCont').show();
iefix();
});

// png fix for IE6 ////////////////////////////////////////
if ($.browser.msie && $.browser.version <= 6){
DD_belatedPNG.fix('.pfix');
}

// あとで電話とお困りですか ////////////////////////////////////////

//お困りですかのインターバルスタート
timer = setInterval(floatWdwHelp, 480000);

//あとで電話のボタンを押したとき
$('.calltrgr').click(function(){
	clearInterval(timer);
	$('#help').hide();
	floatWdw();
});

//helpflagのクッキーがセットされていなければセット
if($.cookie('helpflag') == null){
	$.cookie('helpflag', 0,{ expires: 7 ,path: '/'});
}

//お困りですか内のボタンが押されたとき
$('.helpBTN' ).click(function(){
	var helpFlag = document.helpflag.helpCheck.checked;
	if(helpFlag){
		$.cookie('helpflag', 1,{ expires: 7 ,path: '/'});
	}
});

//オーバーレイか閉じるボタンが押されたとき
$('.btnClose , #layer' ).click(function(){
	var helpFlag = document.helpflag.helpCheck.checked;
	if(helpFlag){
		$.cookie('helpflag', 1,{ expires: 7 ,path: '/'});
	}
	clearInterval(timer);
	if($.cookie('helpflag') == 0){
	timer = setInterval(floatWdwHelp, 480000);
	}
	$('#callLater').hide();
	$('#help').hide();	
	$('#layer').hide();	
});

//あとで電話を開くファンクション
function floatWdw() {
	var widthCtr = $(window).width() / 2;
	var heightCtr = $(window).height() / 2;
	$('#layer').show();
	$('#callLater').show();
	var mgHeight = $('#callLater').height() /2;
	var mgWidth = $('#callLater').width() /2;
	$('#callLater').css({'top': heightCtr - mgHeight + 'px','left': widthCtr - mgWidth + 'px'});
	if ($.browser.msie && $.browser.version <= 6){
		var scrTop = $(window).scrollTop();
		$('#layer').css('top',scrTop);
		$('#callLater').css({'top':scrTop + heightCtr - mgHeight + 'px','left': widthCtr - mgWidth + 'px'});
		$(window).scroll(function(){
			var scrTop = $(window).scrollTop();
			$('#layer').css('top',scrTop);
			$('#callLater').css({'top':scrTop + heightCtr - mgHeight + 'px','left': widthCtr - mgWidth + 'px'});
			$('#layer').height(heightCtr*2);
		});
	}
}

//お困りですかを開くファンクション
function floatWdwHelp() {
	if($.cookie('helpflag') == 0){
		var widthCtr = $(window).width() / 2;
		var heightCtr = $(window).height() / 2;
		$('#layer').show();
		$('#help').show();
		var mgHeight = $('#help').height() /2;
		var mgWidth = $('#help').width() /2;
		$('#help').css({'top': heightCtr - mgHeight + 'px','left': widthCtr - mgWidth + 'px'});
		if ($.browser.msie && $.browser.version <= 6){
			var scrTop = $(window).scrollTop();
			$('#layer').css('top',scrTop);
			$('#help').css({'top':scrTop + heightCtr - mgHeight + 'px','left': widthCtr - mgWidth + 'px'});
			$(window).scroll(function(){
				var scrTop = $(window).scrollTop();
				$('#layer').css('top',scrTop);
				$('#help').css({'top':scrTop + heightCtr - mgHeight + 'px','left': widthCtr - mgWidth + 'px'});
				$('#layer').height(heightCtr*2);
			});
		}
	}
}


// Welcome banner for first time ////////////////////////////////////////
var today = new Date().getDate();
if($.cookie('fisrtvisit') == null){
welcomebanner();
$.cookie('fisrtvisit', today,{ expires: 7 ,path: '/'});
} else if ($.cookie('fisrtvisit') == today){
welcomebanner();
}
function welcomebanner(){
$('body').prepend('<div id="firstUser"></div>');
$('#firstUser').load('/common/include/first_user.html', function(){
setTimeout(function(){
$('#firstUser').slideDown(1000);
},3000);
$('#firstUser .over').bind('mouseenter',function(){
$(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) );
});
$('#firstUser .over').bind('mouseleave',function(){
$(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) );
});
$('#firstUser #fu04 img').click(function(){
$('#firstUser').slideUp();
$.cookie('fisrtvisit', 0 ,{ expires: 7 ,path: '/'});
});
});
}


PEPS.rollover.init();
//End of doccument ready ////////////////////////////////////////
});

// Roll over ////////////////////////////////////////

PEPS = {};
PEPS.rollover = {
init: function(){
this.preload();

$(".over").hover(
function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
);},

preload: function(){
$(window).bind('load', function() {
$('.over').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
$('.idx img').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
$('.idx2 img').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
});},

newimage: function( src ){
return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_over' + src.match(/(\.[a-z]+)$/)[0];
},

oldimage: function( src ){
return src.replace(/_over\./, '.');
}
};
// Roll over end ////////////////////////////////////////