/*-----------------------------------------------------------
index:
	Rollover Image
	Header Search Parts
	Horizon Scroll View
	Window Onload
-----------------------------------------------------------*/

/* Rollover Image
-----------------------------------------------------------*/
function initRollovers() {
	if (!document.getElementById) return

	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');
	var iImages = document.getElementsByTagName('input');

	for (var i = 0; i < aImages.length; i++) {
		if (aImages[i].className == 'over') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;

			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}

			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}

	for (var i = 0; i < iImages.length; i++) {
		if (iImages[i].className == 'over') {
			var src = iImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			iImages[i].setAttribute('hsrc', hsrc);

			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;

			iImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}

			iImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}

}

/* Header Search Parts
-----------------------------------------------------------*/
function logInFormValue(which,theValue) {
	if (document.getElementById(which).value == theValue) {
		document.getElementById(which).value='';
	}
	else if (document.getElementById(which).value == '') {
		document.getElementById(which).value=theValue;
	}
}

/* Horizon Scroll View
-----------------------------------------------------------*/
function sv_initHScrollView( range ) {

	var sv_tx = [];
	var sv_max = [];
	var sv_range = [];

	var sv_view = [];
	var sv_element = [];

	var n = 0;
	var n2 = 0;

	while( 1 ) {

		//window.alert( n );

		if( $("#sv_scrollView"+sv_zero( n )).html() == null ) {
			if ( n == 0 ) {
				n = 1;
				if( $("#sv_scrollView"+sv_zero( n )).html() == null ) break;
			} else {
				break;
			}
		}

		sv_view[n] = $("#sv_scrollView"+sv_zero( n ));
		sv_element[n] = $("#sv_scrollElement"+sv_zero( n ));

		sv_view[n].css("position","relative");
		sv_element[n].css("position", "relative");

		sv_tx[n] = 0;
		sv_max[n] = sv_element[n].width() - sv_view[n].width();
		sv_range[n] = range[n2];

		if ( sv_max[n] > 0 ) {
			$("#sv_nextButton"+sv_zero( n )).click( function(e) {
				var i = e.target.id.split("sv_nextButton")[1];
				if ( sv_tx[i] > -sv_max[i] ) {
					sv_tx[i] -= sv_range[i];
					sv_element[i].stop();
					sv_element[i].animate({ left:sv_tx[i] }, 600, "easeOutQuart" );
				}
			});

			$("#sv_prevButton"+sv_zero( n )).click( function(e) {
				var i = e.target.id.split("sv_prevButton")[1];
				if ( sv_tx[i] < 0 ) {
					sv_tx[i] += sv_range[i];
					sv_element[i].stop();
					sv_element[i].animate({ left:sv_tx[i] }, 600, "easeOutQuart" );
				}
			});
		}
		n++;
		n2++;
	}
}

function sv_zero( n ) {
	return ( n == 0 ) ? "" : n;
}

/* Window Onload
-----------------------------------------------------------*/
$(function(){

	initRollovers();

	/*商品詳細マイリスト*/
	$("#goods").each(function(){
		sv_initHScrollView([140]);
	});

	/*カートマイリスト*/
	$("#shoppingCart").each(function(){
		sv_initHScrollView([140]);
	});

	/*パンくずリスト*/
	$('#topicPath li:first-child').addClass('top');
	$('#topicPath li:last-child').addClass('last');

	/*商品一覧サムネイル 
	$('div:not("#ranking") > table.thumbsnailItem td').hover(
		function () {
			$(this).css("background-color","#EEEEEE");
		},
		function () {
			$(this).css("background-color","transparent");
		}
	);*/

	/* グランドトップ */
	$("#grand-top").each(function(){
		$("#orderinadvance div.iconBox img.icon:nth-child(even)").addClass("spacer"); 
		$("#recommend table.thumbsnailItem tr:last-child").addClass("noline");
	});

	/* 商品(一覧・サムネイル) */
	$("#goods.goodslist").each(function(){
		$(".thumbsnailBox div:last-child").addClass("last");
		$(".thumbsnailBox div.last td").addClass("lastline");
		$(".thumbsnailBox div td:nth-child(5)").addClass("lastcolumn");
		$(".thumbsnailBox div.last td:nth-child(5)").addClass("lastitem");
		$(".thumbsnailBox div.iconBox img.icon:nth-child(even)").addClass("spacer"); 
		$(".listitemBox table:last-child").addClass("noline");
	});
	/* 商品(詳細) */
	$("#goods.goodsDetail").each(function(){
		$("#relationItem-h div.iconBox img.icon:nth-child(even)").addClass("spacer"); 
		$("#footPrint div.iconBox img.icon:nth-child(even)").addClass("spacer"); 
		$("#favorite .inner td:last-child").addClass("noline");
		$("#favorite .inner div.iconBox img.icon:nth-child(even)").addClass("spacer");
	});
	/* 商品(カラーリスト) */
	$("#goods.colorlist").each(function(){
		$(".thumbsnailBox div:last-child").addClass("last");
		$(".thumbsnailBox div.last td").addClass("lastline");
		$(".thumbsnailBox div td:nth-child(5)").addClass("lastcolumn");
		$(".thumbsnailBox div.last td:nth-child(5)").addClass("lastitem");
		$(".thumbsnailBox div.iconBox img.icon:nth-child(even)").addClass("spacer"); 
	});
	/* 商品(アイテム一覧) */
	$("#goods.itemlist").each(function(){
		$(".thumbsnailBox div:last-child").addClass("last");
		$(".thumbsnailBox div.last td").addClass("lastline");
		$(".thumbsnailBox div td:nth-child(5)").addClass("lastcolumn");
		$(".thumbsnailBox div.last td:nth-child(5)").addClass("lastitem");
		$(".thumbsnailBox div.iconBox img.icon:nth-child(even)").addClass("spacer"); 
	});
	/* 商品(予約販売一覧) */
	$("#goods.advlist").each(function(){
		$(".listitemBox table:last-child").addClass("noline");
		$(".advBox div:last-child").addClass("last");
		$(".advBox div.last td").addClass("lastline");
		$(".advBox div td:nth-child(2)").addClass("lastcolumn");
		$(".advBox div.last td:nth-child(2)").addClass("lastitem");

	});
	/* 商品(予約販売バックナンバー) */
	$("#goods.advbnlist").each(function(){
		$(".thumbsnailBox div:last-child").addClass("last");
		$(".thumbsnailBox div.last td").addClass("lastline");
		$(".thumbsnailBox div td:nth-child(5)").addClass("lastcolumn");
		$(".thumbsnailBox div.last td:nth-child(5)").addClass("lastitem");
		$(".thumbsnailBox div.iconBox img.icon:nth-child(even)").addClass("spacer"); 
	});
	/* 検索一覧 */
	$("#search").each(function(){
		$(".thumbsnailBox div:last-child").addClass("last");
		$(".thumbsnailBox div.last td").addClass("lastline");
		$(".thumbsnailBox div td:nth-child(5)").addClass("lastcolumn");
		$(".thumbsnailBox div.last td:nth-child(5)").addClass("lastitem");
		$(".thumbsnailBox div.iconBox img.icon:nth-child(even)").addClass("spacer"); 
		$("#listitemBox table:last-child").addClass("noline");
	});
	/* ショッピングカート */
	$("#shoppingCart").each(function(){
		$("#relationItem-w div.iconBox img.icon:nth-child(even)").addClass("spacer"); 
		$("#footPrint-l div.iconBox img.icon:nth-child(even)").addClass("spacer"); 
		$("#favorite-l div.iconBox img.icon:nth-child(even)").addClass("spacer"); 
		$("#favorite-l .inner td:last-child").addClass("noline");
	});



});

