/*---------------------------------------------------------------------*
| fullimage.js - Loads a full resolution image in a div-layer.
|
| Copyright by:
| Tobias Knab, open New Media GmbH
| Koblenz, Germany
*---------------------------------------------------------------------*/

function FullImage( center )
{
    /* center values: both, y, x, none */
    this.center = center;
    
    this.image = new Image();
    
    this.loadImage = new Image();
    this.loadImage.src = '../images/load.gif';
}

FullImage.prototype.load = function()
{
	if ( this.image.width <= 0 ) {
        setTimeout('fi.load();', 100);
    } else {
        this.change();
    }
}

FullImage.prototype.show = function( imageUrl )
{
    var div = document.getElementById('fullimage');
    
    if ( this.image.src != '../images/load.gif' ) {
        this.image = this.loadImage;
    	this.change();
    }
    
    div.className = 'show';
    
    this.image = new Image();
    this.image.src = imageUrl;
    this.load();
}

FullImage.prototype.change = function()
{
    var div = document.getElementById('fullimage');
    
    if ( this.center == 'y' || this.center == 'both' ) {
        div.style.top = this.yTopToCenter(this.image.height) + 'px';
    }
    if ( this.center == 'x' || this.center == 'both' ) {
        div.style.left = this.xLeftToCenter(this.image.width) + 'px';
        
    } else if ( this.center != 'y' ) {
        div.style.top = (this.yOffset() + 50) + 'px';
    }
    div.style.width = this.image.width + 'px';
    div.firstChild.nextSibling.src = this.image.src;
}

FullImage.prototype.hide = function()
{
    var div = document.getElementById('fullimage');
    
	div.className = '';
	
	this.image = this.loadImage;
	this.change();
}

FullImage.prototype.yOffset = function()
{
    var yOffset = 0;
    if ( window.innerHeight ) {
        yOffset = window.pageYOffset;
    } else if ( document.documentElement &&
document.documentElement.scrollTop ) {
        yOffset = document.documentElement.scrollTop;
    } else if ( document.body ) {
        yOffset = document.body.scrollTop;
    }
    return yOffset;
}

FullImage.prototype.xOffset = function()
{
    var xOffset = 0;
    if ( window.innerHeight ) {
        xOffset = window.pageXOffset;
    } else if ( document.documentElement &&
document.documentElement.scrollLeft ) {
        xOffset = document.documentElement.scrollLeft;
    } else if ( document.body ) {
        xOffset = document.body.scrollLeft;
    }
    return xOffset;
}

FullImage.prototype.iHeight = function()
{
    var iHeight = 0;
    if ( window.innerHeight ) {
        iHeight = window.innerHeight;
    } else if ( document.documentElement &&
document.documentElement.clientHeight ) {
        iHeight = parseInt(document.documentElement.clientHeight);
    } else if ( document.body ) {
        iHeight = parseInt(document.body.clientHeight);
    }
    return iHeight;
}

FullImage.prototype.iWidth = function()
{
    var iWidth = 0;
    if ( window.innerHeight ) {
        iWidth = window.innerWidth;
    } else if ( document.documentElement &&
document.documentElement.clientWidth ) {
        iWidth = parseInt(document.documentElement.clientWidth);
    } else if ( document.body ) {
        iWidth = parseInt(document.body.clientWidth);
    }
    return iWidth;
}

FullImage.prototype.yTopToCenter = function( height )
{
    var iHeight = this.iHeight();
    if ( (height + 20) > iHeight ) {
        return this.yOffset() + 10;
    } else {
        return parseInt(this.yOffset() + (iHeight - height) / 2);
    }
}

FullImage.prototype.xLeftToCenter = function( width )
{
    var iWidth = this.iWidth();
    if ( (width + 20) > iWidth ) {
        return this.xOffset() + 10;
    } else {
        return parseInt(this.xOffset() + (iWidth - width) / 2);
    }
}

fi = new FullImage('both');

