
var $j = jQuery.noConflict();

// ＨＯＴ発送リロード
var _nowHotShipIndex = 0;
function hotShipReload(){

	var box = $j( "td#parapara" );
    
	if( !( "__hotShipItems" in window ) || __hotShipItems == undefined || __hotShipItems == null ){
    	return false;
	}    
    if( !_nowHotShipIndex ){
    	_nowHotShipIndex = 0;
    }
    if( !__hotShipItems[_nowHotShipIndex] ){
    	_nowHotShipIndex = 0;
    }
    if( !__hotShipItems[_nowHotShipIndex] ){
    	return false;
    }

    var nextItem = __hotShipItems[_nowHotShipIndex];
	var itemName    = nextItem['item_name'];
	var itemAddr    = nextItem['item_addr'];
	var country     = nextItem['country'];
	var countryName = nextItem['country_name'];
	var image_flg   = nextItem['image_flg'];
	if( itemName && itemAddr && countryName ){
		var newElem = $j( "#hotShipMsg" ).clone();
		$j( "a#itemLink",       newElem ).attr( 'href', itemAddr );
		$j( "a#itemLink",       newElem ).html( itemName );
		$j( "span#countryName", newElem ).html( countryName );
		$j( "td#shipDate",    newElem ).html( __hotShipItemDate );
		if( image_flg ){
			$j( "img#countryFlag", newElem ).attr( 'src', '/img/country/' + country + '.gif' );
		}
		$j( box ).fadeOut( 1000, function(){
			$j( box ).empty();
			$j( box ).append( $j( newElem ).html() );
			$j( box ).fadeIn( 1000, function(){
				window.setTimeout( hotShipReload, 3000 );
			});　	
			
		});　	
	}
	_nowHotShipIndex++;
	$j.cookie( 'hotItemViewIndex', _nowHotShipIndex, { expires:7 } );

}



// 検索タイプ選択	
function selectType( obj ){

	// オークション
	if( $j( obj ).val() == "1" && $j( obj ).attr( 'checked' ) ){
	
		$j(	"#order_bidders" ).attr( "disabled", true );
		$j( "#order_yahoo"   ).attr( "disabled", true );
		$j( "#order_amazon"  ).attr( "disabled", true );
		$j( "#order_kakaku"  ).attr( "disabled", true );
		$j( "#order_rakuten" ).attr( "disabled", true );
		$j( "#order_calamel" ).attr( "disabled", true );
			
		$j( "#auc_bidders"   ).attr( "disabled", false );
		$j( "#auc_yahoo"     ).attr( "disabled", false );

		$j( "#auc_bidders"   ).attr( "checked", true  );
		$j( "#auc_yahoo"     ).attr( "checked", true  );
		$j(	"#order_bidders" ).attr( "checked", false );
		$j( "#order_yahoo"   ).attr( "checked", false );
		$j( "#order_amazon"  ).attr( "checked", false );
		$j( "#order_kakaku"  ).attr( "checked", false );
		$j( "#order_rakuten" ).attr( "checked", false );
		$j( "#order_calamel" ).attr( "checked", false );

		$j( "#aucArea"  ).css( "background", "#E0E0E0"           );
		$j( "#aucArea"  ).css( "border",     "1px solid #808080" );
		$j( "#shopArea" ).css( "background", "none"              );
		$j( "#shopArea" ).css( "border",     "none"              );

		resetOptions( cate1_vals );
			
	}
	
	// ショッピング
	else if( $j( obj ).val() == "2" && $j( obj ).attr( 'checked' ) ){

		$j(	"#order_bidders" ).attr( "disabled", false );
		$j( "#order_yahoo"   ).attr( "disabled", false );
		$j( "#order_amazon"  ).attr( "disabled", false );
		$j( "#order_kakaku"  ).attr( "disabled", false );
		$j( "#order_rakuten" ).attr( "disabled", false );
		$j( "#order_calamel" ).attr( "disabled", false );
			
		$j( "#auc_bidders"   ).attr( "disabled", true );
		$j( "#auc_yahoo"     ).attr( "disabled", true );

		$j( "#auc_bidders"   ).attr( "checked", false );
		$j( "#auc_yahoo"     ).attr( "checked", false );
		$j(	"#order_bidders" ).attr( "checked", true  );
		$j( "#order_yahoo"   ).attr( "checked", true  );
		$j( "#order_amazon"  ).attr( "checked", true  );
		$j( "#order_kakaku"  ).attr( "checked", true  );
		$j( "#order_rakuten" ).attr( "checked", true  );
		$j( "#order_calamel" ).attr( "checked", true  );
		
		$j( "#shopArea" ).css( "background", "#E0E0E0"           );
		$j( "#shopArea" ).css( "border",     "1px solid #808080" );
		$j( "#aucArea"  ).css( "background", "none"              );
		$j( "#aucArea"  ).css( "border",     "none"              );
		
		resetOptions( cate2_vals );
		
	}
	
}

function resetOptions( vals ){

	var selectElem = $j( "#searchCategory" );
	$j( selectElem ).attr( 'disabled', true );
	$j( selectElem ).empty();
	var select_option = "";
	if(vals[""]!=""&&vals[""]!=null&&vals[""]!=undefined){
      select_option = "<option value=''>"+vals[""]+"</option>";
	}
	for( var i in vals ){
    if(i!=""){
        select_option += "<option value='"+i+"'>"+vals[i]+"</option>";
    }
	}
	$j( selectElem ).html(select_option);
	$j( selectElem )[0].options.selectedIndex = 0;
	$j( selectElem ).attr( 'disabled', false );
}

// 検索キーワード欄をリセットクリアする
function reSetKeywordData(){

	var obj = $j( "#searchKeyword" );
	if( $j( obj ).val() == "" ){
		$j( obj ).val( nothingKwyword );
		$j( obj ).css( 'color', "GrayText" );
		
	}else if( $j( obj ).val() == nothingKwyword ){
		$j( obj ).val( "" );
		$j( obj ).css( 'color', "Black" );
		
	}else{
		$j( obj ).css( 'color', "Black" );
	}
	
}

// 検索エンジンに飛びます
function dosubmit( f ){

	// キーワード入力チェック
	var search = $j( "#searchKeyword", f ).val();
	if( !search || search == "" || search == nothingKwyword ){
		alert( nothingKwyword );
		$j( "#searchKeyword" ).focus();
		return false;
	}
	
	// 検索対象チェック
	var hit = false;
	$j( 'input[type=checkbox]', f ).each( function(){
		if( $j( this ).attr( 'checked' ) ){
			hit = true;
		}
	});
	if( !hit ){
		alert( "Please choose site!" );
		return false;
	}

	// ＯＫ
	return true;
	
}

function otherAction(){
	$j( "#otherForm" ).submit();
	return false;
}

// ダイレクト注文対象ボタンクリック
function directTargetClick( target ){

	$j( '#rdo_direct_target_' + target ).attr( 'checked', true );

	if( target == 's' ){

		$j( '#item_addr_div_title' ).html( spItemAddrLabel );

		$j( '#bidding_mode_div_title'  ).hide();
		$j( '#bidding_mode_div_detail' ).hide();

		$j( '#site_choose_div_title'  ).show();
		$j( '#site_choose_div_detail' ).show();
		specialTargetClick();

		// ボタン画像切り替え
		setDirectSpecialImage();
		
		// 注意書き切り替え
		setNoticeSpecial();
		
	
	}else{

		$j( '#item_addr_div_title' ).html( aucItemAddrLabel );

		// ヤフオク入札用エリア
		$j( '#bidding_mode_div_title'  ).show();
		$j( '#bidding_mode_div_detail' ).show();

		// 他サイト注文用エリア
		$j( '#site_choose_div_title'  ).hide();
		$j( '#site_choose_div_detail' ).hide();
		$j( "#item_name_div_title"    ).hide();
		$j( "#item_name_div_detail"   ).hide();

		// ボタン画像切り替え
		setDirectAucImage();
		
		// 注意書き切り替え
		setNoticeAuc();
		
	}

}

// 他サイト注文区分選択
function specialTargetClick(){
	if( $j( '#rdo_sp_site_1' ).attr( 'checked' ) ){
		$j( "#item_name_div_title"  ).hide();
		$j( "#item_name_div_detail" ).hide();
	}else{
		$j( "#item_name_div_title"  ).show();
		$j( "#item_name_div_detail" ).show();
	}
}

// ダイレクト実行
function directAction( from ){

	var addr     = $j( '#txt_item_addr' ).val();
	var quantity = $j( '#txt_quantity'  ).val();
	if( addr && quantity && !isNaN( quantity ) ){
		$j( '#directForm' ).submit();
	}
	return false;
	
}

function hotAction( obj ){
	var keyword = $j( obj ).html();
	$j( "#searchKeyword" ).val( keyword );
	reSetKeywordData();
	$j( "#btn_search" ).click();
}

function whatsNewOpen(){
	var www = window.open( '/member/news.php', 'NEWS', 'height=400, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no' );
	www.focus();
	return false;
}

$j( document ).ready( function(){

	// ＨＯＴ発送
	_nowHotShipIndex = $j.cookie( 'hotItemViewIndex' );
	window.setTimeout( hotShipReload, 5000 );

	// WhatsNewマーキーイベント
	$j( "#whatsNewMarquee" ).mouseover( function(){ this.stop();  });
	$j( "#whatsNewMarquee" ).mouseout ( function(){ this.start(); });
	$j( "#whatsNewMarquee" ).click( function(){ whatsNewOpen(); });

	// 検索対象ラジオボタンの選択
	$j( ".stRdo" ).click( function(){
		selectType( this );
	});

	// 検索キーワードテキストボックスの出入
	$j( "#searchKeyword" ).focus( function(){ reSetKeywordData(); });
	$j( "#searchKeyword" ).blur ( function(){ reSetKeywordData(); });
	
	// ホットキーワードクリック
	$j( ".hotLink" ).click( function(){ return hotAction( this ); });
	
	// ダイレクト注文ラジオボタンの選択
	$j( '#rdo_direct_target_s' ).click( function(){ directTargetClick('s') } );
	$j( '#img_direct_target_s' ).click( function(){ directTargetClick('s') } );
	$j( '#rdo_direct_target_a' ).click( function(){ directTargetClick('a') } );
	$j( '#img_direct_target_a' ).click( function(){ directTargetClick('a') } );

	// 他サイト注文種別ラジオボタンの選択
	$j( '#rdo_sp_site_1' ).click( function(){ specialTargetClick() });
	$j( '#rdo_sp_site_2' ).click( function(){ specialTargetClick() });
	$j( '#img_sp_site_1' ).click( function(){ $j( '#rdo_sp_site_1' ).trigger( 'click' ); specialTargetClick(); });
	

	// 第１位商品注文ボタン
	$j( '.buyNowBt' ).mouseover( function(){ $j( this ).attr( 'src', '/img/images/label_black_buy.png' ); });
	$j( '.buyNowBt' ).mouseout ( function(){ $j( this ).attr( 'src', '/img/images/label_blue_buy.png'  ); });
	
	// ムリヤリ・・・１
	$j( "#st1" ).trigger( 'click' );
	selectType( $j( ".stRdo" ) );

	// ムリヤリ・・・２
	$j( "#rdo_direct_target_a" ).trigger( 'click' );
	$j( "#rdo_auction_type_1"  ).trigger( 'click' );
	
	// ムリヤリ・・・３
	$j( "#rdo_sp_site_1" ).trigger( 'click' );
	specialTargetClick();
	

});

