/**
 * 商品詳細表示
 * smartProductViewer
 * シリーズ情報から切り替えなしに、商品詳細を表示
 **/
function smartProductViewer(id) {
    this._id = id ? id :"smart_product_viewer";
    this.create();
}

smartProductViewer.prototype = {
    _heightMargin :140,
	_scrollBarWidth : 20,
	_border : 4,


	create : function() {
		var THIS = this;
		var win = $('<div>').attr('id', this._id).addClass("smart_product_viewer")
		    .append($('<div>').addClass("ajax_contents").attr('id', 'ajax_contents'))
		    .append($('<button>').addClass("close").text("×閉じる"))
			.hide()
		;
		this.close();
		
		$('body').append(win);
		
		win.find('.close').click(function(){ THIS.close(); });
		
		// 読み込んだ内容に再帰的にイベント設定
		$('#ajax_contents .pan a').live("click", function(e){
		    THIS.load($(this).attr('href'), e);
			return false;
		});
		
// 		// 読み込み後の表示コールバック
// 		$('#ajax_contents').ajaxComplete( function(){ THIS.open(); }); 
	},
	
	// 商品詳細表示を読み込み
	load : function(url, e) {
		var THIS = this;
		
	    $('#ajax_contents').load(url+" .c_product_viewer", {}, function(){ THIS.open(); });
		return true;
	},
	
	// 商品詳細表示を表示
	open : function() {
		var THIS = this;
		var win = $('#'+this._id);

	    win.css({
		    "bottom" : $('html').attr('clientHeight') - ($('.main_search_table').offset().top ),
		    "left" : $('.main_search_table').offset().left - this._border - this._scrollBarWidth/2,
		    "width" : $('.main_search_table').width() + this._border*2 + this._scrollBarWidth
	    });
			
		$('#ajax_contents').css({
		    "top" : this._border,
		    "left" : this._border,
		    "width" : $('.main_search_table').width() + this._scrollBarWidth,
		    "height" : $('.series_detail_box').height() + this._heightMargin - this._border*2
	    });
			

		$('#'+this._id).animate(
		    {
// 			    top : $('.main_search_table').offset().top - ($('.series_detail_box').height() + this._heightMargin),
			    height: $('.series_detail_box').height() + this._heightMargin
			},
		    {
			    duration: 300, 
				complete:function(){
			        $("#ajax_contents").css("overflow", "auto");
  			        $("#ajax_contents").show();
  		            win.find(".close").show();
			    }
			}
		);
	},
	
	// 商品詳細表示を閉じる
	close : function () {
		var THIS = this;
		var win = $('#'+this._id);
		
 		$("#ajax_contents").css("overflow", "hidden");
//  		$("#ajax_contents").hide();
 		win.find(".close").hide();

		$('#'+this._id).animate(
		    {
// 			    top : $('.main_search_table').offset().top,
			    height: 0
			},
		    {duration: 300, complete:function(){ $('#'+THIS._id).hide(); }}
		);
	}
}
