/*------------------------------------------------------------------------------
カワチサイト用共通JSスクリプト
------------------------------------------------------------------------------*/

//ONLOAD
$(document).ready(function(){
	
	//ヘッダのICONのonmouse
	/*
	$('#header_icons a').mouseover( function(){
		$(this).fadeTo(1, 0.6);
	});
	$('#header_icons a').mouseout( function(){
		$(this).fadeTo(1, 1);
	});
	*/
	
	//クラスのonmouse
		/*
		$('.brandTable a').mouseover( function(){
			$(this).fadeTo(1, 0.6);
		});
		$('.brandTable a').mouseout( function(){
			$(this).fadeTo(1, 1);
		});
		**/
	
	
	
	$('a').mouseover( function(){
		$(this).fadeTo(1, 0.6);
	});
	$('a').mouseout( function(){
		$(this).fadeTo(1, 1);
	});
	
	
	//画像サイズ
	var i = 0;
	while( i < $('.imgClickSelecter').length ){
		//alert( $('.imgClickSelecter :eq(' + i + ')' ).attr('src') );
		if( $('.imgClickSelecter:eq(' + i + ')' ).width() > 140 ){
			$('.imgClickSelecter:eq(' + i + ')' ).width( 140 );
		}
		i ++ ;
	}
	
	//画像の数が一つなら並べない
	var i = 0;
	while( i < $('.imgClickSelecterStage').length ){
		var children = $('.imgClickSelecterStage:eq(' + i + ')' ).children('a');
		//alert( children.length );
		if( children.length < 2 ){
			$('.imgClickSelecterStage:eq(' + i + ')' ).css( 'display', 'none' );
		}
		i ++ ;
	}
	
	
	//ツールチップ
	if( $('.toolTipItems').length ){
		//alert($('.toolTipItems').length);
		$('.toolTipItems').attr( 'title', '' );
		$('.toolTipItems').tooltip({
			delay: 0,
			showURL: false,
			bodyHandler: function() {
				var rel = $(this).attr('rel');
				rel = rel.replace(/::/g, "　<br />\n　" );
				rel += '　';
				return rel;
			}
		});
	}
	
	if( $('.categoryThumb').length ){
		$('.categoryThumb').attr('title','');
	}
	
	//$("#header_menubar_news_str").jStockTicker({interval: 30});
	
	//レコメンドエンジンの場所
	if( $('#recommendArea').length > 0 ){
		if( $('#recommendArea').height() > 400 ){
			$('#recommendArea').height( 400 );
			$('#recommendArea').css( 'overflow', 'scroll' );
		}
	}
	
	//度入りの窓用
	if( $('#iframeArea').length > 0 ){
		$('#iframeArea').dialog({
			modal: true,
			height: 500,
			width: 680,
			resizable: false,
			autoOpen: false
		});
	}
	
});



//画像切替//------------------------------------------------------------------//
/*
* @param string dispid 表示切り替えするID
* @param string imgsrc 表示する画像のsrc
*/
function imageStageChange( dispid, imgsrc ){
	document.getElementById( dispid ).src = imgsrc;
	return;
}
//============================================================================//


// ---------------------------------------------------------


/**
 * 度入りボタン（直接度入り - 加工 ）
 * @param DOMobje but 押されたボタン
 * @param int proc 加工費
 * @return void
 **/
function getOptButDirect( but, proc ){
	var f = $(but).parent('form').get(0);
	//$('#iframeArea').dialog('open');
	
	callOpt(
		f.itemid.value,
		f.itemname.value,
		'',
		'',
		f.price.value,
		1,
		proc,
		f.qty.value
	);
	
	
}

// ---------------------------------------------------------


/**
 * 度入りボタン（直接 - アダプタ）
 * @param DOMobje but 押されたボタン
 * @param int proc 加工費
 * @return void
 **/
function getOptButAdapter( but, proc ){
	var f = $(but).parent('form').get(0);
	//$('#iframeArea').dialog('open');
	
	callOpt(
		f.itemid.value,
		f.itemname.value,
		'',
		'',
		f.price.value,
		2,
		proc,
		f.qty.value
	);
	
}

// ---------------------------------------------------------


/**
 * 度入りボタン（インナー）
 * @param DOMobje but 押されたボタン
 * @param int proc 加工費
 * @return void
 **/
function getOptButInner( but, proc ){
	var f = $(but).parent('form').get(0);
	//$('#iframeArea').dialog('open');
	
	callOptInner(
		f.itemid.value,
		f.itemname.value,
		'',
		'',
		f.price.value,
		proc,
		f.qty.value
	);
	
}

// ---------------------------------------------------------


function callOpt( itemid, itemname, maker, dir, price, procType, procPrice, qty  ){
	
	var url = 	'/sportsLensPlus/' +
				'?itemid=' + encodeURIComponent( itemid ) + 
				'&itemname=' + encodeURIComponent( itemname ) + 
				'&dir=' + encodeURIComponent( dir ) + 
				'&maker=' + encodeURIComponent( maker ) + 
				'&price=' + encodeURIComponent( price ) +
				'&procType=' + procType +
				'&procPrice=' + procPrice +
				'&qty=' +  qty;
	
	var src = '<iframe src="' + url + '" style="width:645px; border:none; height:440px;" id="lensif"></iframe>';
	$('#iframeArea').html( src );
	$('#iframeArea').dialog( 'open' );
	
}

// ---------------------------------------------------------

function callOptInner( itemid, itemname, maker, dir, price, procPrice, qty  ){
	
	var url = 	'/sportsLensPlus/index2.html' +
				'?itemid=' + encodeURIComponent( itemid ) + 
				'&itemname=' + encodeURIComponent( itemname ) + 
				'&dir=' + encodeURIComponent( dir ) + 
				'&maker=' + encodeURIComponent( maker ) + 
				'&price=' + encodeURIComponent( price ) +
				'&procPrice=' + procPrice +
				'&qty=' +  qty;
	
	var src = '<iframe src="' + url + '" style="width:645px; border:none; height:440px;" id="lensif"></iframe>';
	$('#iframeArea').html( src );
	$('#iframeArea').dialog( 'open' );
	
}

// ---------------------------------------------------------
