/*-----------------------------------------------------------
index:
	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);
			}
		}
	}

}

/* 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;
	
	var now = 1;

	while( 1 ) {

		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];
		
		var k = parseInt(sv_element[n].width()/sv_range[n]);
		if (parseInt(sv_element[n].width()%sv_range[n])!=0) {
			k++;
		}
		for( j = 1; j < ( k+1 ); j++) {
			$("#scrollpagebtn").append("<div id='sv_pageButton"+j+"' class='pageOff'></div");
		}
		$(".scrollbtn").width(62 + 23 * k);
		sv_changePageBtn(now);

		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 );
					now += 1;
					sv_changePageBtn( now );
				}
			});

			$("#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 );
					now -= 1;
					sv_changePageBtn( now );
				}
			});
			
			$("div[id*='sv_pageButton']").click( function(e) {
					var i = e.target.id.split("sv_pageButton")[1];
					sv_tx[n2] = -[n2] * (i-1);
					sv_element[n2].stop();
					sv_element[n2].animate({ left:sv_tx[n2] }, 600 );
					now = i - 0;
					sv_changePageBtn( now );
			});
			
			
		}
		n++;
		n2++;
	}
}

function sv_changePageBtn( p ) {
	$("div[id*='sv_pageButton']").attr("class", "pageOff");
	$("#sv_pageButton"+( p )).attr("class", "pageOn");
}

function sv_zero( n ) {
	return ( n == 0 ) ? "" : n;
}

/* 選択されたページに該当するメニュー画像 
-----------------------------------------------------------*/
function changeActive(){

	var showObj = location.href;
	myData = showObj.split("/");

	for (var i = 0; i < myData.length; i++) {
		var $node = $("#" + myData[i] + "-m");
		if( $node.size() == 1 ) {
			var src = $node.attr('src');
			var ftype = src.substring( src.lastIndexOf('.'), src.length );
			var hsrc = src.replace( ftype, '_o'+ftype );
			$node.removeClass("over").attr('src',hsrc);
		}
	}
};

/* Slideshow
-----------------------------------------------------------*/
function slideShow( element, interval, speed ) {
	
	if ( $(element).length < 2 ) return;
	if ( !$(element+".current").length ) $(element+":first").addClass("current");
	
	$( element + ":not(.current)" ).css("opacity", 0 );
	
	setInterval( function(){
	
		var $current = $(element+".current");
		var $next = $current.next().length ? $current.next() : $(element+":first");
		
		$current.removeClass("current").animate( {opacity: 0}, speed );
		$next.addClass("current").animate( {opacity: 1.0}, speed );
	
	}, interval );
	
}

/* Window Onload
-----------------------------------------------------------*/
$(function(){
		   
	initRollovers();
	
	entryChangeConv();
	$('#convenience-1').change(entryChangeConv);

	// 検索窓にフォーカスすると文字が消える
	$("#globalNav input#search").focus(function() {
		if($(this).val() == $(this).attr('defaultValue'))
		$(this).val('');
	}).blur(function() {
			if(jQuery.trim($(this).val()) == "") {
			$(this).val($(this).attr('defaultValue'));
		}
	});

	/*商品スクロール基礎：商品詳細用*/
	$("#goodsDetail .horizonScroll").each(function(){
		sv_initHScrollView([133]);
	});

	/*商品スクロール基礎：カート用*/
	$("#shoppingCart .horizonScroll").each(function(){
		sv_initHScrollView([132]);
	});

	$("#grand-top #scrollable_wrap").each(function() {
		$(".scrollable").scrollable({circular:true}).autoscroll({ autoplay:true, interval:6000 });
	});

	$("#goods").each(function(){
		$("#main .boder_itemGroupThumbs:last-child").removeClass("boder_itemGroupThumbs").addClass("border_none_itemGroupThumbs");
		$('.itemGroupList table:last-child').css('background-image','none');
	});
	
	$("#shoppingCart").each(function() {
		$('.itemGroupThumbs .singleL:last-child').css('background-image','none');
	});	

	$("#members").each(function() {
		$('.basic_table1 table.selectway tr:last-child').css('background-image','none');
		$('.basic_table1 table#goodsListItems tr:last-child').css('background-image','none');
	});

	$("#members #memberNav").each(function(){
		changeActive();
	});	

	$("#order").each(function() {
		$('.basic_table1 table.selectway tr:last-child').css('background-image','none');
		$('.basic_table1 table.selectway tbody tr:last-child').css('background-image','none');
	});
});


/* コンビニ決済
-----------------------------------------------------------*/
// 選択されたコンビニの詳細を表示し、その他の詳細を非表示にする
function entryChangeConv(){
if(document.getElementById('convenience-1')){
// 選択されたコンビニの値を取得
id = document.getElementById('convenience-1').value;
	// セブン-イレブン
	if(id=='1'){
	$('#conv01').css("display","block");
	$('#conv02').css("display","none");
	$('#conv03').css("display","none");
	$('#conv04').css("display","none");
	$('#conv05').css("display","none");
	$('#conv06').css("display","none");
	// ローソン
	}else if(id=='2'){
	$('#conv01').css("display","none");
	$('#conv02').css("display","block");
	$('#conv03').css("display","none");
	$('#conv04').css("display","none");
	$('#conv05').css("display","none");
	$('#conv06').css("display","none");
	// ファミリーマート
	}else if(id=='3'){
	$('#conv01').css("display","none");
	$('#conv02').css("display","none");
	$('#conv03').css("display","block");
	$('#conv04').css("display","none");
	$('#conv05').css("display","none");
	$('#conv06').css("display","none");
	// サークルＫサンクス
	}else if(id=='4'){
	$('#conv01').css("display","none");
	$('#conv02').css("display","none");
	$('#conv03').css("display","none");
	$('#conv04').css("display","block");
	$('#conv05').css("display","none");
	$('#conv06').css("display","none");
	// ミニストップ
	}else if(id=='5'){
	$('#conv01').css("display","none");
	$('#conv02').css("display","none");
	$('#conv03').css("display","none");
	$('#conv04').css("display","none");
	$('#conv05').css("display","block");
	$('#conv06').css("display","none");
	// デイリーヤマザキ
	}else if(id=='6'){
	$('#conv01').css("display","none");
	$('#conv02').css("display","none");
	$('#conv03').css("display","none");
	$('#conv04').css("display","none");
	$('#conv05').css("display","none");
	$('#conv06').css("display","block");
	// 上記以外の場合
	} else {
	$('#conv01').css("display","none");
	$('#conv02').css("display","none");
	$('#conv03').css("display","none");
	$('#conv04').css("display","none");
	$('#conv05').css("display","none");
	$('#conv06').css("display","none");
}
}
} // JavaScript Document
