// JavaScript Document

//ヘッダナビゲーションのマウスオーバー
function chgNav(){
		var bgPsn = new Array;
	//ナビ見出しの初期背景位置を取得
	if(navigator.userAgent.indexOf('MSIE') >= 0){//IEの場合
		bgPsn[0] = '0px ' + $('#hnavtop h3').css('background-positionY');
		bgPsn[1] = '0px ' + $('#hnavdvd h3').css('background-positionY');
		bgPsn[2] = '0px ' + $('#hnavbd h3').css('background-positionY');
		bgPsn[3] = '0px ' + $('#hnavcd h3').css('background-positionY');
		bgPsn[4] = '0px ' + $('#hnavcosme h3').css('background-positionY');
		bgPsn[5] = '0px ' + $('#hnavdrink h3').css('background-positionY');
		bgPsn[6] = '0px ' + $('#hnavgoods h3').css('background-positionY');
		bgPsn[7] = '0px ' + $('#hnavgame h3').css('background-positionY');
																}else{//それ以外
		bgPsn[0] = $('#hnavtop h3').css('background-position');
		bgPsn[1] = $('#hnavdvd h3').css('background-position');
		bgPsn[2] = $('#hnavbd h3').css('background-position');
		bgPsn[3] = $('#hnavcd h3').css('background-position');
		bgPsn[4] = $('#hnavcosme h3').css('background-position');
		bgPsn[5] = $('#hnavdrink h3').css('background-position');
		bgPsn[6] = $('#hnavgoods h3').css('background-position');
		bgPsn[7] = $('#hnavgame h3').css('background-position');
																};

	var chkId;
	var chgBgPsn;
	var nm;
	//h3over
	$('#hnav h3,#hnav ul').mouseover(function (event){

		//マウスを乗せたカテゴリIDを取得
		chkId = $(this).parent('div').attr('id');
		
		//カテゴリによって背景位置を設定（スプライト使用）
		if(chkId == 'hnavtop'){
			chgBgPsn = '0px -26px';
			nm = 0;
		}else if(chkId == 'hnavdvd'){
			chgBgPsn = '0px -52px';
			nm = 1;
		}else if(chkId == 'hnavbd'){
			chgBgPsn = '0px -78px';
			nm = 2;
		}else if(chkId == 'hnavcd'){
			chgBgPsn = '0px -104px';
			nm = 3;
		}else if(chkId == 'hnavcosme'){
			chgBgPsn = '0px -130px';
			nm = 4;
		}else if(chkId == 'hnavdrink'){
			chgBgPsn = '0px -156px';
			nm = 5;
		}else if(chkId == 'hnavgoods'){
			chgBgPsn = '0px -182px';
			nm = 6;
		}else if(chkId == 'hnavgame'){
			chgBgPsn = '0px -208px';
			nm = 7;
	};
		//リストの表示と背景変更
		$(this).parent('div').children('ul').css('display','block');
		$(this).parent('div').children('h3').css('background-position',chgBgPsn);

	});


	//mouseout
	$('#hnav h3,#hnav ul').mouseout(function (event){
																						
		//リストの非表示
		$(this).parent('div').children('ul').css('display','none');
		
		//選択カテゴリが現在のカテゴリじゃ無ければ初期グレーに
		if(bgPsn[nm] != chgBgPsn){
				$(this).parent('div').children('h3').css('background-position','0 0');
		};
	});
};

//ドロップダウンメニューul・li（ie）の幅設定
function catUlWidth(){
	//リストのカラム数
	var lstClm = new Array;
	lstClm[0] = 2;//DVD
	lstClm[1] = 2;//Blu-ray
	lstClm[2] = 2;//CD
	lstClm[3] = 2;//cosme
	lstClm[4] = 2;//drink
	lstClm[5] = 2;//goods
	lstClm[6] = 2;//game
	
	var lstClmlen = lstClm.length;

	if(navigator.userAgent.indexOf('MSIE') >= 0){//IEの場合
			for(i = 0;i < lstClmlen;i++){
				var a = i + 2;
				var b = $('#hnav div:nth-child('+a+') ul li:nth-child(2)').css('width');
				var c = Number(b.replace(/px/,'')) + 6;
				var d = lstClm[i] + 1;
				var e = (c * lstClm[i]) + (d * 5);
				var f = e + 'px';
				$('#hnav div:nth-child('+a+') ul').css('width',f);
				var g = (c + 5) + 'px';
				$('#hnav div:nth-child('+a+') ul li').css('width',g);
			};
		//	$('#hnavcosme li.hcosttl').css('width','100%');
		}else{
			for(i = 0;i < lstClmlen;i++){
				var a = i + 2;
				var b = $('#hnav div:nth-child('+a+') ul li:nth-child(2)').css('width');
				var c = Number(b.replace(/px/,''));
				var d = lstClm[i] + 1;
				var e = (c * lstClm[i]) + (d * 5);
				var f = e + 'px';
				$('#hnav div:nth-child('+a+') ul').css('width',f);
		};
	};
};



//検索テキストボックスのフォーカス設定
function searBxBg(){
//ページロード時に背景設定
	var txBxVlf = $('#txtbx').val();//テキストボックスの初期入力値取得
	if(txBxVlf != ''){
		$('#txtbx').css('background-position','0 -25px');
	}else{
		$('#txtbx').css('background-position','0 0');
	};
//focus時に背景変更
	$('#txtbx').focus(function(){
	 $(this).css('background-position','0 -25px');
	});
//blur時
	$('#txtbx').blur(function(){
		var txBxVl = $(this).val();//テキストボックスの入力値取得
		if(txBxVl != ''){//入力されていたら何もしない
		}else{//入力されてなかったら所期背景に戻す
	 $(this).css('background-position','0 0');
		}
	});
		
};






$(document).ready(function () {
	searBxBg();
	chgNav();
	catUlWidth();
});

