var IE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;

// ------------- 背景ライン -----------------//

function bcgLinePosition() {
	var bcgX;

	if($(window).width()<=960){
		var w = 960;
	} else {
		var w = $(window).width();
	}

	bcgX = (w-960)/2 - 1100 + 312;
	bcgX = Math.floor(bcgX);

	$("#bcgLine1").css({
		width: $(window).width(),
		height: $(window).height(),
		backgroundPosition: bcgX + 'px 0'
	});	
}

if(!IE6){ /* ie6以外 */
	$(function(){
		$('body').prepend('<div id="bcgLine1"></div>');
		$('#bcgLine1').css({
			width: $(window).width(),
			height: $(window).height(),
			position: 'absolute',
			top:'130px',
			left: '0',
			background: 'transparent url(../images/body_bcg_img1.png) no-repeat -1100px 0',
			zIndex: '-10'
		});

		bcgLinePosition();
	});


	$(window).resize(function(){
		bcgLinePosition();
	});

	var lineOverFlag = false;

	$(window).scroll(function () {
		var scrolltop = $(window).scrollTop();

		if (scrolltop >= 130 && lineOverFlag == false ) {
			lineOverFlag = true;
			$('#bcgLine1').css({
				position : 'fixed',
				top : '0'
			});
		} else if (scrolltop < 130 && lineOverFlag == true ) {
			lineOverFlag = false;
			$('#bcgLine1').css({
				position : 'absolute',
				top : '130px'
			});
		}
	});
}


// ------------- ボーダーボックス -----------------//

$(function(){
	$(".secB").css({
		background: 'transparent url(../images/common_img1.gif) repeat 0 0',
		border : 'none',
		padding : '1px'
	});

	$(".secB").wrapInner(
		$('<div></div>').css({
			backgroundColor :'#fff',
			padding : '30px'
		})
	);
});



// ------------- サイドバナー読み込み -----------------//

$(function(){
	$('body:not(#top) #cnt').append('<div id="cntRight"></div>');
	//$('#cntRight').load('../sidecnt/index.html div.section');

	$('body:not(#top) #cntRight').load('../sidecnt/index.html div.section');
});



// ------------- ページの先頭へ -----------------//
$(function(){
	$('#topNav img').click(function(){
			$($.browser.opera ? document.compatMode == 'BackCompat' ? 'body' : 'html' :'html,body').animate({
				scrollTop: 0
			}, 500);
			return false;
	});
});





// ------------- トップロゴ -----------------//

function topLogo(){
	if(!IE6){ /* ie6以外 */
		var cnts = '<div id="logoBox"><img src="images/pagetitle_bcg.png" /></div>'
		$('#mainImgBlock').append(cnts);
		$('#logoBox').css({
			position:'absolute',
			zIndex: 1,
			top: -20,
			left: 20
		})
	}
}



// ------------- トップ切り替え画像 -----------------//

function changeImages() {

	var imgNum = $('#mainImgBlock li').size();
	var id =1;

	$('#mainImgBlock li').eq(id-1).fadeIn(1200);
	
	var t = setInterval(changeImg, 7000);
	
	function changeImg(){
		$('#mainImgBlock li').eq(id-1).fadeOut(800);

		if(id<imgNum){
			id++;
		} else {
			id=1;
		}
		
		$('#mainImgBlock li').eq(id-1).fadeIn(1200);
	}
}


// ------------- トップブログ読み込み -----------------//

function loadFeed() {

    var feed = new google.feeds.Feed("http://miyagoas.jugem.jp/?mode=rss");
    feed.setNumEntries(5);

    feed.load(function(result) {
		
        var html;
        if (!result.error) {
            // 各記事の情報を順に出力
            if (result.feed.entries.length) {
                html = '<dl>';
                for (var i = 0; i < result.feed.entries.length; i++) {

                    var entry = result.feed.entries[i];
					var date = new Date(entry.publishedDate);
					var dateY = date.getFullYear();
					var dateM = date.getMonth()+1;
					var dateD = date.getDate();
					var str = dateY + "." + dateM + "." + dateD;

					html += '<dt lang="en">' + str + '</dt>';
                    html += '<dd><a href="' + entry.link + '" target="_blank">' + entry.title + '</a></dd>';
                }
                html += '</dl>';
            }
        }

        var container = document.getElementById("newsSec");
        container.innerHTML = html;

		$('#cntLeft .secA dd').eq(1).css('background','#f2f8f5');
		$('#cntLeft .secA dd').eq(3).css('background','#f2f8f5');
    });
}


// ------------- FAQ -----------------//

function FaqPanel(){

	var hArray = new Array();

	for(i=0; i <= $('#faq #cntLeft dd').size(); i++){
		hArray[i] = $('#faq #cntLeft dd').eq(i).height();
			
		$('#faq #cntLeft dd').eq(i).css({
			display:'none',
			height:hArray[i]+15,
			backgroundPosition: '7px 18px'
		});
	}
	
	$('#faq #cntLeft dt').hover(
		function(){
			$(this).css({
				cursor:"pointer",
				backgroundColor:"#f2f2f2"
			});
		},function(){
			$(this).css({
				cursor:"default",
				backgroundColor:"#fff"				
			});
		}
	);

	$('#faq #cntLeft dt').click(
		function(){
			var num = $('#faq #cntLeft dt').index(this);			
			$('#faq #cntLeft dd').eq(num).slideToggle(400);
		}
	);
}




// ------------- courses -----------------//

function Courses(){

	var id = 0;

	if(location.hash=="#course1"){ id = 0; };
	if(location.hash=="#course2"){ id = 1; };
	if(location.hash=="#course3"){ id = 2; };
	if(location.hash=="#course4"){ id = 3; };
	if(location.hash=="#course5"){ id = 4; };
	if(location.hash=="#course6"){ id = 5; };
	if(location.hash=="#course7"){ id = 6; };
	if(location.hash=="#course8"){ id = 7; };
	if(location.hash=="#course9"){ id = 8; };
	if(location.hash=="#course10"){ id = 9; };

	
	$('#coursesCnts div.block').css({
		display : 'none'
	});

	$('#coursesCnts div.block').eq(id).show();

	var tg = $('#coursesNav li').eq(id).find('img');
	$(tg).attr('src', $((tg)).attr('src').replace(/^(.+)(\.[a-z]+)$/, '$1_a$2'));

	$('#coursesNav li').click(
		function(){
			if(id != $('#coursesNav li').index(this)){

				$('#coursesCnts div.block').eq(id).hide();
				var tg = $('#coursesNav li').eq(id).find('img');
				$(tg).attr('src', $((tg)).attr('src').replace(/^(.+)_a(\.[a-z]+)$/, '$1$2'));

				id = $('#coursesNav li').index(this);

				$('#coursesCnts div.block').eq(id).fadeIn(400);
				tg = $('#coursesNav li').eq(id).find('img');
				$(tg).attr('src', $((tg)).attr('src').replace(/^(.+)_on(\.[a-z]+)$/, '$1_a$2'));	
			}
		}
	);
}



// ------------- form生年月日 -----------------//

function BirthdaySetup(){
			now = new Date();
			yy = now.getFullYear();
			for(i=1;i<=90;i++){
				yys = yy-90+i-10;
				$('#birth_year').append($('<option>').attr({ value:yys }).text(yys));
			}
			$('#birth_year').width();
			$('#birth_year').val(yy-20);
			$('#birth_year option:eq(0)').remove();


			for(i=1;i<=12;i++){
				$('#birth_month').append($('<option>').attr({ value:i }).text(i));
			}
			$('#birth_month').width();
			$('#birth_month').val(1);
			$('#birth_month option:eq(0)').remove();


			for(i=1;i<=31;i++){
				$('#birth_day').append($('<option>').attr({ value:i }).text(i));
			}
			$('#birth_day').width();
			$('#birth_day').val(1);
			$('#birth_day option:eq(0)').remove();
}



// ------------- ロールオーバー -----------------//

function rollOver(tg) {	
	$(tg).each(function(){
		//画像のプレロード
		$('<img>').attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
		

		$(this).mouseover(function(){
			var str = $(this).attr("src");
			//一致した文字列がなかった場合には-1
　			if(str.indexOf("_a")==-1){
				$(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
			
  			}
		}).mouseout(function(){
			$(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
		})
		
	});
}

$(function(){
	rollOver($('#header li a img, #footer li a img, #cntLeft li a img'));
});




