// 2009.05.25 - Hidokeisha GK

// prototype.js must be imported first.

// 商品詳細を隠す
function HideDetail(showGuidance){
	$('photo1').src = 'item_dummy.gif';
	if( showGuidance ){
		$('guidance').show();
	}
	else{
		$('guidance').hide();
	}
	$('item_info').hide();
}

// カタログにおいてあるアイテムがクリックされたとき
var InfoUpdater;
var InfoUrl;
function ShowDetail(catalog_id){
	$('guidance').hide();
	$('item_info').show();
	
	var url = 'iteminfo.php?ci=' + escape(catalog_id);
	if( InfoUrl == url ){
		return;
	}
	InfoUrl = url;

	$('photo1').src = 'item_dummy.gif';
	$('item_shopid').update("&nbsp;");
	$('item_name').update("商品情報を読み込み中");
	$('item_size').update("&nbsp;");
	$('item_memo').update("&nbsp;");
	$('item_price').update("&nbsp;");
	$('item_ctrl').update("&nbsp;");
	
	InfoUpdater = new Ajax.Request(InfoUrl, {
		method: 'get',
		onSuccess: function(transport){
			var data = eval("(" + transport.responseText + ")");
			if( data.photo_id_c ){
				$('photo1').src = 'http://www.first-arrows.com/image/shopping/photo/' + data.photo_id_c + '.jpg';
			}
			else if( data.photo_id ){
				$('photo1').src = 'http://www.first-arrows.com/image/shopping/photo/' + data.photo_id + '.jpg';
			}
			else{
				$('photo1').src = 'item_dummy.gif';
			}
			
			var shopid = (data.shopid_c ? data.shopid_c : data.shopid);
			//特別処理
			if( shopid == 'SB-042' ) shopid = 'SB-042(LS-002)';
			if( shopid == 'SB-043' ) shopid = 'SB-043(LS-003)';
			if( shopid == 'SB-044' ) shopid = 'SB-044(LS-004)';
			if( shopid == 'SB-046' ) shopid = 'SB-046(LS-001)';
			
			$('item_shopid').update(shopid);
			
			$('item_name').update(data.item_name_c ? data.item_name_c : data.item_name);
			
			var size = ( data.item_size_c ? data.item_size : data.item_size );
			if( size ){
				$('item_size').update('SIZE: ' + size);
			}
	
			$('item_memo').update(data.memo_c ? data.memo_c : data.memo);
			
			var price = '';
			if( data.price_c ){
				price = data.price_c;
			}
			else if( data.price > 0 ){
				price = data.price;
			}
			if( ! isNaN(price) ){
				$('item_price').update('￥' + FormatPrice(price));
			}
			else{
				$('item_price').update('￥' + price);
			}
			
			if( data.idnum ){
				var uri =
					'/shopping/cart_do.php?popup=1&additem='
					+ data.idnum 
					+ '&back_url=http%3A%2F%2Fwww.first-arrows.com%2Fcatalog%2F';
				$('item_ctrl').update('<a href="javascript:ShowCart(\'' + uri  + '\');">カートに入れる</a>');
			}
		}
	});
}

// 金額のフォーマット
function FormatPrice(price){
	var s = "" + price;
	do{
		var s2 = s.replace(/^(\d+)(\d{3})/, "$1,$2");
		if( s == s2 ) break;
		else s = s2;
	}while( true );
	return s;
}


// デバッグ用
function DebugTrace(msg){
	$('debug').update($('debug').innerHTML + "<br />" + msg);
}

// カタログの表示
function ShowCatalog(){
	var flashvars = {
		firstarrows: 1
	};
	var params = {
		menu: "false",
		quality: "high",
		wmode: "opaque",
		loop: "false"
	};
	var attributes = {
		id: "catalog_flash",
		name: "catalog_flash",
		align: "left"
	};
	
	/*
	var ratio = 1;
	var gh = document.viewport.getHeight();
	if( gh < 660 + 30 ){
		ratio = gh / (660 + 30);
	}
	var tw = Math.floor(1040 * ratio);
	var th = Math.floor(660 * ratio);
	
	$('flash_table').setStyle({width: tw + 'px', height: th + 'px'});
	
	swfobject.embedSWF("main.swf", "flash_area_div", "100%", "100%", "9.0.45","expressInstall.swf", flashvars, params, attributes);
	*/
	swfobject.embedSWF("main.swf", "flash_area_div", "765", "660", "9.0.45","expressInstall.swf", flashvars, params, attributes);
}

// 買い物かごの表示
var CART_WINDOW_NAME = 'fa_catalog_cart_win';
function ShowCart(uri){
	window.open(uri, CART_WINDOW_NAME, 'width=640,height=680,scrollbars=yes,resizable=yes');
}


