function ITHWaveBoard()
{

this.brd_cfgs = {
	nodoctype:false,
	ticktime1:150,
	ticktime2:15,
	ltimer:0,
	visible : false,
	wwidth : 450,
	wminwidth: 290,
	ohash: ''
};

this.site_infos = {
	site_url : 'http://ithwave.com'
};

this.iframe_src = this.site_infos['site_url']+'/twboard.php?ssrl=102';
this.img_path = this.site_infos['site_url']+'/custom/2010visit/images/';

this.init_onload = function ()
{
	if(this.gel('wv_wcont_brd') && this.gel('wv_cont_brd')) return false;

	if(navigator.userAgent.indexOf('MSIE') >= 0)
	{
		if((navigator.userAgent.indexOf('MSIE 6') >= 0) || (document.firstChild.nodeValue == null))
		{
			this.brd_cfgs['nodoctype'] = true;
		}
	}

	// append css
	var cssText = "";
	if (this.brd_cfgs['nodoctype'])
	{
		cssText += " * { margin : 0; }";
	 	cssText += " html, body { height: 100%; }";
	}

	cssText += " .wv_passive_container { position:"+(this.brd_cfgs['nodoctype']? "absolute" : "fixed")+"; top:35%; left:0; bottom:0; margin:0; padding:0; cursor:pointer; z-index:2000000000; background:none; line-height:normal; }";
	//cssText += " .wv_passive_container_sub { position:relative; top:35%; }";
	cssText += " #wv_passive_twitter { position:absolute; top: 19px; left:15px; width:21px; height:127px; z-index:1; background:none; }";
	cssText += " .wv_passive_container.wv_open #wv_passive_twitter { left:8px; }";
	cssText += " #wv_passive_large { position:absolute; top:0px; left:0px; width:39px; height:157px; margin:0; padding:0; border: none; background:transparent url("+this.img_path+"tab.gif) 0px 0px no-repeat; opacity:.95; }";
	cssText += " #wv_passive_large.wv_open { background-position: 0px -157px !important; }";
	cssText += " .wv_passive_container.wv_open #wv_passive_large { background-position: 0px -314px !important; }";
	cssText += " .wv_passive_container.wv_open #wv_passive_large.wv_open { background-position: 0px -471px !important; }";

	if (this.brd_cfgs['nodoctype'])
	{
		cssText += " .wv_overlay { width: 450px; min-width:289px; z-index: 2000000000; background:#260300 url("+this.img_path+"bg_wrap.jpg) repeat-x; border-right:1px solid #260300; position: absolute; top: 0px; bottom:0px; left:-450px; padding:0px; margin:0px; height: expression(document.documentElement.clientHeight); }";
		cssText += " .wv_content { z-index: 2000000000; margin: 0px; padding: 0px; position: absolute; width: 400px; scrolling: no; min-width:269px; top: 0px; bottom:0px left:-440px; height: expression(document.documentElement.clientHeight - 15); border:none; }";
	}
	else 
	{
		cssText += " .wv_overlay { width: 450px; min-width:289px; z-index: 2000000000; background:#260300 url("+this.img_path+"bg_wrap.jpg) repeat-x; border-right:1px solid #260300; position: fixed; top: 0px; left:-450px; padding:0px; margin:0px; height: 100%; }";
		cssText += " .wv_content { z-index: 2000000000; margin: 0px; padding: 0px; position: fixed; width: 400px; scrolling: no; min-width:269px; top: 0px; left:-440px; height: 98%; border:none; }";
	}

	//cssText += " #wv_close { display:none; position:absolute; top:0; left:0; }";
	//cssText += " .wv_open #wv_close { display:inline; }";
	cssText += " #wv_waitload { display:none; position:absolute; top:39px; left:11px; }";
	cssText += " .wv_n_load { opacity:0.6; filter2: alpha(opacity=60); }";
	cssText += " .wv_n_load #wv_waitload { display:inline; }";
	cssText += " a:focus { outline: none; }";

	var d = document;

	var styleText = d.createTextNode(cssText);
	var styleNode = d.createElement("style");
	styleNode.type = 'text/css';
	if(styleNode.styleSheet)
		styleNode.styleSheet.cssText = styleText.nodeValue;
	else
		styleNode.appendChild(styleText);
	d.getElementsByTagName("head")[0].appendChild(styleNode);

	// wv_wcont_brd
	if(!this.gel('wv_wcont_brd'))
	{
		var obj = d.createElement('div');
		var html = '';
		html += '<div id="wv_wcont_brd" class="wv_passive_container">';
		//html += '<img id="wv_close" src="'+this.img_path+'btn_close.jpg" onclick="return ith_wv_brd.icon_click()" />';
		//html += '<div class="wv_passive_container_sub">';
		html += '<div onclick="return ith_wv_brd.icon_click()" onmouseover="ith_wv_brd.icon_over(\'large\')" onmouseout="ith_wv_brd.icon_out(\'large\')">';
		html += '<div id="wv_passive_twitter"></div><div id="wv_passive_large"></div>';
		html += '</div>';
		html += '<img id="wv_waitload" src="'+this.img_path+'ajax-loader.gif" />';
		//html += '</div>';
		html += '</div>';

		obj.innerHTML = html;
		obj.id = 'ITH_icon';
		obj.style.display = 'none';
		this.add_el(obj);

		d.body.replaceChild(this.gel('wv_wcont_brd'), this.gel('ITH_icon'));
	}

	// wv_cont_brd
	if(!this.gel('wv_cont_brd'))
	{
		var obj = document.createElement('iframe');
		obj.id = 'wv_cont_brd';
		obj.name = 'wv_cont_brd';
		obj.className = 'wv_content';
		obj.style.left = '-'+this.brd_cfgs['wwidth']+'px';
		obj.style.display = 'none';
		obj.scrolling = 'no';
		obj.frameBorder=0;
		obj.setAttribute("allowTransparency","true");
		this.add_el(obj);

		// important: after add_el
		// obj.src = this.iframe_src;
	}

	if(document.location.hash.substring(1,7) == 'wvshow')
	{
		this.icon_click();
	}

	this.set_timer(1);
};

this.remove_px = function (str)
{
	var pos = str.indexOf('px');
	if (pos > 0)
		return str.substring(0, pos);
	else return str;
}

this.get_left_pos = function (el)
{
	return parseInt(this.remove_px(el.style.left));
}

this.set_left_pos = function (el, left)
{
	el.style.left = left;
};

this.change_state = function (state)
{
	if(this.brd_cfgs['visible'] == state) return;

	this.brd_cfgs['visible'] = state;

	// 빠른 check
	// this.set_timer(2);

	var pshift = (state ? this.brd_cfgs['wwidth'] : -this.brd_cfgs['wwidth']);
	this.change_class('wv_wcont_brd', 'wv_open', (state ? true : false));
	document.location.hash = this.brd_cfgs['visible'] ? '#wvshow' : '#wvhide';

	if (this.brd_cfgs['visible']) this.refresh();

	this.cur_left_pos = {};
	var ael = ['wv_cont_brd', 'wv_over_brd', 'wv_wcont_brd'];
	for(var i=0;i<ael.length;i++)
	{
		if(this.gel(ael[i]))
		{
			el = ael[i];

			if(typeof this.cur_left_pos[el] == 'undefined')
			{
				this.cur_left_pos[el] = this.get_left_pos(this.gel(el));
				if(isNaN(this.cur_left_pos[el])) this.cur_left_pos[el] = 0;
			}
			this.set_left_pos(this.gel(el), this.cur_left_pos[el] + pshift + 'px');
		}
	}
}

this.check_hash = function()
{	
	var cmdpos = document.location.hash.indexOf('wvcmd_');
	if(cmdpos >= 0)
	{
		var cmd = document.location.hash.substring(cmdpos+6);
		document.location.hash = this.brd_cfgs['ohash'] ? this.brd_cfgs['ohash'] : '#';

		var psplit = cmd.split('_');
		var cmd = psplit[0];

		if(cmd.indexOf('brd') == 0) cmd = cmd.substring(3);

		switch(cmd)
		{
			case 'ready':
				this.change_class('wv_wcont_brd', 'wv_n_load', false);
				this.change_state(true);
				this.gel('wv_cont_brd').style.display = '';
				break;

			case 'close':
				this.change_state(false);
				break;

		}
	}

	if(this.brd_cfgs['ohash'] != document.location.hash)
		this.brd_cfgs['ohash'] = document.location.hash;
};

this.refresh = function()
{	
	this.gel('wv_cont_brd').src = this.iframe_src;
};

this.icon_click = function ()
{
	this.set_board_pos();

	if(!this.gel('wv_over_brd'))
	{
		this.change_class('wv_wcont_brd', 'wv_n_load', true);

		var obj = document.createElement('div');
		obj.id = 'wv_over_brd';
		obj.className = 'wv_overlay';
		obj.style.left = '-'+this.brd_cfgs['wwidth']+'px';
		this.add_el(obj);

		if(this.gel('wv_cont_brd'))
		{
			if(document.location.hash.indexOf('wvcmd_brdready') < 0)
			{
				document.location.hash = document.location.hash+"#wvcmd_brdready";
			}
			// this.gel(this.wname('wv_cont')).src = this.if_src('');
		}

		this.set_board_pos()
	}
	else
	{
		ith_wv_brd.change_state(!this.brd_cfgs['visible']);
	}

	return false;
};

this.gel = function (elid)
{
	return document.getElementById(elid);
};

this.icon_over = function(tp)
{
	this.change_class('wv_passive_'+tp, 'wv_open', true);
};

this.icon_out = function(tp)
{
	this.change_class('wv_passive_'+tp, 'wv_open', false);
};

this.set_timer = function (tp) 
{
	if(this.brd_cfgs['ltimer'])
		window.clearInterval(this.brd_cfgs['ltimer']);

	this.brd_cfgs['ltimer'] = null;
	this.brd_cfgs['ltimer'] = window.setInterval('ith_wv_brd.check_hash()', this.brd_cfgs['ticktime'+tp]);
};

this.set_board_pos = function () 
{
	wd = Math.min(parseInt(document.body.clientWidth*0.9), this.brd_cfgs['wwidth']);
	wd = Math.max(ith_wv_brd.brd_cfgs['wminwidth'], wd);
	ith_wv_brd.brd_cfgs['wwidth'] = wd;

	var e1 = ith_wv_brd.gel('wv_over_brd');
	var e2 = ith_wv_brd.gel('wv_cont_brd');
	if(e1 && e2)
	{
		e1.style.width = (wd - 1) + 'px';
		e2.style.width = (wd - 20)+ 'px';
		// e2.style.width = (wd - 1) + 'px';

		var l1 = this.remove_px(e1.style.left);
		var l2 = this.remove_px(e2.style.left);

		if(parseInt(l1)<0) e1.style.left = '-'+(wd)+'px';
		if(parseInt(l2)<0) e2.style.left = '-'+(wd-10)+'px';
		// if(parseInt(l2)<0) e2.style.left = '-'+(wd)+'px';
	}
};


this.change_class = function (elid, cname, onoff) 
{
	var el = this.gel(elid);
	if(onoff && (onoff!=0))
	{
		if(el.className.indexOf(cname)<0)
			el.className += ' '+cname;
	}
	else
	{
		for(var cn='';cn!=el.className;)
		{
			cn = el.className;
			el.className = el.className.replace(cname,'');
		}
		el.className = el.className.replace(/ +/g, ' ');
	}
};

this.add_el = function (obj)
{
	var b = document.body;
	try {
		if(b.childNodes.length > 0)
			b.insertBefore(obj, b.childNodes[0]);
		else
			b.appendChild(obj);
	}catch(e) {
		return false;
	}

	return true;
};


this.add_event = function(ev, func, wnd)
{
	var scope = wnd ? window : document;
	if(typeof scope.addEventListener != 'undefined')
	{
		scope.addEventListener(ev, func, false);
	}
	else
	{
		if(typeof scope.attachEvent != 'undefined')
			scope.attachEvent('on'+ev, func);
		else
			return false;
	}

	return true;
};

this.add_onload = function(fnc)
{
	if(!this.add_event( 'load', fnc, true ))
	{
		if ( window.onload != null ) 
		{
			var oldOnload = window.onload;
			window.onload = function ( e ) 
			{
				oldOnload(e);
				window[fnc]();
			};
		}
		else
			window.onload = fnc;
	}
};

}

if(typeof ith_wv_brd == 'undefined')
{
	var ith_wv_brd = new ITHWaveBoard();

	if(document.body)
	{
		ith_wv_brd.init_onload();
	}
	ith_wv_brd.add_onload(function(){ith_wv_brd.init_onload();});
}

