/**
 * ホイール画像の拡大表示
 *
 * var showWheelPhoto = new ShowWheelPhoto();
 * showWheelPhoto.show("PHOTONAME");
 */
function ShowWheelPhoto() {
    this.block_width = 300;
    this.block_height = 300;

    function getWindowWidth() {
	return (self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0);
    }
    function getWindowHeight() {
	return (self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0);
    }
    function getScrollLeft() {
	return (self.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0);
    }
    function getScrollTop() {
	return (self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0);
    }

    /**
     * 画像ディレクトリのURL
     * @var string
     */
    this.photo_dir_url = "/ec/img_w/";

    /**
     * イメージ要素を表示する要素
     * @var string
     */
    /*
    this.show_element  = null;
    if (document.getElementById) {
	this.show_element = document.getElementById('ShowWheelPhoto');
    } else if (document.all) {
	this.show_element = document.all['ShowWheelPhoto'];
    }
    */
    this.show_element_block  = null;
    if (document.getElementById) {
	this.show_element_block = document.getElementById('ShowWheelPhotoBlock');
    } else if (document.all) {
	this.show_element_block = document.all['ShowWheelPhotoBlock'];
    }
    this.show_element_image  = null;
    if (document.getElementById) {
	this.show_element_image = document.getElementById('ShowWheelPhotoImage');
    } else if (document.all) {
	this.show_element_image = document.all['ShowWheelPhotoImage'];
    }
    this.show_element_title  = null;
    if (document.getElementById) {
	this.show_element_title = document.getElementById('ShowWheelPhotoTitle');
    } else if (document.all) {
	this.show_element_title = document.all['ShowWheelPhotoTitle'];
    }

    //this.show_element.style.zIndex = -1;
    //this.show_element.style.position = "absolute";
    if (document.all) {
    } else {
        //this.show_element.style.position = "fixed";
        //this.show_element_block.style.position = "fixed";
    }

    /**
     * void show(element e)
     *
     * image 要素e を元にホイール画像を表示する
     * 画像のURL とタイトルははe のsrc 属性とalt 属性を元に決定
     *
     *
     * @var string photoname
     */
    this.show = function(e) {
	//if (!this.show_element) return;
	if (!this.show_element_block) return;
	if (!this.show_element_image) return;
	//scrollbars.visible = false;
	//photoname = photoname.replace(/_small\.jpg$/, ".jpg");
	//var url = this.photo_dir_url + photoname;
	var url = e.src.replace(/_small\.jpg$/, ".jpg");
	//alert(url);
	this.show_element_title.innerHTML = e.alt;
        this.show_element_image.src = url;
        this.show_element_image.alt = e.alt;
	//if (document.all) {
    	var block_left = ((getWindowWidth()-this.block_width)/2);
    	var block_top = ((getWindowHeight()-this.block_height)/2);
	//alert("left: "+block_left+"; top: "+block_top);
	var scroll_left = getScrollLeft();
	var scroll_top  = getScrollTop();
	//alert("left: "+scroll_left+"; top: "+scroll_top);

	this.show_element_block.style.left = (block_left+scroll_left)+"px";
	//this.show_element.style.top = scroll_top+"px";
	this.show_element_block.style.top = (block_top+scroll_top)+"px";

	//this.show_element.style.zIndex = 9997;
	this.show_element_block.style.zIndex = 9998;
	//this.show_element.style.display = "block";
	this.show_element_block.style.display = "block";
	if (document.all) {
	    //document.body.style.overflow = 'hidden';
	}
        this.show_element_image.style.visibility = "visible";
    };
    this.hide = function() {
	if (this.show_element_block.style.display !== 'block') {
	    return;
	}
        this.show_element_block.style.display = "none";
        //this.show_element.style.display = "none";
	//this.show_element.style.zIndex = -1;
	this.show_element_block.style.zIndex = -1;
        this.show_element_image.style.visibility = "hidden";
	if (document.all) {
	    //document.body.style.overflow = 'auto';
	}
	//scrollbars.visible = true;
    }
}
