/* vim: set tabstop=2 shiftwidth=2 foldmethod=marker: */
/**
 * 
 * Lazurite公開画面 基本スクリプト
 *
 * @author     Tsukasa Koizumi <tsukasa@virtuawave.jp>
 * @copyright  2005-2006 VirtuaWave Inc.
 * @version    CVS: $Id: common.js,v 1.14.2.2 2007/03/19 07:24:57 shogo Exp $
 *
 */

vw.url      = '';
vw.script   = '';

/* 初期化
------------------------------------------------------------------------*/
vw.init = function(url, script, secure)
{
	initLightbox();
	this.url    = url;
	this.script = url + script;
	vw.swapImage.init();
	vw.lbCtrl.init();
}

/* イメージの自動切り替え
------------------------------------------------------------------------*/
vw.swapImage = {
	/** 初期化 */
	init: function()
	{
		document.getElementsByClassName('swapImage', document.body, 'a').each(function(e){
			Event.observe(e, 'mouseover', vw.swapImage.swap.bind(e), false);
		});
	},
	swap: function()
	{
		var target  = $('swapImageTarget');
		target.href = this.href;
		target.replaceChild(this.firstChild.cloneNode(true), target.firstChild);
		if (vw.userAgent.msie) {
			
		}
	}
}

/* LightBox風Q&A
------------------------------------------------------------------------*/
vw.lbCtrl = {
	/** 初期化 */
	init: function()
	{
		vw.overlay = $('overlay2');
		vw.overlay.hide();
		
		// イベント設定
		var lbs = document.getElementsByClassName('vwlb');
		if (lbs.length) {
			var i = 0;
			lbs.each(function(e){ Element.hide(e); });
			$A(document.getElementsByTagName('a')).each(function(a){
				if (a.rel == 'vwlb') {
					a._vwlb = lbs[i++];
					Event.observe(a, 'click', vw.lbCtrl.open.bindAsEventListener(a), false);
				}
			});
		}
	},
	/** アクセス開始 */
	open: function(event)
	{
		Event.stop(event);
		var size    = [420, 310];
		var b       = vw.body();
		var height  = $A([b.scrollHeight, b.clientHeight, window.innerHeight]).max();
		vw.lightbox = $(this._vwlb);
		
		// オーバーレイ処理
		vw.overlay.setStyle({height: height + 'px', display: 'block', zIndex: 90});
		
		// レイヤー表示
		vw.lightbox.setStyle({
			position:  'absolute',
			left:      Math.floor((b.clientWidth - size[0]) / 2 + b.scrollLeft) + 'px',
			top:       Math.floor((b.clientHeight - size[1]) / 2 + b.scrollTop) + 'px',
			width:     size[0] + 'px',
			height:    size[1] + 'px',
			display:   'block',
			overflowY: 'scroll',
			zIndex:    100
			});
		
		return null;
	},
	/** 隠す */
	close: function()
	{
		vw.lightbox.hide();
		vw.overlay.hide();
		return false;
	}
};
