///////////////////////////////////////////////////////////////////////////////
//
//
//
//
///////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////
if ( typeof ecbeing != "undefined" ) var _ecbeing = ecbeing;

var ecbeing = window.ecbeing = function(){ return this instanceof ecbeing ? this.init() : new ecbeing(); };


///////////////////////////////////////////////////////////////////////////////
ecbeing.prototype = {
	init: function()
	{
	},

	///////////////////////////////////////////////////////////////////////////
	//
	//	ecbeing.history
	//
	///////////////////////////////////////////////////////////////////////////
	history: function(num)
	{
		//-------------------------------------------------------------------------
		function Record(name, url, image, price)
		{
			this.name	= name;
			this.url	= url;
			this.image	= image;
			if(this.image =="/img/sys/sorryL.jpg") this.image = "/img/sys/sorryS.jpg";
			this.price	= price;

			this.isNull	= function()
			{
				return (
						this.name == '' || this.url == '' || this.image == '' || this.price == '' ||
						this.name == null || this.url == null || this.image == null || this.price == null
					   );
			}

			this.html	= function()
			{
				if ( this.isNull() ){ return ''; }

				result ='<div class="itemimg"><a href="' + this.url + '"><img boder="0" width="110" height="110" src="'+ this.image +'" alt="' + this.name + '" /></a></div>\n' +
						//'<div class="itemicon"></div>\n' +
						//'<div class="itemstate"></div>\n' +
						'<div class="itemname"><a href="' + this.url + '">'+ this.name +'</a></div>\n' +
						'<div class="itemprice">' + this.price +'</div>\n';
				return result;
			}
		}
		//-------------------------------------------------------------------------
		function Records(num)
		{
			this.records_ = new Array(num);
			for ( i=0; i<num; i++ )
			{
				this.records_[i] = new Record( j$.cookie('name_'+i), j$.cookie('url_'+i), j$.cookie('image_'+i), j$.cookie('price_'+i) );
			}

			this.write = function()
			{
				for ( i=0; i<this.records_.length; i++ )
				{
					j$.cookie('url_'+i,	this.records_[i].url,	{'path':'/'});
					j$.cookie('name_'+i,	this.records_[i].name,	{'path':'/'});
					j$.cookie('image_'+i,	this.records_[i].image,	{'path':'/'});
					j$.cookie('price_'+i,	this.records_[i].price,	{'path':'/'});
				}
			}
			this.find = function(url)
			{
				for ( i=0; i<this.records_.length; i++ )
				{
					if ( this.records_[i].url == url ) { return i; }
				}
				return -1;
			}
			this.get = function(idx)
			{
				if ( idx<0 || idx>=this.records_.length ) return new Record(null, null, null);//null object
				return this.records_[idx];
			}
			this.set = function(record)
			{
				var idx = this.find( record.url );
				if ( idx < 0 )
				{ // new
					this.pushHead( record );
				}
				else
				{
					for ( i=idx; i>0; i-- )
					{
						this.records_[i] = this.records_[i-1];
					}
					this.records_[0] = record;
				}
				this.write();
			}
			this.pushHead = function(record)
			{
				// shift
				for ( i=this.records_.length-1; i>0; i-- )
				{
					this.records_[i] = this.records_[i-1];
				}
				this.records_[0] = record;
			}
			this.swap = function( idx1, idx2 )
			{
				var temp = this.records_[idx1];
				this.records_[idx1] = this.records_[idx2];
				this.records_[idx2] = temp;
			}
			this.html = function()
			{
				var html = '';
				for ( i=0; i<this.records_.length; i++ )
				{
					html += this.records_[i].html();

		j$('#vis_'+i).html( this.records_[i].html() );	/* 画面に表示　<div id='vis_'> */

				}
				return html;
			}
		}

		var records = new Records(num);

		//cookie記録する
		if ( ECBEING_PAGETYPE=='goodsdetail' )
		{
			var current = new Record( j$('#x_goodsName').text(), document.URL, j$('#x_goodsImageMainThum').attr('src'), j$('#x_goodsPrice').text() );
			records.set(current);
		}
		j$('#recentGoods').html( records.html() );	/* 画面に表示　<div id='recentGoods'> */
		return this;
	}
}

ecbeing.history	= ecbeing.prototype.history;



///////////////////////////////////////////////////////////////////////////////
//
//   引数に表示回数（最大数）を指定
//
///////////////////////////////////////////////////////////////////////////////

j$(
	function()
	{
		ecbeing.history(5);
	}
);


