/*-----------------------------------------------------------
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([144]);
	});
	/*カートマイリスト*/
	$("#shoppingCart").each(function(){
		sv_initHScrollView([130]);
	});

	/*パンくずリスト*/
	$('#topicPath li:first-child').addClass('home');
	$('#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");
		}
	);
	 */

});


/* Search
-----------------------------------------------------------*/

function printYearLink(){
	now = new Date();
	thisYear = now.getFullYear();
	if(now.getMonth() == 11){
		thisYear++;
	}
	for(i=2002;i<=thisYear;i++){
		document.write('| <a href="#" onclick="javascript:document.getElementById(\'show\').innerHTML = document.getElementById(\'div' + i + '\').innerHTML;document.getElementById(\'tyear\').innerHTML =' + i + '">' + i + '</a> ');
	}
	document.write('|');
}

function printYearOption(){
	now = new Date();
	thisYear = now.getFullYear();
	if(now.getMonth() == 11 && now.getDate() > 14){
		thisYear++;
	}
	for(i=thisYear;i>=1984;i--){
		document.write('<option value="' + i + '">' + i + '年</option>\n');
	}
}

