/**
 * シリーズ詳細TIPS
 * SeriesTips
 * シリーズ情報を省略表示に変更したため、フル表示するウィンドウ
 **/
function SeriesTips(id) {
    this._id = id ? id :"series_tips";
    this.create();
	this._buttonArea;
	
	// 非表示フラグ:trueで非表示
	this._flagname =  this._id+"Flag";
	this._viewerFlag  = $.cookie(this._flagname);
}

SeriesTips.prototype = {
	create : function() {
		var tips = $('<div>').attr('id', this._id).addClass("series_tips").hide();
		$('body').append(tips);
	},
	// シリーズ詳細TIPSを表示
	open : function(contents, e) {
		
		if(	this._viewerFlag > 0) { return false; }
		
		// 表示内容をセット
		$('#'+this._id).html(contents);
		
		var leftTemp = '';
		var topTemp = '';

			// 現在のマウス位置に合わせて、表示位置をずらす
		if ($('html').scrollLeft() + $('html').attr('clientWidth') / 2 > e.pageX) {
// 		    $('#'+this._id).css({left : e.pageX + 32 +'px', right:'inherit'});
			leftTemp = e.pageX + 32 +'px';
		} else {
// 		    $('#'+this._id).css({right : $('html').attr('clientWidth') - e.pageX +  32 +'px', left:'inherit'});
			leftTemp = e.pageX - $('#'+this._id).outerWidth() - 32 +'px';
		}

		if ($('html').scrollTop() + $('html').attr('clientHeight') / 2 > e.pageY) {
//		    $('#'+this._id).css({top : e.pageY + 32 +'px', bottom:'inherit'});
			topTemp = e.pageY + 32 +'px';
			
		} else {
// 		    $('#'+this._id).css({bottom : $('html').attr('clientHeight') - e.pageY +  32 +'px', top:'inherit'});
			topTemp = e.pageY - $('#'+this._id).outerHeight() - 32 +'px';
		}
		
	    $('#'+this._id)
			.css({left : leftTemp, top : topTemp})
			.fadeIn(200);
	},
	
	// シリーズ詳細TIPSを閉じる
	close : function () {
	    $('#'+this._id).fadeOut(200);
	    return false;
	},
	
	////////////////////////////////////////
	// @ba-ta 表示設定
	setButtonArea : function (id) {
		this._buttonArea = id;
		return this;
	},
	
	setButtonDOM : function () {
		var THIS = this;

		// ボタン表示
		buttonDOM = "<div id='"+this._buttonArea+"_button'>ポップアップ表示";
		if (this._viewerFlag > 0) {
			buttonDOM += "<a href='#'>ON</a>｜<span class='set'>OFF</span></div>";
		} else {
			buttonDOM += "<span class='set'>ON</span>｜<a href='#'>OFF</a></div>";
		}
		$('#'+this._buttonArea).html(buttonDOM);
		
		// CSS調整
		$('#'+this._buttonArea+'_button span').css({'font-weight':'bold', padding:'4px'});
		$('#'+this._buttonArea+'_button a')
			.css({padding:'4px'})
			.click(function() {
			    THIS.switchButton();
			return false;
			});
		return this;
	},
	
	switchButton :  function () {
		// フラグを切り替える
		this._viewerFlag = this._viewerFlag > 0 ? 0 : 1;
		$.cookie(this._flagname, this._viewerFlag);

		// 表示も切り替える
		this.setButtonDOM();
		
		return false;
	}
}
