$().ready(function(){
pageTopFst();
$(window).scroll(function(){
pageTop();
});
$(window).resize(function(){
pageTop();
});
//checking Agreement ///////////////////////////////

$('#agreeCheck').click(function(){
var agree = document.agreement.ag1.checked;
if (agree){location.href = "form.php";}
else { alert("優住協の会員お申し込みには、規約への同意が必要です。");}
});

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

$('#subNav a').each(function(){
var linkURL = $(this).attr('href');
if (thisURL.match(linkURL)){
var thisSRC = $(this).children('img').attr('src').replace('.gif','_current.gif');
$(this).children('img').attr('src',thisSRC);
$(this).children('img').removeClass();
}
});

$('#tab 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).parent('li').addClass('current');
$(this).children('img').removeClass();
}
});


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

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

// pagetop ////////////////////////////////////////

function pageTopFst() {
	var winHeight = $(window).height();
	var winscroll = $(window).scrollTop();
	var wrapperHeight = $('.wrapper').height();
	var imgHeight = $('#mainImage img').height();
	var ttlHeight = $('#title img').height();
	var minHeight = imgHeight + ttlHeight + 80;
	var maxHeight = wrapperHeight-220;
	var pos = winscroll + winHeight -120;
	if( pos < minHeight ){
		pos = minHeight;
	} 
	if (pos > maxHeight ) {
		pos = maxHeight;
	}
$('.pagetop').css({top: pos +'px' });
}

function pageTop() {
	var winHeight = $(window).height();
	var winscroll = $(window).scrollTop();
	var wrapperHeight = $('.wrapper').height();
	var imgHeight = $('#mainImage img').height();
	var ttlHeight = $('#title img').height();
	var minHeight = imgHeight + ttlHeight + 80;
	var maxHeight = wrapperHeight-220;
	var pos = winscroll + winHeight -120;
	if( pos < minHeight ){
		pos = minHeight;
	} 
	if (pos > maxHeight ) {
		pos = maxHeight;
	}
setTimeout(function(){
$('.pagetop').stop();
$('.pagetop').animate({top: pos +'px' },1500,'easeOutExpo');
},500);
}
PEPS.rollover.init();

// method  ////////////////////////////////////////
$('.methodList div:even').addClass('clear');

//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 ////////////////////////////////////////
