var $j = jQuery.noConflict();

/*! Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * Version: 3.0.2
 * 
 * Requires: 1.2.2+
 */

(function($) {

var types = ['DOMMouseScroll', 'mousewheel'];

$.event.special.mousewheel = {
	setup: function() {
		if ( this.addEventListener )
			for ( var i=types.length; i; )
				this.addEventListener( types[--i], handler, false );
		else
			this.onmousewheel = handler;
	},
	
	teardown: function() {
		if ( this.removeEventListener )
			for ( var i=types.length; i; )
				this.removeEventListener( types[--i], handler, false );
		else
			this.onmousewheel = null;
	}
};

$.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});


function handler(event) {
	var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true;
	
	event = $.event.fix(event || window.event);
	event.type = "mousewheel";
	
	if ( event.wheelDelta ) delta = event.wheelDelta/120;
	if ( event.detail     ) delta = -event.detail/3;
	
	// Add events and delta to the front of the arguments
	args.unshift(event, delta);

	return $.event.handle.apply(this, args);
}

})(jQuery);
 /**
  * Class
  * @Author NHN Japan RIA
  * @name jQuery.Class
  * @param {String} nameSpace {Object} method {Boolean} extend
  **/
jQuery.extend({
	Class: function(ns,obj,extend) {
		var typeClass = function(){
			var _this = this;
			var a = [];
			while (typeof _this.$super != "undefined") {
				_this.$super.$this = this;
				if (typeof _this.$super.init == "function") a[a.length] = _this;
				_this = _this.$super;
			}
			for (var i = a.length - 1; i > -1; i--) a[i].$super.init.apply(a[i].$super, arguments);
			if (this.init instanceof Function) this.init.apply(this, arguments);
		}
		typeClass.prototype = obj;
		typeClass.prototype.constructor = typeClass;
		typeClass._extend = jQuery.Class._extend;

		if(extend) return typeClass;
		
		var pkg = jQuery.Class._verifyNameSpace(ns);
		pkg.container[pkg.name] = typeClass;
		//pkg.container[pkg.name].name = pkg.name;
	}
});

jQuery.extend(jQuery.Class,{
	_verifyNameSpace :
		function(ns){
			if(ns=="")return null;
			var names=ns.split(".");
			var componentName="",parent=window;
			if(names.length==1){
				componentName=names.pop()
			}else{
				for(var i=0,length=names.length;i<length;i++){
					var n=names[i];
					if(i==names.length-1){
						componentName=n;
						break
					}
					if(parent[n]==undefined)parent[n]={};
					parent=parent[n]
				}
			}
			return{container:parent,name:componentName}
		},
	_extend :
		function (superClass) {
			this.prototype.$super = new Object;
			var superFunc = function (m, superClass, func) {
				if (m != 'constructor' && func.toString().indexOf("$super") > -1) {
					var funcArg = func.toString().replace(/function\s*\(([^\)]*)[\w\W]*/g, "$1").split(",");
					var funcStr = func.toString().replace(/function\s*\(.*\)\s*\{/, "").replace(/this\.\$super/g, "this.$super.$super");
					funcStr = funcStr.substr(0, funcStr.length - 1);
					func = superClass[m] = new Function(funcArg, funcStr);
				}
				return function () {
					var f = this.$this[m];
					var t = this.$this;
					var r = (t[m] = func).apply(t, arguments);
					t[m] = f;
					return r;
				};
			};
			for (var x in superClass.prototype) {
				if (typeof this.prototype[x] == "undefined" && x != "init") this.prototype[x] = superClass.prototype[x];
				if (typeof superClass.prototype[x] == "function") {
					this.prototype.$super[x] = superFunc(x, superClass, superClass.prototype[x]);
				} else {
					this.prototype.$super[x] = superClass.prototype[x];
				}
			}
			for (var x in superClass) {
				if (x == "prototype") continue;
				this[x] = superClass[x];
			}
			return this;
		},
	extend :
		function(superClass,ns,obj){
			var pkg = jQuery.Class._verifyNameSpace(ns)
			pkg.container[pkg.name] = jQuery.Class(ns,obj,true)._extend(superClass);
			//pkg.container[pkg.name].name = pkg.name;
		}
})

 /**
  * $Class old
  * @Author NHN Japan RIA
  * @name jQuery.$Class
  * @param {Object} method
  **/
jQuery.extend({
	$Class: function(obj) {
		var typeClass = function(){
			var _this = this;
			var a = [];
			while (typeof _this.$super != "undefined") {
				_this.$super.$this = this;
				if (typeof _this.$super.$init == "function") a[a.length] = _this;
				_this = _this.$super;
			}
			for (var i = a.length - 1; i > -1; i--) a[i].$super.$init.apply(a[i].$super, arguments);
			if (typeof this.$init == "function") this.$init.apply(this, arguments);
		}
		typeClass.prototype = obj;
		typeClass.prototype.constructor = typeClass;
		typeClass.extend = jQuery.$Class.extend;
		return typeClass;
	},
	vpn : function(namespace){
		if(namespace=="")return null;
		var names=namespace.split(".");
		var componentName="",parent=window;
		if(names.length==1){
			componentName=names.pop()
		}else{
			for(var i=0,length=names.length;i<length;i++){
				var n=names[i];
				if(i==names.length-1){
					componentName=n;
					break
				}
				if(parent[n]==undefined)parent[n]={};
				parent=parent[n]
			}
		}
		return{container:parent,name:componentName}
	}
});

jQuery.$Class.extend = function (superClass) {
    this.prototype.$super = new Object;
    var superFunc = function (m, superClass, func) {
        if (m != 'constructor' && func.toString().indexOf("$super") > -1) {
            var funcArg = func.toString().replace(/function\s*\(([^\)]*)[\w\W]*/g, "$1").split(",");
            var funcStr = func.toString().replace(/function\s*\(.*\)\s*\{/, "").replace(/this\.\$super/g, "this.$super.$super");
            funcStr = funcStr.substr(0, funcStr.length - 1);
            func = superClass[m] = new Function(funcArg, funcStr);
        }
        return function () {
            var f = this.$this[m];
            var t = this.$this;
            var r = (t[m] = func).apply(t, arguments);
            t[m] = f;
            return r;
        };
    };
    for (var x in superClass.prototype) {
        if (typeof this.prototype[x] == "undefined" && x != "$init") this.prototype[x] = superClass.prototype[x];
        if (typeof superClass.prototype[x] == "function") {
            this.prototype.$super[x] = superFunc(x, superClass, superClass.prototype[x]);
        } else {
            this.prototype.$super[x] = superClass.prototype[x];
        }
    }
    for (var x in superClass) {
        if (x == "prototype") continue;
        this[x] = superClass[x];
    }
    return this;
};



/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright  2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright  2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */



/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};



var gcHGToolBar;

//jQuery(function($) {
//	/*if(getStrCookie("login")) */gcHGToolBar = new hg.hgToolBar.Main({});
//});

(function($) {
	$.Class('hg.hgToolBar.Main',{
		init : function(opt){
			this.prms = $.extend({
			}, opt);
			
			var osInfo = getOSInfo();
			if(osInfo.iphone || osInfo.android || osInfo.ipad) return;
			if($.browser.msie && parseInt($.browser.version) == 6) return;
			
			this.userid = this.prms.userid;
			
			this.logoutURL = 'http://ctrad.hangame.co.jp/go?loc=clate.logout&ad=AD1138864266428';
			
			var locHref = location.href;
			if (locHref.indexOf('//beta-') > 0) {
				this.server = 'beta-';
			} else if (locHref.indexOf('//alpha-') > 0) {
				this.server = 'alpha-';
				this.logoutURL = 'http://ctrad.hangame.co.jp/go?loc=clate.logout&ad=AD1138864328242';
			} else if (locHref.indexOf('//dev') > 0) {
				this.server = 'dev-';
//				this.server = 'alpha-';
			} else {
				this.server = '';
			}
			
			this.cssPath = 'http://static.hangame.co.jp/hangame/common/css/mod_hg_toolbar.css';
			
			this.welBody = $('body');
						
			if (!getStrCookie("login")) {
				this._appendLogoutToolbar();
				return;
			}
			
			var apiPrefix = 'http://' + this.server + 'toolbar.hangame.co.jp/';
			var friendsURL = 'http://' + this.server + 'friends.hangame.co.jp/';
			
			var avatarViewerJsURL = 'http://static.hangame.co.jp/avv/avatarViewer.js';
			if(typeof VIEWER_showAvatarNf != 'function'){
				var avaVScriptTag = $('<script>').attr({
					'src': avatarViewerJsURL,
					'type': 'text/javascript'
				});
				$('head').append(avaVScriptTag);
			}
			
			this.cmnCookieFlg = false;
			
			this.proxyIframeID = 'hgToolBarProxy';
			this.proxySrc = apiPrefix + 'proxy.html';
//			this.myPageURL = 'http://' + this.server + 'mypage.hangame.co.jp/mynews/index.nhn';
			this.myPageURL = 'http://' + this.server + 'mypage.hangame.co.jp/mynews/';
			
			//maps
			
			this.toolAPIMap = {
				init : apiPrefix + 'load.nhn'
				,online:apiPrefix + 'online.nhn'
				,follow: apiPrefix + 'follow.nhn'
				,ignore: apiPrefix + 'ignore.nhn'

				,playHistory:apiPrefix + 'playhist.nhn'
				,playHistoryadd:apiPrefix + 'mymenu/add.nhn'
				,myMenu:apiPrefix + 'mymenu.nhn'
				,myMenudel:apiPrefix + 'mymenu/del.nhn'
				,imapico:{
					friend:apiPrefix + 'imapico.nhn'
					,my:apiPrefix + 'imapico.nhn'
				}
				,imapicopost:'imapico/api/post.nhn'
				,imapicodel:'imapico/api/delete.nhn'
				,imapicoreport: 'imapico/api/inform.nhn'
			}
			
			this.clickCntAPI = apiPrefix + 'measure/clickcnt.nhn';
			
			if (this.server == 'dev-') {
				this.proxySrc = 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/proxy.html';
				this.myPageURL = 'http://alpha-mypage.hangame.co.jp/mynews/';
				this.logoutURL = 'http://ctrad.hangame.co.jp/go?loc=clate.logout&ad=AD1138864328242';
//				this.proxySrc = 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/proxy.html';
//				this.myPageURL = 'http://alpha-mypage.hangame.co.jp/mynews/';
//				this.logoutURL = 'http://ctrad.hangame.co.jp/go?loc=clate.logout&ad=AD1138864328242';
				//maps

				this.toolAPIMap = {
//					init: 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/res.php',
//					online: 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/resOnline2.php',
//					follow: 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/resFollow.php',
//					ignore: 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/resIgnore.php',
//					playHistory: 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/resHistory.php',
//					playHistoryadd: 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/resHistoryAdd.php',
//					myMenu: 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/resMymenu.php',
//					myMenudel: 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/resMymenuDel.php',
//					imapico: {
//						friend: 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/resImapicoFriendNew.php',
//						my: 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/resImapicoMyNew.php'
//					},
//					imapicopost: 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/resImapicoPost.php',
//					imapicodel: 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/resImapicoDel.php',
//					imapicoreport: 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/resImapicoReport.php'
//				}
//				this.clickCntAPI = 'http://devui.hangame.co.jp/common/html/hg_toolbar/dev2/resClickCnt.php';
					init: 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/res.php',
					online: 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/resOnline.php',
					follow: 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/resFollow.php',
					ignore: 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/resIgnore.php',
					playHistory: 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/resHistory.php',
					playHistoryadd: 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/resHistoryAdd.php',
					myMenu: 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/resMymenu.php',
					myMenudel: 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/resMymenuDel.php',
					imapico: {
						friend: 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/resImapicoFriendNew.php',
						my: 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/resImapicoMyNew.php'
					},
					imapicopost: 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/resImapicoPost.php',
					imapicodel: 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/resImapicoDel.php',
					imapicoreport: 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/resImapicoReport.php'
				}
				this.clickCntAPI = 'http://dev2.hangame.co.jp/common%5BDEV%5D/html/hg_toolbar/dev2/resClickCnt.php';
			}

			this.toolIDMap = {
				mm:'hgTools1'
				,good:'hgTools7'
				,board:'hgTools2'
				,online:'hgTools3'
				,playHistory:'hgTools4'
				,myMenu:'hgTools5'
				,imapico:'hgTools6'
				,logout:'hgToolOut'
			}
			
			this.clickCntIDMap = {
				mm:'A'
				,good:'I'
				,board:'B'
				,online:'C'
				,playHistory:'D'
				,myMenu:'E'
				,imapico:'F'
				,logout:'H'
				,mypage:'G'
			}
			
			this.toolClassMap = {
				online:'cOnline'
				,playHistory:'cPlayHistory'
				,playHistoryadd:'cPlayHistory'
				,myMenu:'cMyMenu'
				,myMenudel:'cMyMenu'
				,imapico:'cImapico'
				,imapicopost:'cImapicoPost'
			}
			
			this.followIcon = {
				off: 'http://images.hangame.co.jp/hangame/common/hg_toolbar/img_player.gif'
				,on: 'http://images.hangame.co.jp/hangame/common/hg_toolbar/img_player_ani.gif'
			}

			this.onAjax = false;
			
			this.elProxyIframe = this._setProxyIframe();
			
			this._appendToolbar();
			this.commonNumElms = this._getCommonNumElms();
			//this.btnElms = this._getBtnElms();
			
			this.cBase = new hg.hgToolBar.Base({proxy:this.elProxyIframe});
			this.cOnline = new hg.hgToolBar.Online({proxy:this.elProxyIframe,friendsURL:friendsURL,bID:this.clickCntIDMap.online});
			this.cPlayHistory = new hg.hgToolBar.PlayHistory({proxy:this.elProxyIframe,bID:this.clickCntIDMap.playHistory});
			this.cMyMenu = new hg.hgToolBar.MyMenu({proxy:this.elProxyIframe,bID:this.clickCntIDMap.myMenu});
			this.cImapico = new hg.hgToolBar.Imapico({proxy:this.elProxyIframe,userid:this.userid,bID:this.clickCntIDMap.imapico});
			
			this.cImapicoPost = new hg.hgToolBar.ImapicoPost({proxy:this.elProxyIframe,userid:this.userid});
			
			//var cookieCmnData = this._getCommonDataCookie();
			//if(cookieCmnData) this._setCookieCmnData(cookieCmnData);
			
			//todo:cookie logic
			this.checkTimer = setInterval($.proxy(this._initRequest,this),100);
			
			this._setBtnEvents();
			this._setFollowBaloonEvent();
		},
		_clickCntAjaxRequest : function(param){

			this.elProxyIframe.contentWindow.gcHGToolBarProxy.clickCnt(param,this.clickCntAPI);
		},
		_getCommonNumElms : function(){
			return {
				mm : $('#'+this.toolIDMap.mm+' .num > a')
				,good : $('#'+this.toolIDMap.good+' .num > a')
				,board : $('#'+this.toolIDMap.board+' .num > a')
				,online : $('#'+this.toolIDMap.online+' .onlineNum_jskey')
				,friend : $('#'+this.toolIDMap.online+' .friendNum_jskey')
			};
		},
		_getFollowElms : function() {
			return {
				aniImg : $('#'+this.toolIDMap.online+' p.item > img')
				,baloon : $('#'+this.toolIDMap.online+' div.ifBaln')
			};
		},
		_getBtnElms : function(){
			return {
				mypage : $('#mydateArea p.mypage')
				,mm : $('#'+this.toolIDMap.mm+' p.item')
				,good : $('#'+this.toolIDMap.good+' p.item')
				,board : $('#'+this.toolIDMap.board+' p.item')
				,online : $('#'+this.toolIDMap.online+' p.item')
				,playHistory : $('#'+this.toolIDMap.playHistory+' p.item')
				,myMenu : $('#'+this.toolIDMap.myMenu+' p.item')
				,imapico : $('#'+this.toolIDMap.imapico+' p.item')
				,logout : $('#'+this.toolIDMap.logout+' p.logout')
			};
		},
		_setBtnEvents : function(){
			var _this = this;
			$.each(this._getBtnElms(),function(n,v){
				$(v).click(function(e){
					if(e) e.preventDefault();
					_this._clickEventHandler(n);
				})
			})
		},
		_setFollowBaloonEvent : function() {
			var _this = this;
			this._getFollowElms().baloon.click(function(e) {
				if(e) e.preventDefault();
				_this._clickEventHandler('online');
			});
		},
		_openMyPage : function(){
//			window.open(this.myPageURL,'mypage');
			window.open(this.myPageURL+'index.nhn','mypage');
		},
		_openGoodPage : function() {
			window.open(this.myPageURL+'goodbutton.nhn','mypage');
		},
		_clickEventHandler : function(name){
			var clickCntParam = {buttonId:this.clickCntIDMap[name]}
			switch(name){
				case 'mypage':
					this._clickCntAjaxRequest(clickCntParam);
					this._openMyPage();
					break;
				case 'mm':
					this._clickCntAjaxRequest(clickCntParam);
					openPost();
					break;
				case 'good':
					this._clickCntAjaxRequest(clickCntParam);
					this._openGoodPage();
					break;
				case 'board':
					this._clickCntAjaxRequest(clickCntParam);
					this._openMyPage();
					break;
				case 'logout':
					this._clickCntAjaxRequest(clickCntParam);
					location.href = this.logoutURL;
					break;
				default:
					if(this.onAjax) return;
					this[this.toolClassMap[name]].clickHandler();
					break;
			}
		},
		_buildToolBarTag : function(){
			var toolBarTag = '<div class="toolbar"><div class="hgToolbar_bgL"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="7" height="37" alt="" /></div><div class="hgToolbar_inner">';
			toolBarTag += '<div id="mydateArea"><p class="mypage"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/btn_mypage.gif" width="102" height="24" alt="マイページ" /></p><ul id="hgToolsWrap"><li id="hgTools1"><p class="item"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/img_mail.gif" alt="" width="19" height="14" /><span class="num"><a href="#"></a></span></p></li>';
			toolBarTag += '<li id="hgTools7"><p class="item"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/img_good.gif" alt="" width="14" height="15" /><span class="num"><a href="#"></a></span></p></li>';
			toolBarTag += '<li id="hgTools2"><p class="item"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/img_tubuyaki.gif" alt="" width="19" height="17" /><span class="num"><a href="#"></a></span></span></p></li>';
			toolBarTag += '<li id="hgTools3"><p class="loader" style="display:none;"><img alt="" src="http://images.hangame.co.jp/hangame/common/loading/cycle_black_13x13.gif"></p><p class="item"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/img_player.gif" alt="" width="15" height="17" /><em class="online"><span class="num"><a href="#" class="onlineNum_jskey"></a></span></span><span>人</span>友だち</em></p><div class="hgToolsMenu" style="height:0px"><div class="hgToolsMenuTop"><div class="hgToolsTopL"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="38" alt="" /></div><div class="hgToolsTopC"><table border="0" cellspacing="0" cellpadding="0"><tbody>  <tr>    <th scope="row" class="headTit">友だち(<span class="friendNum_jskey num">-- </span>人中) <span class="onlineNum_jskey num">-- </span>人ログイン</th>    <td class="closeArea"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/img_close.gif" alt="閉じる" width="46" height="12" /></td>  </tr></tbody></table></div><div class="hgToolsTopR"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="38" alt="" /></div></div><table class="hgToolsBody" border="0" cellspacing="0" cellpadding="0"><tbody>  <tr>    <td class="hgToolBodyL"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="1" alt="" /></td>    <td class="hgToolBodyC"><div class="hgToolList"><ul class="listArea"></ul><p class="notice">※オンライン状態表示に対応していないゲームもあります</p><p class="moreBtn"><span>もっと見る</span><img alt="" src="http://images.hangame.co.jp/hangame/common/loading/cycle_black_13x13.gif"></p>  </div>      </td>    <td class="hgToolBodyR"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="1" alt="" /></td>  </tr></tbody></table></div><div class="ifBaln" style="display:none;"><p class="ava" id="followAva"></p><p class="txt">フォローされました！</p></div></li>';
			toolBarTag += '<li id="hgTools4"><p class="loader" style="display:none;"><img alt="" src="http://images.hangame.co.jp/hangame/common/loading/cycle_black_13x13.gif"></p><p class="item"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/img_history.gif" alt="プレイ履歴" width="62" height="14" /></p><div class="hgToolsMenu" style="height:0px"><div class="hgToolsMenuTop"><div class="hgToolsTopL"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="38" alt="" /></div><div class="hgToolsTopC"><table border="0" cellspacing="0" cellpadding="0"><tbody>  <tr>    <th scope="row" class="headTit">プレイ履歴</th>    <td class="closeArea"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/img_close.gif" alt="閉じる" width="46" height="12" /></td>  </tr></tbody></table></div><div class="hgToolsTopR"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="38" alt="" /></div></div><table class="hgToolsBody" border="0" cellspacing="0" cellpadding="0"><tbody>  <tr>    <td class="hgToolBodyL"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="1" alt="" /></td>    <td class="hgToolBodyC"><ul class="listArea"></ul></td>    <td class="hgToolBodyR"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="1" alt="" /></td>  </tr></tbody></table></div></li>';
			toolBarTag += '<li id="hgTools5"><p class="loader" style="display:none;"><img alt="" src="http://images.hangame.co.jp/hangame/common/loading/cycle_black_13x13.gif"></p><p class="item"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/img_mymenu.gif" alt="マイメニュー" width="71" height="14" /></p><div class="hgToolsMenu" style="height:0px"><div class="hgToolsMenuTop"><div class="hgToolsTopL"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="38" alt="" /></div><div class="hgToolsTopC"><table border="0" cellspacing="0" cellpadding="0"><tbody>  <tr>    <th scope="row" class="headTit">マイメニュー</th>    <td class="closeArea"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/img_close.gif" alt="閉じる" width="46" height="12" /></td>  </tr></tbody></table></div><div class="hgToolsTopR"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="38" alt="" /></div></div><table class="hgToolsBody" border="0" cellspacing="0" cellpadding="0"><tbody>  <tr>    <td class="hgToolBodyL"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="1" alt="" /></td>    <td class="hgToolBodyC"><ul class="listArea"></ul></td>    <td class="hgToolBodyR"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="1" alt="" /></td>  </tr></tbody></table></div></li>';
			toolBarTag += '<li id="hgTools6"><p class="loader" style="display:none;"><img alt="" src="http://images.hangame.co.jp/hangame/common/loading/cycle_black_13x13.gif"></p><p class="item"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/img_question.gif" alt="みんな何してる？" width="92" height="14" /></p><div class="hgToolsMenu" style="height:0px"><div class="hgToolsMenuTop"><div class="hgToolsTopL"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="38" alt="" /></div><div class="hgToolsTopC"><table border="0" cellspacing="0" cellpadding="0"><tbody>  <tr>    <th scope="row" class="headTit">みんな何してる？</th>    <td class="closeArea"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/img_close.gif" alt="閉じる" width="46" height="12" /></td>  </tr></tbody></table></div><div class="hgToolsTopR"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="38" alt="" /></div></div><table class="hgToolsBody" border="0" cellspacing="0" cellpadding="0"><tbody>  <tr>    <td class="hgToolBodyL"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="1" alt="" /></td><td class="hgToolBodyC"><div class="imapicoItem"><div class="avaArea"><p class="tit"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/tit_imapico.gif" alt="イマピコ" width="56" height="24" /></p><div class="avaImg"><div id="hgTBImapicoOwnerAva"></div><span class="hgId"></span></div></div><div class="bllnArea"><p class="alert"></p><div class="bllnInner"><textarea></textarea></div><p class="count"><span>0文字／最大140文字</span></p><p class="cmmntBtn"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/btn_cmmt.gif" alt="発言する" width="91" height="22" /><span><img alt="" src="http://images.hangame.co.jp/hangame/common/loading/cycle_black_13x13.gif"></span></p></div><div class="impcCmmt"><ul class="impcTab"><li class="friend">友だちの行動</li><li class="info off">あなたへのお知らせ</li></ul><div class="impcDataArea"><div class="impcDataFrame"><ul class="feedList"></ul><p class="moreBtn" style="display:none"><span>もっと見る</span><img alt="" src="http://images.hangame.co.jp/hangame/common/loading/cycle_black_13x13.gif"></p></div><div class="impcDataFrame" style="display:none"><ul class="feedList"></ul><p class="moreBtn" style="display:none"><span>もっと見る</span><img alt="" src="http://images.hangame.co.jp/hangame/common/loading/cycle_black_13x13.gif"></p></div></div></div></div></td>    <td class="hgToolBodyR"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="13" height="1" alt="" /></td>  </tr></tbody></table></div></li>';
			toolBarTag += '</ul></div>';
			toolBarTag += '<div id="hgToolOut"><p class="logout"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/btn_logout.gif" width="86" height="20" alt="ログアウト" /></p></div>';
			toolBarTag += '</div>';
			/*<!-- /hgToolbar_inner -->*/			
			toolBarTag += '<div class="hgToolbar_bgR"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="7" height="37" alt="" /></div>';
			toolBarTag += '</div>';
			/*<!-- /Toolbar -->*/
			//toolBarTag += '</div>';
			/*<!-- /footerToolbar -->*/

			return toolBarTag;
		},
		_buildLogoutToolBarTag : function(){
			var toolBarTag = '<div class="toolbar"><div class="hgToolbar_bgL"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="7" height="37" alt="" /></div><div class="hgToolbar_inner">';
			toolBarTag += '<div class="offItem02" id="mydateArea"></div>';
			toolBarTag += '<div id="hgToolOut"><p class="login"><a href="javascript:document.getElementById(\'nexturl\').value=document.location.href;void(document.getElementById(\'simpleLoginLogout\').submit());"><img height="20" width="86" alt="ログイン" src="http://images.hangame.co.jp/hangame/common/hg_toolbar/btn_login.gif"></a></p></div>';
			toolBarTag += '</div>';
			/*<!-- /hgToolbar_inner -->*/			
			toolBarTag += '<div class="hgToolbar_bgR"><img src="http://images.hangame.co.jp/hangame/common/hg_toolbar/bg_bar_spacer.gif" width="7" height="37" alt="" /></div>';
			toolBarTag += '</div>';
			/*<!-- /Toolbar -->*/
			//toolBarTag += '</div>';
			/*<!-- /footerToolbar -->*/
			
			return toolBarTag;
		},
		_appendToolbar : function(){
			var weLink = $('<link>');
			weLink.attr({rel:'stylesheet',type:'text/css',href:this.cssPath});
			this.welBody.append(weLink);
			this.welBody.append($('<div>').attr('id','hgToolbar').html(this._buildToolBarTag));
			$('body').css('paddingBottom','37px');
		},
		_appendLogoutToolbar : function(){
			var weLink = $('<link>');
			weLink.attr({rel:'stylesheet',type:'text/css',href:this.cssPath});
			this.welBody.append(weLink);
			this.welBody.append($('<div>').attr('id','hgToolbar').html(this._buildLogoutToolBarTag));
			$('body').css('paddingBottom','37px');
		},
		_setProxyIframe : function(){
			var welProxyIframe = $('#'+this.proxyIframeID);
			if(welProxyIframe.size() > 0) return welProxyIframe.get(0);
			
			welProxyIframe = $('<iframe>').attr({id:this.proxyIframeID,src:this.proxySrc}).css({display:'none'});
			this.welBody.append(welProxyIframe);
			return welProxyIframe.get(0);
		},
		_initRequest : function(){
			try {
				if (this.elProxyIframe.contentWindow.gcHGToolBarProxy.xhr) {
					clearInterval(this.checkTimer);
					/*if (!this.cmnCookieFlg)*/ this.cBase._ajaxRequest({}, 'init');
				}
			}catch(e){}
		},
		handleXhrResponse : function(data,type,subType,param){
			this.onAjax = false;
			var jsonData = eval("(" + data + ")");
			
			//todo errorHandling....
			if (jsonData.header && jsonData.header.status != 0) {
				if(type != 'init') this[this.toolClassMap[type]].errorHandler(data);
				return;
			}
			
			if (jsonData.common) {
				this._setCommonData(jsonData.common);
				//this._setCommonDataCookie(jsonData.common);
			}
			// online状態のアイコン変更
			if(type == 'init' || type == 'online') {
				if(this.cOnline && (typeof this.cOnline.reqType == 'undefined' || this.cOnline.reqType == 'new')) {
					this._setFollowNotification(jsonData.common);
				}
			}

			var json = jsonData.body || jsonData;
			if(type != 'init') this[this.toolClassMap[type]].responsHandler(json,subType,param);
		},
		handleXhrError : function(type){
			this.onAjax = false;
			this[this.toolClassMap[type]].errorHandler();
		},
		handleClickCntResponse : function(data,url){
			//console.log(url);
		},
		handleClickCntError : function(){
			//console.log(url);
		},
//		_getCommonDataCookie : function(){
//			return $.cookie('hgToolBarCmn');
//		},
//		_setCommonDataCookie : function(data){
//			var value = 'uid=' + getCookie(CK_MEMBERID) + ',mm=' + data.cntmm + ',board=' + data.cntboard + ',online=' + data.cntonline; 
//			var date = new Date();
//			date.setTime(date.getTime() + (5 * 60 * 1000));
//			$.cookie('hgToolBarCmn', value, { expires: date, path: '/', domain: 'hangame.co.jp'});
//		},
		_setCommonData : function(data){
			$.each(this.commonNumElms,function(n,v){
				$.each(v,function(){
					var cnt = data['cnt'+n];
					if (cnt > 999) {
						cnt = 999;
					} else if (cnt < 0) {
						cnt = '--';
					}
					$(this).html(cnt);
				})
			})
		},
		_setFollowNotification : function(data) {
			// 初期表示時またはオンライン時
			var followCnt = parseInt(data.cntfollow, 10);
			this._getFollowElms().baloon.hide();
			if(followCnt > 0) {
				this._getFollowElms().aniImg.attr('src', this.followIcon.on);
				if(data.avatarid) {
					VIEWER_showAvatarNf3('followAva','CHA', data.avatarid);
//					var _this = this;
					this._getFollowElms().baloon.show().delay(2500).fadeOut(1000);
				}
			} else {
				this._getFollowElms().aniImg.attr('src', this.followIcon.off);
			}
		},
//		_setCookieCmnData : function(data){
//			this.cmnCookieFlg = true;
//			
//			d = data.split(',');
//			var o = {};
//			$(d).each(function(){
//			
//			    d = this.split('=');
//			    o['cnt'+d[0]] = d[1];
//			});
//			if (o.cntuid != getCookie(CK_MEMBERID)) {
//				this.cmnCookieFlg = false;
//				this._initRequest();
//			} else {
//				this._setCommonData(o);
//			}
//		},
		changeTool : function(name){
			if(this.activeToolName) this[this.toolClassMap[this.activeToolName]].hide();
			this.activeToolName = name;
		},
		callImapico : function(text){
			if (!getStrCookie("login")) {
				alert('ハンゲームにログインしてください。'); return;
			}
			if(!this.cImapico) return;
			this.cImapico.clickHandler(text);
		}
	});
})(jQuery);

/**
 * hg.hgToolBar.Base
 * @param {Object} $
 */
(function($) {
	$.Class('hg.hgToolBar.Base',{
		init : function(opt){
			this.prms = $.extend({
			}, opt);
			this.type = 'init';
			this.slideVar = 45;
		},
		_clickCnt : function(param,url){
			this.prms.proxy.contentWindow.gcHGToolBarProxy.clickCnt(param,gcHGToolBar.clickCntAPI,url);
		},
		_ajaxParams : function(){
			return {};
		},
		hide : function(){
			this.weBaseElm.animate({'height':'0px'},300,"easeOutSine");
			this.dispFlg = false;
			this._changeItemImage(false);
		},
		_changeItemImage : function(showFlg){
			if(showFlg){
				this.weItemImg.attr('src',this.itemImg.hide);
			}else{
				this.weItemImg.attr('src',this.itemImg.show);
			}
		},
		_ajaxAPIURL : function(subType){
			return gcHGToolBar.toolAPIMap[this.type + (subType || '')];
		},
		_ajaxRequest : function(param,type,subType){
			gcHGToolBar.onAjax = true; 
			this.prms.proxy.contentWindow.gcHGToolBarProxy.xhr(param,type,this._ajaxAPIURL(subType),subType);
		},
		clickHandler : function(){
			if (!this.weBaseElm) {
				this.weBaseElm = this._getMyBaseElm();
				this.weItemElm = $('p.item',this.weBaseElm.parent());
				
				if (this.type == 'online') {
					this.weItemImg = $('em', this.weItemElm);
				} else {
					this.weItemImg = $('img', this.weItemElm);
				}

				this.weLoadingElm = $('p.loader',this.weBaseElm.parent());
				this._setCloseEvent();

				this.weBaseElm.mousewheel($.proxy(function(event, delta) {
					if(event.preventDefault){
						event.preventDefault();
					}else{
						event.returnValue = false; 
					};
					if(this.elScrollElm) this.elScrollElm.scrollTop -= delta*10;
				},this));
			}

			if (this.dispFlg) {
				this.hide();
			} else {
				this.reqType = 'new'; 
				this._ajaxRequest(this._ajaxParams(), this.type);
				this.weLoadingElm.show();
				this.weItemElm.fadeTo(0,0.3);
			}
		},
		responsHandler : function(){
		},
		_getMyBaseElm : function(){
			 return $('#' + gcHGToolBar.toolIDMap[this.type] + ' .hgToolsMenu');
		},
		_setCloseEvent: function(){
			$('.closeArea img', this.weBaseElm.get(0)).click($.proxy(this.hide,this));
		},
		toContent : function(url,bID,cID){
			this._clickCnt({buttonId:bID,contentId:cID},url);
			location.href = url;
		},
		errorHandler : function(data){
			this.weLoadingElm.hide();
			this.weItemElm.fadeTo(0, 1);
		},
		show : function(){
				var e = $('.listArea',this.weBaseElm.get(0));
				e.css('height','');
				var h = e.height();
				var eh = Math.min(h,400);

				tpx = (eh + this.slideVar) +'px';
				e.css('height',eh + 'px');
				gcHGToolBar.changeTool(this.type);
				this.dispFlg = true;

			this.weBaseElm.animate({'height':tpx},300,"easeOutSine");
			this._changeItemImage(true);
		}
	});
})(jQuery);

(function($) {
	$.Class.extend(hg.hgToolBar.Base,'hg.hgToolBar.Online',{
		init : function(opt){
			this.prms = $.extend({
			}, opt);
			this.type = 'online';
			this.bID = this.prms.bID;
			this.dispFlg = false;
			this.avaCnt = 0;
			this.page = 0;
			
			this.itemImg = {
				show : 'http://images.hangame.co.jp/hangame/common/hg_toolbar/ico_arrow.gif'
				,hide : 'http://images.hangame.co.jp/hangame/common/hg_toolbar/ico_arrow_down.gif'
			}
			this.slideVar = 38;
			this.removeFlg = false;
			this.onLineLiClassMap = {
				0 : '', // オフライン
				1 : 'act01', // オンライン
				2 : '', // 最終ゲーム起動
				3 : 'act01', // ログイン中
				4 : 'act02' // フォローされた
			},
			this.followErrorMsgMap = {
				// msgid:[msg,li削除するか]
				'1' : ['ログインしてください', false],
				'2' : ['これ以上フォローできません', true],
				'3' : ['既にフォローしています', true],
				'4' : ['既に友だちになっています', true],
				'5' : ['フォローに失敗しました', true],
				'9' : ['フォローに失敗しました', false]
			}
		},
		
		_ajaxParams : function(){
			if(this.reqType == 'new') return {page:1};
			return {page:this.page + 1};
		},
		responsHandler : function(data){
			if(this.reqType == 'follow' || this.reqType == 'ignore'){
				this._followResult(data);
				return;
			}
			//todo
			if (!this.weListElm) {
				this.weListElm = $('ul.listArea', this.weBaseElm.get(0));
				this.elScrollElm = this.weListElm.get(0).parentNode;
				this.weMoreElm = $('p.moreBtn', this.weBaseElm.get(0));
				this._setMoreEvent();
			}

			(data.hasnext)? this.weMoreElm.show() : this.weMoreElm.hide();

			this.page = data.page;
			this._makeList(data.list);
			if (this.reqType != 'more') {
				this.show();
				this.weLoadingElm.hide();
				this.weItemElm.fadeTo(0, 1);
			}else{
				this._loading(false);
			}
		},
		_followRequest : function(param, reqType) {
			gcHGToolBar.onAjax = true;
			this.prms.proxy.contentWindow.gcHGToolBarProxy.xhr(param,this.type,this._followAjaxAPIURL(), reqType);
		},
		_followAjaxAPIURL : function() {
			return gcHGToolBar.toolAPIMap[this.reqType];
		},
		errorHandler : function(data){
			this.weLoadingElm.hide();
			this.weItemElm.fadeTo(0, 1);
			if (this.reqType == 'more') this._loading(false);
		},
		_setMoreEvent : function(){
			this.weMoreElm.click($.proxy(this._more,this));
		},
		_more : function(){
			if(gcHGToolBar.onAjax) return;
			this._loading(true);
			this.reqType = 'more';
			this._ajaxRequest(this._ajaxParams(),this.type);
		},
		_loading : function(flg){
			(flg)? this.weMoreElm.addClass('load') : this.weMoreElm.removeClass('load');
		},
		_changeItemImage : function(showFlg){
			if(showFlg){
				this.weItemImg.css('background','url(' + this.itemImg.hide + ') no-repeat scroll right center transparent');
			}else{
				this.weItemImg.css('background','url(' + this.itemImg.show + ') no-repeat scroll right center transparent');
			}
		},
		_makeList : function(data){
			if (this.reqType != 'more') {
				this.avaCnt = 0;
				this.weListElm.html('');
				
				if(data.length <= 0){
					this.weListElm.html('<li class="noItem">現在フォロー中の人はいません。<a href="' + this.prms.friendsURL + '">友だち広場</a>で友だちを探してみよう！</li>');
					return;
				}
			}

			var _this = this;

			$(data).each(function(i){
				var v = this;
				_this.avaCnt += 1;
				var li = $('<li>');
				//var myAvaIdCnt = _this.avaidCnt;
				li.addClass(_this.onLineLiClassMap[this.online]);
				li.html(_this._liTag(this,_this.avaCnt));
				_this.weListElm.append(li);
				
				$('a.cont_jskey',li).click(function(e){
					e.preventDefault();
					_this.toContent(v.gameurl,_this.bID,v.contentid);
				},this);
				VIEWER_showAvatarNf3("onlineAva"+_this.avaCnt,"GHS", this.avatarid);

				var followElm = $('.fbtns a', li);
				$.each(followElm, function(i, j) {
					$(j).click(function(e) {
						if(e) e.preventDefault();
						_this._follow(i, v.userid, e);
					});
				});
			});
		},

		_follow : function(num, userid, e) {
			if(gcHGToolBar.onAjax) return;
			if(this.removeFlg) return;
			this.removeFlg = true;
			this.reqType = num == 0 ? 'follow' : 'ignore';
			this.welRemoveLi = $(e.target.parentNode.parentNode.parentNode);
			this._followRequest({"userid": userid}, this.reqType);
		},

		_followResult : function(data) {
//			var welRemoveLi = $(e.target.parentNode.parentNode.parentNode);
			var msg = {'follow': 'フォローしました！', 'ignore': '無視しました'};
			var welMsg = $('<p>').addClass('actTxt').html(msg[this.reqType]);
			var friendNum = parseInt(gcHGToolBar.commonNumElms.friend.text(), 10);
			var _this = this;
			if(data.result && parseInt(data.result) == 0) {
				this.welRemoveLi.html(welMsg);
				if(this.reqType == 'follow') { // follow
					gcHGToolBar.commonNumElms.friend.html(friendNum + 1);
				}
				welMsg.delay(1000).fadeOut('fast', function() {
//					_this.welRemoveLi.animate({height: '0px'}, 'fast', function() {
					_this.welRemoveLi.animate({height: '0px'}, 0.5, function() {
						_this.welRemoveLi.remove();
						_this.removeFlg = false;
					});
				});
			} else {
				var welFbtnDiv = $('div.fbtns', this.welRemoveLi);
				welFbtnDiv.hide();
				var errmsg = this.followErrorMsgMap[data.msgid][0] || (this.reqType == 'follow' ? 'フォローに失敗しました' : 'フォローキャンセルに失敗しました');
//				var errmsg = data.msg || (this.reqType == 'follow' ? 'フォローに失敗しました' : 'フォローキャンセルに失敗しました');
				var welFollowError = $('<div>').addClass('fbtns').html(errmsg);
				this.welRemoveLi.append(welFollowError);
				setTimeout(function() {
					welFollowError.remove();
					welFbtnDiv.show();
					if(_this.followErrorMsgMap[data.msgid][1] == true) {
						_this.welRemoveLi.animate({height: '0px'}, 0.5, function() {
							_this.welRemoveLi.remove();
							_this.removeFlg = false;
						});
					}
				}, 1500);
				this.removeFlg = false;
			}
		},

		_liTag : function(data,i){
//			var template = '<a href="%mypageurl%" target="mypage"><div id="%avaid%"></div></a><dl><dt class="hgId"><a href="%mypageurl%" target="mypage">%userid%</a>%minimaillink%</dt><dd %ddstyle%>%now%　<a href="%gameurl%" class="cont_jskey">%gametitle% %gameplace%</a> %gamestart%<span class="history">%gamestartdt%</span></dd></dl>';
			var template = '<a href="%mypageurl%" target="mypage"><div id="%avaid%"></div></a><dl><dt class="hgId"><a href="%mypageurl%" target="mypage">%userid%</a>%followmsg%%minimaillink%</dt><dd %ddstyle%>%now%　<a href="%gameurl%" class="cont_jskey">%gametitle% %gameplace%</a> %gamestart%<span class="history">%gamestartdt%</span></dd></dl>%fbtns%';
			var mypageURL = getMypageURL('?mid='+data.userid,0,0);
			
			if(data.online == 0){
				template = template.replace('%ddstyle%','style="display:none"');
				template = template.replace('%minimaillink%', '');
				template = template.replace('%followmsg%', '');
				template = template.replace('%fbtns%', '');
			} else if (data.online == 3) {
				data.gameurl = mypageURL + '#bbs';
				template = template.replace('%ddstyle%','');
				template = template.replace('%now%', 'ハンゲームにログイン中！');
				template = template.replace('%gametitle%', '伝言板');
				template = template.replace('%gamestartdt%', '');
				template = template.replace('%gameplace%', '');
				template = template.replace('%gameurl%', data.gameurl + '" target="mypage"');
				template = template.replace('%gamestart%', ' であいさつしよう');
				template = template.replace('%minimaillink%', '<a href="javascript:openPost(\'?tid[]='+ data.userid +'\')" class="minimail"><img alt="ミニメール" title="ミニメールを送る" src="http://images.hangame.co.jp/hangame/common/userarea/ico_mail.gif"></a>');
				template = template.replace('%followmsg%', '');
				template = template.replace('%fbtns%', '');
				data.contentId = 'WEB';
			} else if (data.online == 4) {
				// 表示 userid ,avatarid gametitle,urlがある場合はゲームのリンク
				template = template.replace('%followmsg%', 'さんにフォローされました！');
				template = template.replace('%now%', '');
				if(data.gametitle && data.gameurl) {
					template = template.replace('%ddstyle%','');
					template = template.replace('%gametitle%', data.gametitle);
					template = template.replace('%gameurl%', data.gameurl);
					template = template.replace('%gamestart%', 'で遊んだことがあります');
				} else {
					template = template.replace('%ddstyle%','style="display:none"');
					template = template.replace('%gametitle%', '');
					template = template.replace('%gameurl%', '');
					template = template.replace('%gamestart%', '');
				}
				template = template.replace('%gamestartdt%', '');
				template = template.replace('%gameplace%', '');
				template = template.replace('%minimaillink%', '');
//				template = template.replace('%minimaillink%', '<a href="javascript:openPost(\'?tid[]='+ data.userid +'\')" class="minimail"><img alt="ミニメール" title="ミニメールを送る" src="http://images.hangame.co.jp/hangame/common/userarea/ico_mail.gif"></a>');

				template = template.replace('%fbtns%', '<div class="fbtns"><a href="#"><img width="126" height="25" alt="フォローをお返しする" src="http://images.hangame.co.jp/hangame/common/btn/btn_follow01_126x25.gif"></a><a href="#"><img width="66" height="25" alt="無視する" src="http://images.hangame.co.jp/hangame/common/btn/btn_follow02_66x25.gif"></a></div>');
			} else{
				template = template.replace('%ddstyle%','');
				template = template.replace('%followmsg%', '');
				template = template.replace('%fbtns%', '');
				if (data.gamestartdt) {
					template = template.replace('%minimaillink%', '');
					template = template.replace('%now%', '');
					template = template.replace('%gametitle%',data.gametitle);
					template = template.replace('%gameplace%', '');
					template = template.replace('%gamestart%', 'ゲームスタート');
					template = template.replace('%gamestartdt%', '（' + data.gamestartdt + '）');
					template = template.replace('%gameurl%', data.gameurl);
				} else {
					template = template.replace('%now%', '現在');
					template = template.replace('%gametitle%',data.gametitle);
					template = template.replace('%gamestartdt%', '');
					if (data.gameplace == '') {
						template = template.replace('%gameplace%', '');
						template = template.replace('%gamestart%', 'をプレイ中');
					} else {
						template = template.replace('%gameplace%', 'の' + data.gameplace);
						template = template.replace('%gamestart%', 'でプレイ中');
					}
					template = template.replace('%gameurl%', data.gameurl);
					template = template.replace('%minimaillink%', '<a href="javascript:openPost(\'?tid[]='+ data.userid +'\')" class="minimail"><img alt="ミニメール" title="ミニメールを送る" src="http://images.hangame.co.jp/hangame/common/userarea/ico_mail.gif"></a>');
				}
			}
			template = template.replace('%avaid%','onlineAva' + i);
			template = template.replace(/%userid%/g,data.userid);
			template = template.replace(/%mypageurl%/g,mypageURL);
			return template
		},
		show : function(){
			var e = $('.hgToolList',this.weBaseElm.get(0));
			e.css('height','');
			var h = e.height();
			var eh = Math.min(h,400);

			tpx = (eh + this.slideVar) +'px';
			e.css('height',eh + 'px');
			gcHGToolBar.changeTool(this.type);
			this.dispFlg = true;

			this.weBaseElm.animate({'height':tpx},300,"easeOutSine");
			this._changeItemImage(true);
		}
	});
})(jQuery);

(function($) {
	$.Class.extend(hg.hgToolBar.Base,'hg.hgToolBar.PlayHistory',{
		init : function(opt){
			this.prms = $.extend({
			}, opt);
			this.type = 'playHistory';
			this.dispFlg = false;
			this.bID = this.prms.bID;
			this.gameStatusImgMap = {
				ok : 'http://images.hangame.co.jp/hangame/htop/extraarea/icn_governing.gif'
				,ng : 'http://images.hangame.co.jp/hangame/htop/extraarea/icn_mainte.gif'
			}
			
			this.iconImgMap = {
				NEW:'http://images.hangame.co.jp/hangame/htop/icn_new.gif'
				,EVENT:'http://images.hangame.co.jp/hangame/htop/icn_event.gif'
				,UPDATE:'http://images.hangame.co.jp/hangame/htop/icn_update.gif'
				,TEST:'http://images.hangame.co.jp/hangame/htop/icn_test.gif'
			}
			
			this.msgMap = {
				'0' : 'マイメニューに登録しました。'
				,'-1' : '登録に失敗しました。'
				,'1' : 'これ以上登録できません。'
				,'2' : 'すでに登録されています。'
				,'4' : '登録に失敗しました。'
			}
			
			this.itemImg = {
				show : 'http://images.hangame.co.jp/hangame/common/hg_toolbar/img_history.gif'
				,hide : 'http://images.hangame.co.jp/hangame/common/hg_toolbar/img_history_down.gif'
			}
			
			this.slideVar = 45;
			
		},
		
		
		responsHandler : function(data,subType){
			if (subType == 'add') {
				this._addResponseHandler(data);
				return;
			}
//			this.contentsMaster = data;
//			data = this.historyData;
			//todo
			if (!this.weListElm) {
				this.weListElm = $('ul.listArea', this.weBaseElm.get(0));
			}
			
			this._makeList(data.list);
			this.show();
			this.weLoadingElm.hide();
			this.weItemElm.fadeTo(0,1);
		},
		_makeList : function(data){
			this.weListElm.html('');
			
			if(data.length <= 0){
				this.weListElm.html('<li class="noItem">プレイ履歴はありません<br>※一部ゲームは履歴に反映されません</li>');
				return;
			}
			
			var _this = this;
			$(data).each(function(){
				if(this.valid == 'N') return true;
				
				var li = $('<li>');
				li.html(_this._liTag(this));
				_this.weListElm.append(li);
				var v = this;				
				$('img.add',li).click(function(e){
					_this.add(v.contentid,e);
				})
				$('a.cont_jskey',li).click(function(e){
					e.preventDefault();
					_this.toContent(v.url,_this.bID,v.contentid);
				},this);
			})
		},
		_liTag : function(data){
			var template = '<a href="#" class="cont_jskey"><img class="thm" alt="" src="http://images.hangame.co.jp/_images/toppage/gicon_%contentid%.gif" width="32" height="32"></a><img class="stt" alt="" src="%ment%">%iconimg%<br><span><a href="#" class="cont_jskey">%title%</a></span>%addimg%';

			template = template.replace('%contentid%',data.contentid.toLowerCase());
			//template = template.replace('%url%',data.url);
			template = template.replace('%ment%',(data.ment == 'Y')? this.gameStatusImgMap.ng :this.gameStatusImgMap.ok);
			if (data.icon != 'NONE') {
				template = template.replace('%iconimg%', '<img alt="' + data.icon + '" src="' + this.iconImgMap[data.icon] + '" class="stt">');
			}else{
				template = template.replace('%iconimg%', '');
			}
			template = template.replace('%title%',data.title);
			
			(data.mymenu)? addimg = '' : addimg = '<img class="add" alt="+" title="マイメニューに追加" src="http://images.hangame.co.jp/hangame/htop/extraarea/icn_plus.gif">';
			template = template.replace('%addimg%',addimg);
			return template
		},
		add : function(contentid,e){
			this.welDelLi = $(e.target.parentNode);
			this._ajaxRequest({contentId:contentid},this.type+'add','add');
		},
		_addResponseHandler : function(data){
			var result = data.result;
			
			var welMsg = $('<em>');
			welMsg.html(this.msgMap[result]);
			this.welDelLi.append(welMsg.get(0));
			if(result == '0') $('img.add',this.welDelLi).remove();
			
			welMsg.delay(2000).fadeOut('fast',$.proxy(function(){
				welMsg.remove();
			},this));
		}
	});
})(jQuery);

(function($) {
	$.Class.extend(hg.hgToolBar.Base,'hg.hgToolBar.MyMenu',{
		init : function(opt){
			this.prms = $.extend({
			}, opt);
			this.type = 'myMenu';
			this.dispFlg = false;
			this.bID = this.prms.bID;
			this.msgMap = {
				'0' : 'マイメニューから削除しました。'
				,'-1' : 'マイメニューから削除に失敗しました。'
//				emptyMyMenu : 'サービスが未登録です。<br /><br />【マイメニューとは？】<br />よく利用するサービスのショートカットです♪<br />各サービスにある「マイメニューに追加」ボタンを押して登録してね。'
			}
			
			this.itemImg = {
				show : 'http://images.hangame.co.jp/hangame/common/hg_toolbar/img_mymenu.gif'
				,hide : 'http://images.hangame.co.jp/hangame/common/hg_toolbar/img_mymenu_down.gif'
			}
		},
		
		responsHandler : function(data,subType){
			if (subType == 'del') {
				this._delResponseHandler(data);
				return;
			}
			
			if (!this.weListElm) {
				this.weListElm = $('ul.listArea', this.weBaseElm.get(0));
			}

			this._makeList(data.list);
			this.show();
			this.weLoadingElm.hide();
			this.weItemElm.fadeTo(0,1);
		},
		_makeList : function(data){
			this.weListElm.html('');
			
			if(data.length <= 0){
				this.weListElm.html('<li class="noItem">登録されている内容はありません</li>');
				return;
			}
			
			var _this = this;
			
			$(data).each(function(){
				var v = this;
				var li = $('<li>');
				li.html(_this._liTag(this));
				_this.weListElm.append(li);
				
				$('img.del_jskey',li).click(function(e){
					_this.del(v.contentid,e);
				});
				$('a.cont_jskey',li).click(function(e){
					e.preventDefault();
					_this.toContent(v.url,_this.bID,v.contentid);
				},this);
			})
		},
		_liTag : function(data){
			if (data.valid == 'Y') {
				var template = '<a href="#" class="cont_jskey">%title%</a><img class="del_jskey" alt="削除" src="http://images.hangame.co.jp/hangame/htop/extraarea/icn_delete.gif">';
				template = template.replace('%title%', data.title);
				//template = template.replace('%url%', data.url);
			}else{
				var template = '%title%<img class="del_jskey" alt="削除" src="http://images.hangame.co.jp/hangame/htop/extraarea/icn_delete.gif">';
				template = template.replace('%title%', '終了したサービスです');
			}
			return template
		},
		del : function(contentid,e){
			this.welDelLi = $(e.target.parentNode);
			this._ajaxRequest({contentId:contentid},this.type+'del','del');
		},
		_delResponseHandler : function(data){
			var result = data.result;
			
			var welMsg = $('<em>');
			welMsg.html(this.msgMap[result]);
			this.welDelLi.append(welMsg.get(0));
			
			(result == '0')? el = this.welDelLi : el = welMsg; 
			el.delay(2000).fadeOut('fast',$.proxy(function(){
				el.remove()
			},this));
		}
	});
})(jQuery);

(function($) {
	$.Class.extend(hg.hgToolBar.Base,'hg.hgToolBar.Imapico',{
		init : function(opt){
			this.prms = $.extend({
			}, opt);
			
			this.userID = this.prms.userid;

			this.type = 'imapico';
			this.dispFlg = false;
			this.bID = this.prms.bID;
			this.remarkno_friend = null;
			this.remarkno_my = null;
			
			this.page_friend = 1;
			this.page_my = 1;
			
			this.currentTab = 'friend';
			
			this.listParamMap = {
				friend : 'FRIEND_NEW'
				,my : 'MY_NEW'
			}
			
			this.fromKindMap = {
	            P: {alt: 'パソコン',img: 'ico_pc_18x18.gif'},
	            M: {alt: 'モバイル',img: 'ico_mob_18x18.gif'},
	            S: {alt: 'スマートフォン',img: 'ico_smt_18x18.gif'}
	        }
			
			// フィード種別
            this.remarkKind = {
                non: 'T1', target: 'T2', svc: 'T3',// イマピコ
                game: 'F1', gameBoot: 'F2', 
				blogNew: 'F3_B_NEW', blogCom: 'F3_B_COM', // ブログ
				circleTpc: 'F3_C_TPC', circleCom: 'F3_C_COM', // サークル
				bbsCom: 'F3_T_COM', bbsRes: 'F3_T_RES', // 掲示板
                iconGet: 'F4', // 記念アイコン
                koreGet: 'F5_GET', koreComp: 'F5_COMP', koreFeaver: 'F5_FEVR', koreMyCard: 'F5_MY', koreYourCard: 'F5_YOUR', korePresent: 'F5_SEND', korePresented: 'F5_RECV', koreDeny: 'F5_DENY', // イマコレ
                avAlbum: 'F6_ALBUM', avStage: 'F6_STAGE'// アバター
            }
			
			this.itemImg = {
				show : 'http://images.hangame.co.jp/hangame/common/hg_toolbar/img_question.gif'
				,hide : 'http://images.hangame.co.jp/hangame/common/hg_toolbar/img_question_down.gif'
			}
			
		},
		
		_setTabEvent : function(){
			var tabElm = $('ul.impcTab li',this.weBaseElm);
			this.welTab_friend = $(tabElm.get(0));
			this.welTab_my = $(tabElm.get(1));
			
			this.welTab_friend.click($.proxy(function(){this.changeTab('friend');},this));
			this.welTab_my.click($.proxy(function(){this.changeTab('my');},this));
		},
		changeTab :function(tab,post){
			if(gcHGToolBar.onAjax) return;
			this.currentTab = tab;
			if(post){
				this.postFlg = post;
				this.reqType = 'new';
			}
			
			
			if(this['remarkno_' + this.currentTab] == null || this.postFlg) this._listAjaxRequest({dispCateCode:this.listParamMap[this.currentTab]});
			if(this.postFlg) this.postFlg = false;
			
			switch(tab){
				case 'friend':
					this.welListDiv_my.hide();
					this.welListDiv_friend.show();
					this.welTab_friend.removeClass('off');
					this.welTab_my.addClass('off');
					break;
				case 'my':
					this.welListDiv_friend.hide();
					this.welListDiv_my.show();
					this.welTab_friend.addClass('off');
					this.welTab_my.removeClass('off');
					break;
			}
		},
		focusTextarea : function(){
			this.welTextArea.get(0).focus();
		},
		//LIST AJAX
		_listAjaxRequest : function(param){
			gcHGToolBar.onAjax = true;
			this.prms.proxy.contentWindow.gcHGToolBarProxy.xhr(param,this.type,this._listAjaxAPIURL());
		},
		_listAjaxAPIURL : function(){
			return gcHGToolBar.toolAPIMap[this.type][this.currentTab];
		},
		_loading : function(flg){
			(flg)? $(this['welMoreElm_' + this.currentTab]).addClass('load') : $(this['welMoreElm_' + this.currentTab]).removeClass('load');
		},
		//MSG AJAX
		_msgAjaxRequest : function(param,subType){
			gcHGToolBar.onAjax = true;
			this.prms.proxy.contentWindow.gcHGToolBarProxy.xhr(param,this.type,this._msgAjaxAPIURL(subType),subType);
		},
		_msgAjaxAPIURL : function(subType){
			return gcHGToolBar.toolAPIMap[this.type + subType];
		},
		_setOwnerInfo : function(){
			VIEWER_showAvatarNf3('hgTBImapicoOwnerAva',"GHS", getCookie(CK_AVATARID));
			this.welOwnerID.html(this.userID)
		},
		clickHandler : function(text){
			this.defaultText = text || '';
			if (!this.weBaseElm) {
				this.weBaseElm = this._getMyBaseElm();

				this.welDiv = $('div.impcDataFrame',this.weBaseElm);
				this.welListDiv_friend = $(this.welDiv.get(0));
				this.welListDiv_my = $(this.welDiv.get(1));
				
				this.weListElm_friend = $('ul', this.welListDiv_friend);
				this.weListElm_my = $('ul', this.welListDiv_my);
				
				this.eScrollElm_friend = this.weListElm_friend.get(0).parentNode;
				this.eScrollElm_my = this.weListElm_my.get(0).parentNode;
				
				this.moreElm = $('.moreBtn', this.weBaseElm);
				this.welMoreElm_friend = this.moreElm.get(0);
				this.welMoreElm_my = this.moreElm.get(1);
				this.weItemElm = $('p.item',this.weBaseElm.parent());
				this.weLoadingElm = $('p.loader',this.weBaseElm.parent());
				
				
				this.wePostBtn = $('p.cmmntBtn > img',this.weBaseElm);
				
				
				this.welOwnerAva = $('div.avaImg',this.weBaseElm);
				this.welOwnerID = $('span.hgId',this.weBaseElm);
				
				this.welTextArea = $('.bllnInner > textarea',this.weBaseElm);
			
				//set btn events
				this._setMoreEvent();
				this._setCloseEvent();
				this._setTabEvent();
				this._setPostEvent();
		
				this._setOwnerInfo();
				gcHGToolBar[gcHGToolBar.toolClassMap['imapicopost']].initialize();
				
				this.weBaseElm.mousewheel($.proxy(function(event, delta) {
					if(event.preventDefault){
						event.preventDefault();
					}else{
						event.returnValue = false; 
					};
					this['eScrollElm_'+this.currentTab].scrollTop -= delta*10;
				},this));
				
				this.weItemImg = $('img', this.weItemElm);
			}
			
			//remarkno reset
			this['remarkno_' + this.currentTab] = null;
			
			if (this.dispFlg) {
				this.hide();
			} else {
				this.reqType = 'new'; 
				this._listAjaxRequest({page:1,dispCateCode:this.listParamMap[this.currentTab]});
				this.weLoadingElm.show();
				this.weItemElm.fadeTo(0,0.3);
			}
		},
		_reportResult : function(data,param){
			$('li.callIn',$('.'+param.remarkno,this['welBaseElm_'+this.currentTab])).html((data.result)? 'ハンゲームへ通報しました' : '通報に失敗しました');
		},
		_delResult : function(data,param){
			var welBaseLi = $('.'+param.remarkno,this['welBaseElm_'+this.currentTab]);
			var welDelLi = $('li.close',welBaseLi);
			if(data.result){
				welBaseLi.css('height',welBaseLi.height() + 'px')
				var welEM = $('<em>').html('削除しました。').css('height',(welBaseLi.height()-4) + 'px');
				welBaseLi.html(welEM);
				welEM.delay(2000).fadeOut('fast',function(){
					welBaseLi.animate({height:'0px'},'fast',function(){
						welBaseLi.remove();
					});
				});
			}else{
				var welDelA = $('a.del_jskey',welBaseLi);
				welDelA.hide();
				var welDelError = $('<span>').html('削除に失敗しました');
				welDelLi.append(welDelError);
				
				setTimeout(function(){
					welDelError.remove();
					welDelA.show();
				},3000);
			}
		},
		responsHandler : function(data,subType,param){
			
			if(subType){
				switch(subType){
					case 'report':
					this._reportResult(data,param);
					break;
					case 'del':
					this._delResult(data,param);
					break;
				}
				return;
			}
			//first request
			(data.hasnext)? $(this['welMoreElm_'+this.currentTab]).show() : $(this['welMoreElm_'+this.currentTab]).hide();
			
			this['page_' + this.currentTab] = data.page;
			
			this._makeList(data.list);
			if(!this.dispFlg) this.show();
			
			this.weLoadingElm.hide();
			this.weItemElm.fadeTo(0,1);
		},
		errorHandler : function(data){
			this.weLoadingElm.hide();
			this.weItemElm.fadeTo(0, 1);
			if (this.reqType == 'more') this._loading(false);
		},
		show : function(){
				if(this.defaultText){
					this.welTextArea.html(this.defaultText);
				}
				var e = $('.hgToolsBody',this.weBaseElm.get(0));
				var eh = 480;
				tpx = (eh + 38) +'px';
				e.css('height',eh + 'px');
				gcHGToolBar.changeTool(this.type);
				this.dispFlg = true;
				this.weBaseElm.animate({'height':tpx},300,"easeOutSine",$.proxy(this.focusTextarea,this));
				this._changeItemImage(true);
		},
		_setPostEvent :function(){
			this.wePostBtn.click($.proxy(this.post,this));
		},
		_setMoreEvent : function(){
			this.moreElm.click($.proxy(this._more,this));
		},
		_more : function(){
			if(gcHGToolBar.onAjax) return;
			this._loading(true);
			this.reqType = 'more';
			this._listAjaxRequest({page:this['page_' + this.currentTab] + 1,dispCateCode:this.listParamMap[this.currentTab]},this.type);
		},
		reportConfirm : function(remarkno) {
			$('li.callIn:first',$('.'+remarkno,this['welBaseElm_'+this.currentTab])).hide();
			$('li.rconfirm_jskey',$('.'+remarkno,this['welBaseElm_'+this.currentTab])).fadeIn();
		},
		report : function(remarkno, isReport){
			//console.debug(remarkno)
			$('li.rconfirm_jskey',$('.'+remarkno,this['welBaseElm_'+this.currentTab])).hide();
			$('li.callIn:first',$('.'+remarkno,this['welBaseElm_'+this.currentTab])).fadeIn();
			if(isReport) {
				this._msgAjaxRequest({
					remarkno: remarkno
				},'report');
			}
		},
		delConfirm : function(remarkno) {
			$('li.close:first',$('.'+remarkno,this['welBaseElm_'+this.currentTab])).hide();
			$('li.dconfirm_jskey',$('.'+remarkno,this['welBaseElm_'+this.currentTab])).fadeIn();
		},
		del : function(remarkno, isDel){
			//console.debug(remarkno)
			$('li.dconfirm_jskey',$('.'+remarkno,this['welBaseElm_'+this.currentTab])).hide();
			$('li.close:first',$('.'+remarkno,this['welBaseElm_'+this.currentTab])).fadeIn();
			if(isDel) {
				this._msgAjaxRequest({
					remarkno: remarkno
				},'del');
			}
		},
		_makeList : function(data){
			var targetElm = this['weListElm_' + this.currentTab];

			if (this.reqType != 'more') {
				this.avaCnt = 0;
				targetElm.html('');
				targetElm.get(0).scrollTop = 0;
				if (data.length <= 0) {
					targetElm.html('<li class="noItem">活動情報はありません</li>');
					return;
				}
			}else{
				this._loading(false);
			}
			
			var _this = this;
			
			(this.postFlg)? lastRemarkno = null : lastRemarkno = this['remarkno_' + this.currentTab];
			$(data).each(function(){
				//overlap data
				//if(lastRemarkno != null && lastRemarkno <= this.remarkno) return true;
				
				var li = $('<li>');
				li.addClass(this.remarkno);
				_this.avaCnt += 1;
				li.html(_this._liTag(this,_this.avaCnt));
				targetElm.append(li);
				VIEWER_showAvatarNf3('imapico'+_this.currentTab+'Ava'+_this.avaCnt,"GHS", this.avatarid);
				
				var v = this;
				$('a.del_jskey',li).click(function(e){
					e.preventDefault();
//					_this.del(v.remarkno);
					if(v.kind == _this.remarkKind.target) {
						_this.delConfirm(v.remarkno);
					} else {
						_this.del(v.remarkno, true);
					}
				},this);
				$('a.delok_jskey',li).click(function(e){
					e.preventDefault();
					_this.del(v.remarkno, true);
				},this);
				$('a.delcancel_jskey',li).click(function(e){
					e.preventDefault();
					_this.del(v.remarkno, false);
				},this);
				$('a.report_jskey',li).click(function(e){
					e.preventDefault();
//					_this.report(v.remarkno);
					_this.reportConfirm(v.remarkno);
				},this);
				$('a.reportok_jskey',li).click(function(e){
					e.preventDefault();
					_this.report(v.remarkno, true);
				},this);
				$('a.reportcancel_jskey',li).click(function(e){
					e.preventDefault();
					_this.report(v.remarkno, false);
				},this);
				
				_this['remarkno_' + _this.currentTab] = this.remarkno;
			});
		},
		_liTag : function(data,i){
			var template = '<p class="colL"><span id="%avaid%"></span></p><div class="colR"><div class="status"><div class="inr"><p class="action">%feedaction%</p><p class="data"><img height="18" width="18" src="%fromkindsrc%" alt="%fromkindalt%"><span>%laptime%</span></p></div></div>%remarktxttag%<div class="feedFt"><p class="ctTit"><img height="23" width="23" src="%iconurl%" alt="%svcname%" onerror="this.src = \'http://images.hangame.co.jp/_images/top200503/game/icon_hg.gif\'">%svcname%</p>%delreport%</div></div>';
			var fromMypageURL = getMypageURL('?mid='+data.fromid,0,0);
			
			template = template.replace('%feedaction%',this._getFeedAction(data));
			template = template.replace('%iconurl%',data.iconurl);
			template = template.replace(/%svcname%/g,this._getSvcNameString(data));
			template = template.replace('%delreport%',this._getLinksString(data) || '');
//			fromKindMap
			var fromKind = this.fromKindMap[data.path];
			template = template.replace('%fromkindsrc%','http://images.hangame.co.jp/hangame/common/icon/' + fromKind.img);
			template = template.replace('%fromkindalt%',fromKind.alt);
			if(data.remarkurl){
				if(data.kind == this.remarkKind.avStage) {
					// アバターステージの場合
					template = template.replace('%remarktxttag%','<p class="txt"><a href="' + data.remarkurl + '" onclick="openWin(this.href, \'popupAvatarStage\', 535, 660, \'yes\'); return false;">' + data.remarktxt + '</a></p>');
				} else {
					template = template.replace('%remarktxttag%','<p class="txt">' + this._getLinkString(data.remarktxt, data.remarkurl, this._isMypageLink(data.kind)) + '</p>');
//					template = template.replace('%remarktxttag%','<p class="txt"><a href="' + data.remarkurl + '">' + data.remarktxt + '</a></p>');
				}
			}else{
				template = template.replace('%remarktxttag%','<p class="txt">' + data.remarktxt + '</p>');
			}

			(data.talkimapiko)? delimg = '<img class="del_jskey" height="8" width="8" alt="削除" src="http://images.hangame.co.jp/_images/mypage/common/btn_delete.gif">削除' : delimg = '';
			template = template.replace('%delimg%',delimg);
			template = template.replace('%remarktxt%',data.remarktxt);
			template = template.replace('%fromid%',data.fromid);
			template = template.replace('%laptime%',data.laptime);
			template = template.replace('%avaid%','imapico'+this.currentTab+'Ava' + i);
			template = template.replace(/%fromMypageURL%/g,fromMypageURL);
			return template;
		},
		_getMypageLinkString: function(sUid){
			return '<a href="javascript:openMypage(\'' + sUid + '\',0,0);">' + sUid + '</a>さん';
	    },
		_getLinkString: function(sTxt, sUrl, bMypage){
			if(this._isLink(sUrl)) {
				if(bMypage) {
					return '<a href="' + sUrl + '" target="' + MYPAGE_WIN_NAME + '">' + sTxt + '</a>';
				} else {
					return '<a href="' + sUrl + '" target="_blank">' + sTxt + '</a>';
				}
			} else {
				return sTxt;
			}
	    },
		_isMypageLink: function(sKind) {
	        if (sKind == this.remarkKind.koreMyCard 
				|| sKind == this.remarkKind.koreYourCard 
				|| sKind == this.remarkKind.korePresent 
				|| sKind == this.remarkKind.korePresented 
				|| sKind == this.remarkKind.koreDeny 
				|| sKind == this.remarkKind.avAlbum) {
	        	return true;
	        }
			return false;
		},
		/**
		 * リンクが必要かどうか.
		 * @param {Object} sUrl
		 */
		_isLink: function(sUrl) {
			return sUrl && sUrl != '';
		},
		/**
		 * サービス名を返す.
		 * @param {Object} oResp
		 */	
	    _getSvcNameString: function(oResp){
	        var sSvcName = oResp.svcname;
	        switch (oResp['kind']) {
	            case this.remarkKind.non:
				case this.remarkKind.target:
				case this.remarkKind.svc:
	                sSvcName = 'イマピコ';
	                return sSvcName;
	            case this.remarkKind.blogNew:
	            case this.remarkKind.blogCom:
	                sSvcName = 'ブログ';
	                return sSvcName;
	            case this.remarkKind.circleTpc:
	            case this.remarkKind.circleCom:
	                sSvcName = 'サークル';
	                return sSvcName;
	            case this.remarkKind.bbsCom:
	            case this.remarkKind.bbsRes:
	                sSvcName = '掲示板';
	                return sSvcName;
	            case this.remarkKind.iconGet:
	                sSvcName = '記念アイコン';
	                return sSvcName;
	            case this.remarkKind.koreGet:
	            case this.remarkKind.koreComp:
	            case this.remarkKind.koreFeaver:
	            case this.remarkKind.koreMyCard:
	            case this.remarkKind.koreYourCard:
	            case this.remarkKind.korePresent:
	            case this.remarkKind.korePresented:
	            case this.remarkKind.koreDeny:
	                sSvcName = 'イマコレ';
	                return sSvcName;
				case this.remarkKind.avAlbum:
					sSvcName = 'アバターアルバム';
					return sSvcName;
				case this.remarkKind.avStage:
					sSvcName = 'アバターステージ';
					return sSvcName;
	            default:
	                return sSvcName;
	        }
	    },
		/**
		 * サービスのアイコンとリンク作成.
		 * @param {Object} sSvcName
		 * @param {Object} sSvcUrl
		 * @param {Object} sIconUrl
		 */
	    _getSvcIconLinkString: function(sSvcName, sSvcUrl, sIconUrl){
	        var sIconLinkString = '';
	        if (sSvcUrl && sSvcUrl != '') {
	            sIconLinkString = '<a href="' + sSvcUrl + '" target="_blank"><img src="' + sIconUrl + '" alt="' + sSvcName + '" width="23" height="23" onerror="this.src = \'' + this.hOption.sDefaultIconImagePath + '\'"/>' + sSvcName + '</a>';
	        } else {
	            sIconLinkString = '<img src="' + sIconUrl + '" alt="' + sSvcName + '" width="23" height="23" onerror="this.src = \'' + this.hOption.sDefaultIconImagePath + '\'"/>' + sSvcName;
	        }
	        return sIconLinkString;
	    },
		/**
		 * 削除or通報リンクの作成.
		 * @param {Object} oResp
		 * @param {Object} nDrawNum
		 */
		_getLinksString: function(oResp, nDrawNum) {
			var sUserID = getCookie(CK_MEMBERID);
			var sLinksString = '';
			var sReport = '';
			var sDel = '';
	
			if(typeof(oResp['talkimapiko']) == 'undefined') {
				switch (oResp['kind']) {
					// TODO これ不要なら削除 ユーザーの発言フィードのみ通報or削除をつける
		            case this.hOption.remarkKind.non:
					case this.hOption.remarkKind.target:
					case this.hOption.remarkKind.svc:
					case this.hOption.remarkKind.koreMyCard:
					case this.hOption.remarkKind.koreYourCard:
					case this.hOption.remarkKind.korePresent:
					case this.hOption.remarkKind.korePresented:
					case this.hOption.remarkKind.koreDeny:
						sReport = this._getReportLinkString(oResp, sUserID);
						sDel = this._getDelLinkString(oResp, sUserID, nDrawNum);
						break;
					default:
						break;
				}
			} else {
				if(oResp['talkimapiko'] == 'true') {
					// ユーザーの発言フィードのみ通報or削除をつける
					// 通報
					sReport = this._getReportLinkString(oResp, sUserID);
				} else if (oResp['talkimapiko'] == 'del') {
					sReport = this._getDelLinkString(oResp, sUserID, nDrawNum);
				}
			}
	
			if(sReport == '' && sDel == '') return sLinksString;
	
			sLinksString = '<ul class="links">';
			if(sReport != '') sLinksString += sReport;
			if(sDel != '') sLinksString += sDel;
			sLinksString += '</ul>'
			return sLinksString;
		},
		/**
		 * 通報リンク作成.
		 * @param {Object} oResp
		 * @param {Object} sUserID
		 */
	    _getReportLinkString: function(oResp, sUserID) {
			var sReport = '';
	//		if(oResp['fromid'] != sUserID) {
	//		sReport = '<li class="callIn"><a href="#" onclick="imapicoList.reportImapico(' + oResp['remarkno'] + '); return false;">ハンゲームへ通報</a></li>';
			sReport = '<li class="callIn"><a href="#" class="report_jskey">ハンゲームへ通報</a></li>';
			sReport += '<li class="callIn rconfirm_jskey" style="display:none;"><a href="#" class="reportok_jskey">通報する</a>|<a href="#" class="reportcancel_jskey">キャンセル</a></li>';
	//		}
			return sReport;
		},
		/**
		 * 削除リンク作成.
		 * @param {Object} oResp
		 * @param {Object} sUserID
		 * @param {Object} nDrawNum
		 */
	    _getDelLinkString: function(oResp, sUserID, nDrawNum){
			var sDel = '';
	//		if (oResp['fromid'] == sUserID || oResp['toid'] == sUserID) {
			sDel = '<li class="close"><a href="#" class="del_jskey"><img height="8" width="8" alt="削除" src="http://images.hangame.co.jp/_images/mypage/common/btn_delete.gif">削除</a></li>';
	//		}
			// 他人からの発言の場合は、確認をつける
			sDel += '<li class="close dconfirm_jskey" style="display:none;"><a href="#" class="delok_jskey">削除する</a>|<a href="#" class="delcancel_jskey">キャンセル</a></li>';
			return sDel;
	    },

		_getFeedAction: function(oResp){
			var sFeedAction = '';
			switch (oResp['kind']) {
				case this.remarkKind.non:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'のつぶやき';
					return sFeedAction;
				case this.remarkKind.target:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'から';
					sFeedAction += '<img src="http://images.hangame.co.jp/_images/mypage/common/arw_dod.gif" alt="" width="11" height="11" />';
					sFeedAction += this._getMypageLinkString(oResp['toid']) + 'へのコメント';
					return sFeedAction;
				case this.remarkKind.svc:
					sFeedAction = '<span>';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl']);
					sFeedAction += 'の話題</span>';
					sFeedAction += this._getMypageLinkString(oResp['fromid']) + 'のつぶやき';
					return sFeedAction;
				case this.remarkKind.game:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + ' ';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl']);
					return sFeedAction;
				case this.remarkKind.gameBoot:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'が';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl']);
					sFeedAction += 'で遊びました';
					return sFeedAction;
				case this.remarkKind.blogNew:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'がブログを書きました';
					return sFeedAction;
				case this.remarkKind.blogCom:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'がブログにコメントを書きました';
					return sFeedAction;
				case this.remarkKind.circleTpc:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'が';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl']);
					sFeedAction += 'で新しい記事を投稿しました';
					return sFeedAction;
				case this.remarkKind.circleCom:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'が';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl']);
					sFeedAction += 'でコメントを書きました';
					return sFeedAction;
				case this.remarkKind.bbsCom:
				case this.remarkKind.bbsRes:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'が掲示板';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl']);
					sFeedAction += ' に書きこみをしました';
					return sFeedAction;
				case this.remarkKind.iconGet:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'が記念アイコン';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl'], true);
					sFeedAction += 'を手に入れました';
					return sFeedAction;
				case this.remarkKind.koreGet:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'が';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl'], true);
					sFeedAction += 'を' + oResp['cardcnt'] + '枚GET!';
					return sFeedAction;
				case this.remarkKind.koreComp:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'が';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl'], true);
					sFeedAction += 'をコンプリート!';
					return sFeedAction;
				case this.remarkKind.koreFeaver:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'が';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl'], true);
					sFeedAction += 'をまとめて' + oResp['cardcnt'] + '枚GET!';
					return sFeedAction;
				case this.remarkKind.koreMyCard:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'が';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl'], true);
					sFeedAction += 'について発言しました';
					return sFeedAction;
				case this.remarkKind.koreYourCard:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'が';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl'], true);
					sFeedAction += 'について' + this._getMypageLinkString(oResp['toid']) + 'へコメントしました';
					return sFeedAction;
				case this.remarkKind.korePresent:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'が';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl'], true);
					sFeedAction += 'を' + this._getMypageLinkString(oResp['toid']) + 'へプレゼントしてくれるって!';
					return sFeedAction;
				case this.remarkKind.korePresented:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'が' + this._getMypageLinkString(oResp['toid']) + 'から';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl'], true);
					sFeedAction += 'を受け取りました';
					return sFeedAction;
				case this.remarkKind.koreDeny:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + 'が';
					sFeedAction += this._getLinkString(oResp['kindtxt'], oResp['kindurl'], true);
					sFeedAction += 'の受け取りを辞退しました。また今度よろしくね！';
					return sFeedAction;
				case this.remarkKind.avAlbum:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + ' アバターアルバム';
					return sFeedAction;
				case this.remarkKind.avStage:
					sFeedAction = this._getMypageLinkString(oResp['fromid']) + ' アバターステージ';
					return sFeedAction;
				default:
					//this._showError();
					
			}
		}
	});
})(jQuery);



(function($) {
	$.Class('hg.hgToolBar.ImapicoPost',{
		init : function(opt){
			this.prms = $.extend({
			}, opt);
			this.userID = this.prms.userid;
		},
		initialize : function(){
			this.sOwnerID = 'ownerID';
			this.type = 'imapicopost';
			this.pcEmojiList = new Array();
			this.initReqCmt = '';

			this._datas = {};
			this._textMap = {};
			this._imageMap = {};
			this._interimMap = {};
			this._wrap = null;
			this._textarea = null;
			this.sDefaultTxt = '';

			this.errorMsg = {
				'logout':'ハンゲームにログインしてください。'
				,'toolong':'140文字以内で入力してください。'
				,'blank':'イマピコを入力してください。'
				,'tabooword':'不適切な表現が含まれています。'
				,'interval':'10秒以内に連続して発言できません。'
				,'timeout':'イマピコの発言に失敗しました。'
				,'error':'エラーが発生しました。'
				,'mainte' : 'イマピコはただいまメンテナンス中です。'
			};
			this.successMsg = "イマピコで発言しました";
			this.oInputDefaultMessage = {
				'my': '今日なにがあった？',
				'other': this.sOwnerID + 'さんへのコメント',
				'imakore': 'カードをゆずってくれる人、交換する人を探そう'
			};

			this._getElms();
			this._setEvent();

		},
		
		_getElms : function(){
			this.elms = {};
			
			this.baseElm = $('div.bllnArea',$('#hgTools6'));
			
			this.elms.txt = $('.bllnInner > textarea',this.baseElm);
			this.elms.postBtnP = $('p.cmmntBtn',this.baseElm);
			this.elms.postBtn = $('p.cmmntBtn > img',this.baseElm);
			this.elms.counter = $('p.count > span',this.baseElm);
			this.elms.error = $('p.alert',this.baseElm);
		},
		_initRequest : function() {
			this._xhrRequest('init');
		},
		responsHandler : function(data,subType){
			this.elms.postBtnP.removeClass('load');
			if (!data.status) {
				this._checkErrorType(data.message);
				return;
			}
			this.elms.txt.get(0).value = '';
			this.elms.txt.get(0).focus();
			gcHGToolBar[gcHGToolBar.toolClassMap['imapico']].changeTab('my',true);
		},
		_setEvent : function(){
//			this.elms.txt.focus($.proxy(this.txtAreaOnfocus,this));
			this.elms.txt.keydown($.proxy(this.onKeyDown,this));
			this.elms.postBtn.click($.proxy(this.postComment,this));
			this.countIntv = window.setInterval($.proxy(this.inputCount,this),100);
		},
		onKeyDown : function(e){
			if(e.keyCode == 13){
				// 改行を制御
				e.preventDefault();
				this.postComment(e);
			}
		},
		// カウント
		inputCount : function() {
			// デフォルト文字列の場合はカウントしない
//			if(this.sDefaultTxt != this.elms.txt.get(0).value) {
				var value = this.elms.txt.get(0).value;
				var count = this.getEmojiTextSize(value, 1);
				this.elms.counter.html(count + '文字／最大140文字');
//			}
		},
//		txtAreaOnfocus : function(){
//			this.elms.txt.removeClass('ntEtrd');
//			var sTxtValus = this.elms.txt._element.value;
//			if(sTxtValus == this.sDefaultTxt || sTxtValus == this.initReqCmt){
//				this.elms.txt._element.value =  '';
//			}
//		},
		postComment : function(e){ 
			e.preventDefault();

			var value = this.elms.txt.get(0).value.replace(/\n|\r|\r\n/g,'').replace(/(^\s*)|(\s*$)/g,'');
			// デフォルト文字列チェック
			if(value == this.sDefaultTxt) {
				this._error('blank');
				return;
			}
			if(!this._validation(value)) return;
			this._xhrRequest('post',{cmt:value,tid:this.userID});
			this.elms.postBtnP.addClass('load');
		},
		
		_ajaxAPIURL : function(){
			return gcHGToolBar.toolAPIMap[this.type];
		},

		_xhrRequest : function(type,param){
			this.prms.proxy.contentWindow.gcHGToolBarProxy.xhr(param,this.type,this._ajaxAPIURL());
		},
		_timeout : function(){
			this.ajax.abort();
			this._error('timeout');
		},
		_postPetitCom : function(){
			var paramObj = {'mid':getCookie(CK_MEMBERID)};
		     this._xhrRequest('disp',paramObj);
		},
//		_complete : function(type){
//			var slocation = location.pathname + '?mid=' + this.sOwnerID;
//			if(this.svcid != null) slocation = slocation + '&svcid=' + this.svcid;
//			hgAlert(this.successMsg, function() {location = slocation;});
//		},

		_reqCallback : function(data,type){
			var _this = this;
			
			if(!data.status){
				//this._error(data.message);
				this._checkErrorType(data.message, type);
				return;
			}
//			if(type == 'init' && data.cmt == ''){
//			if(_this.bNeedDefaultMsg && type == 'init' && data.cmt == ''){
//				var cmt = this.oInputDefaultMessage.my;
//			}else{
//				var cmt = data.cmt;
//				this.initReqCmt = data.cmt;
//			}
//			this.nocmt = true;
//			this.elms.txt._element.value = this._replaceLength(cmt, 58);
			this.elms.txt.get(0).value = cmt;
			if(type == 'init'){
//				this._showComment();
			}else if(type == 'post'){
				this._complete(type);
			}
		},
		_validation : function(cmt){
			var nCmtLen = this.getEmojiTextSize(cmt, 1);
			if(nCmtLen == 0){
				this._error('blank');
				return false;
			}else if(nCmtLen > 140){
				this._error('toolong');
				return false;
			}
			return true;
		},
		_checkErrorType : function(msg, type) {
			if(msg == 'mainte') {
				// メンテナンス中の場合
				this.elms.postBtn.unbind('click',this.postComment);
				this.elms.txt.get(0).value = this.errorMsg[msg];
				this.elms.txt.attr('readonly', 'readonly');
				//this.postFn.detach(this.elms.postBtn,'click');
				//this.focusFn.detach(this.elms.txt,'focus');
				//this.keyDownFn.detach(this.elms.txt,'keydown');
				this.elms.counter.html('0文字／最大140文字');
				if (type == 'init') {
					this._clearTimer();
					return;
				}
			}
			this._error(msg);
		},
		_clearTimer : function() {
			if(this.timer){
				window.clearInterval(this.timer);
				this.timer = null;
			}
		},
		_error : function(msg){
			this._clearTimer();
			if(!msg) msg = 'error';
			var _this = this;
			this.elms.txt.get(0).focus();
			this.elms.error.html(this.errorMsg[msg]);
			this.elms.error.fadeIn(0);
			this.elms.error.delay(2000).fadeOut('fast');
		},
//		_onTextFocus : function(msg) {
//			if(msg == 'toolong' || msg == 'blank' || msg == 'tabooword' || msg == 'interval') {
//				this.elms.txt.$value().focus();
//			}
//		},
		_hideError : function(){
			this.elms.alert.hide();
			if(this.alertTimer){
				window.clearTimeout(this.alertTimer);
				this.alertTimer = null;
			}
		},
		_escapeHTML : function(str){
			var div = document.createElement('div');
			var text =  document.createTextNode('');
			div.appendChild(text);
			text.data = str;
			return div.innerHTML;
		},
		_replaceLength: function(value, nLength) {
			var str = '';
			if(value.length > nLength){
				for (i=0; i <= nLength; i++){
					str += value.charAt(i);
				}
				str += '...' ;
			} else {
				str = value;
			}
			return str;
		},
		getEmojiTextSize: function(sValue, nEmoji) {
			nEmoji = nEmoji || 5;
			var sTmp = sValue;
			var nCnt = 0;
			var nEmojiCnt = 0;
			var nEmojiFalseCnt = 0;
			var _this = this;
			sTmp = sTmp.replace(/\[[^\]]+\]/g, function(sItem, nPos, sStr) {
				if (_this.hasItem(sItem)) {
					nEmojiCnt += 1;
				} else {
					nEmojiFalseCnt += sItem.length;
				}
				return "";
			});

		    nCnt = sTmp.length + nEmojiFalseCnt + nEmojiCnt;
		    return nCnt;
		},
		hasItem: function(oIndex) {
			var oItem = this.getItem(oIndex);
			if (oItem) {
				return true;
			}
			return false;
		},
		setPcEmojiList: function(oIndex) {
			var oItem = null;
			if (typeof(oIndex) == "number") {
				oItem = this._datas[oIndex];
			} else if (typeof(oIndex) == "string" && oIndex.match(/^\[.+\]$/)) {
				oItem = this._textMap[oIndex];
			} else if (typeof(oIndex) == "string" && oIndex.match(/^\{.+\}$/)) {
				oItem = this._interimMap[oIndex];
			} else if (typeof(oIndex) == "string" && oIndex.match(/^.+\.gif$/)) {
				oItem = this._imageMap[oIndex];
			}
			if (!oItem) {
				return null;
			}
			return oItem;
		},
		/**
		 * 指定したインデックスの絵文字情報を取得
		 */
		getItem: function(oIndex) {
			var oItem = null;
			if (typeof(oIndex) == "number") {
				oItem = this._datas[oIndex];
			} else if (typeof(oIndex) == "string" && oIndex.match(/^\[.+\]$/)) {
				oItem = this._textMap[oIndex];
			} else if (typeof(oIndex) == "string" && oIndex.match(/^\{.+\}$/)) {
				oItem = this._interimMap[oIndex];
			} else if (typeof(oIndex) == "string" && oIndex.match(/^.+\.gif$/)) {
				oItem = this._imageMap[oIndex];
			}
			if (!oItem) {
				return null;
			}
			return oItem;
		},
		/**
		 * 絵文字データを直接設定する
		 */
		setPcEmojiList: function(aEmojiList) {
			if (this._datas > 1) {
				return;
			}
			this._datas = aEmojiList;
			for (var i = 0, l = this._datas.length; i < l; i++) {
				this._textMap[this._datas[i].pctxt] = this._datas[i];
				this._textMap[this._datas[i].pctxt].index = i;
				this._imageMap[this._datas[i].pcimg] = this._datas[i];
				this._imageMap[this._datas[i].pcimg].index = i;
				this._interimMap[this._datas[i].interim] = this._datas[i];
				this._interimMap[this._datas[i].interim].index = i;
			}
		}

	});
})(jQuery);

/**
 * 要素をスクロールするスライダー
 *
 * @example
 * $('#slider').hgSlider({
 * 	content:$('selector'),		//スクロールする要素
 * 	view:$('selector'),		//contentを内包しているoverflow=hiddenの要素
 * 	dragLimit:20,			//スライダーのドラッグ範囲(+-)
 * 	pressScrollInterval:20,		//上下ボタンプレス時のスクロール実行インターバル(MSEC)
 * 	pressScrollPix:4,		//上下ボタンプレス時のスクロールサイズ(pixel)
 * 	slideScrollPix:4,		//スライド時のスクロールサイズ(pixel)
 * 	slideScrollMaxInterval:200,	//スライド時のスクロール実行インターバル最大値
 * 	slideScrollMinInterval:1,	//スライド時のスクロール実行インターバル最小値
 * 	turbo:5				//最小、最大スライド時の追加スクロールサイズ(pixel)
 * });
 *
 * @function
 * @name jQuery.hgSlider
 * @param {Object}
 * @returns {}
 */

(function($,ns) {
    $.fn[ns] = function(options) {
        var element = this;
        var prms = $.extend({
		    move : '.movingArea',
		    up : '.arrwUp',
		    drag : '.face',
		    down : '.arrwDown',
			std : '.stdArea',
		    dragLimit : 20,
		    pressScrollInterval : 20,
		    pressScrollPix : 4,
		    slideScrollPix : 4,
		    slideScrollMaxInterval:200,
		    slideScrollMinInterval:5,
		    turbo:10
        }, options);

	var turboV = 0;
	var startY;
	var scrollTimer = null;
	var ppn = Math.floor(prms.dragLimit/10);
	var moveElm = $(prms.move,element);
	var bodyElm = $(document.body);

	var contentHeight = parseInt(prms.content.height());

//	prms.content.css({'position':'absolute','top':'0px', height:});
//	prms.content.css({'position':'absolute','top':'0px', height:'auto'});
	prms.content.css({'position':'absolute','top':'0px'});

	element.css({
		'height': prms.dragLimit * 2 + 77
		//,'padding': '0px'
		/*,'top':'0px'*/
	});
	$(prms.std,element).css('top',prms.dragLimit + 77/2)
	
	var view = prms.view;
	var viewHeight = parseInt(view.css('height'));

	if (viewHeight >= contentHeight) {
		prms.content.css('height', viewHeight);
		contentHeight = viewHeight;
	}

	var sine = function(t,b,c,d){
	    return -c * Math.cos(t/d *(Math.PI/2)) + c + b;
		//return (t==0) ? b : c * Math.pow(2, 10 *(t/d - 1)) + b - c * 0.001;
	}

	var _setEvent = function(){
	    //drag
	    $(prms.drag,element).mousedown(startDrag);
	    bodyElm.mouseup(stopDrag);
	    //press
	    $(prms.up,element).mousedown(pressUp);
	    $(prms.down,element).mousedown(pressDown);
	}

	var pressUp = function(e){
	    e.preventDefault();
	    startClickScroll(-prms.pressScrollPix);
	}

	var pressDown = function(e){
	    e.preventDefault();
	    startClickScroll(prms.pressScrollPix);
	}

	var startClickScroll = function(n){
	    _stopScroll();
	    var scPix = prms.pressScrollPix;
	    if(n < 0) scPix = -scPix;
	    scrollTimer = setInterval(function(){_scrollContent(scPix)},prms.pressScrollInterval);
	}

	var startDrag = function(e){
	    e.preventDefault();
	    startY = e.clientY;
	    //$(prms.drag,element).mousemove(onDrag);
	    bodyElm.mousemove(onDrag);
	}

	var onDrag = function(e){
	    e.preventDefault();
	    _slide(startY-e.clientY);
	}

	var _slide = function(y){
	    var currentSliderY = parseInt(moveElm.css('top'));
	    if(Math.abs(y) >= prms.dragLimit){
			var dn = -prms.dragLimit;
			//todo
			if(y < 0) dn = -dn;
		    moveElm.css('top',dn+'px');
	    }else{
			moveElm.css('top',-y+'px');
	    }
	    _startScroll();
	}

	var stopDrag = function(e){
	    _stopScroll();
	    //e.preventDefault();

	    bodyElm.unbind('mousemove',onDrag);
	    moveElm.animate({'top':'0px'},200,"easeOutElastic");
	}

	var _startScroll = function(n){

	    var m = parseInt(moveElm.css('top'));
	    _stopScroll();

	    //todo
	    var scPix = prms.slideScrollPix;
	    if(m < 0) scPix = -scPix;
	    if(Math.abs(m) >= prms.dragLimit){
			turboV = prms.turbo;
	    }else{
			turboV = 0;
	    }

	    _scrollContent(scPix);
	    var sn = Math.floor(sine(prms.dragLimit-Math.abs(m),prms.slideScrollMinInterval,prms.slideScrollMaxInterval,prms.dragLimit));
	    scrollTimer = setInterval(function(){_scrollContent(scPix)},sn);
	}

	var _stopScroll = function(){
	    turboV = 0;

	    if(scrollTimer){
			clearInterval(scrollTimer);
			scrollTimer = null;
	    }
	}

	var _scrollContent = function(n){
	    //todo
		//if(viewHeight >= contentHeight) return;
		//if(viewHeight >= contentHeight) prms.content.css('height',viewHeight);
		var pp = Math.floor(parseInt(moveElm.css('top'))/ppn);

	    var m = prms.pressScrollPix;
	    if(n < 0){
			m = -m;
			var turboN = -(turboV-pp);
	    }else{
			var turboN = turboV+pp;
	    }

	    var newHeight = parseInt(prms.content.css('top')) - (n + turboN);
		//console.log(newHeight)
	    if (newHeight >= 0) {
			newHeight = 0;
			_bounce(newHeight,40);
			_stopScroll();
		//prms.content.animate({'top':'-50px'},500,"easeOutBounce");
		//newHeight = 0;
		} else if (newHeight <= (viewHeight - contentHeight)) {
				newHeight = viewHeight - contentHeight;
				_bounce(newHeight,-40);
				_stopScroll();
			//newHeight = viewHeight - contentHeight;
			} else {
			
			prms.content.css('top',newHeight+'px');
			}
	}
	
	var bounceFlg = false;
	var _bounce = function(nh,b){
		if (bounceFlg == false) {
			//console.log(bounceFlg);
			bounceFlg = true;
			
			_doBounce(nh,b);
		}
	}
	
	var _doBounce = function(nh,b){
		prms.content.animate({'top':(nh+b)+'px'},200,"easeOutSine",function(){
			_returnBounce(nh,b)
		});
		//_endBounce();
	}
	
	var _returnBounce = function(nh,b){
		prms.content.animate({'top':nh+'px'},200,"easeOutSine",_endBounce);
		
	}
	
	var _endBounce = function(){
		bounceFlg = false;
	}

	_setEvent();

	return this;
    };
})($j,'hgSlider');


/**
 * rollOverImage
 *
 * jQuery
 */
hg.RollOverImage = function(opt){
    var options = this.opt = this._getOptionSet(arguments[0]);
    this._base = $j(options.id);

    if(!this._base) return;

    this.imgArr = $j("#"+this.opt.id+" ."+this.opt.imgCss);
    this._addEvent();
};

hg.RollOverImage.prototype = {
    _getOptionSet : function(argu) {
	var option = {
	    imgCss : "_rollOver",
	    imgOn : "_on"
	};
	if (typeof argu == "undefined") argu = new Object;
	for(var x in argu) option[x] = argu[x];
	return option;
    },
    _addEvent : function() {
	var _this = this;
	$j.each(this.imgArr,function(i,v){
	    $j(v).mouseover(function(){_this.over(this)});
	    $j(v).mouseout(function(){_this.out(this)});
	});
    },
    over : function(elm){
	var src = elm.src;
	var on = this.opt.imgOn;
	elm.src = src.replace(new RegExp('(^.+)(\..{3}$)'), "$1"+on+"$2");
    },
    out : function(elm){
	var src = elm.src;
	var on = this.opt.imgOn;
	elm.src = src.replace(new RegExp('(^.*)'+on+'(\..{3}$)'), "$1$2");
    }
}



hg.AddClassSelector = function(){
    this.hOption = this._getOpts(arguments[0]);
    this._addClass();
}

hg.AddClassSelector.prototype = {
    _getOpts : function(opt){
	var option = {
	    className : 'cellStyle'
	    ,selector : ''
	};
	if(typeof opt == 'undefined') opt = new Object;
	for(var v in opt) option[v] = opt[v];
	return option;
    },
    _addClass : function(){
	$j(this.hOption.selector).addClass(this.hOption.className);;
    }
}
