    /** 
    *    FullScreenMode for DOM objects
    *    
    *    Takes a dom object to magnify to full screen and shrink back in place.
    *    copyright 2008 Weisswo.com
    *
    *   Usage (insert script after 'targetElementId'):
    *     var w = new WeissWoFullScreen('targetElementId',30,153);
    *     w.setFullScreenContainer('containerElementId');
    *     w.setFullScreenButtonImage('Imagetext', 'ImageUrl'); ==> only Imagetext is necessary parameter
    *     w.setCloseButtonImage('Imagetext', 'ImageUrl'); ==> only Imagetext is necessary parameter
    *     w.activateFullScreen('Vollbild'); // optional: add fullscreen button to iframe
    *
    *   Other Methods:
    *     WeissWoFullScreen.prototype.singleton.goFullscreen();
    *     WeissWoFullScreen.prototype.singleton.hideFullScreen();
    */
    
    /** 
    *    Constructor
    */   
function WeissWoFullScreen(elementId, subWidth, subHeight, onGoFull, onHideFull)
    {
        // set singleton
        WeissWoFullScreen.prototype.singleton = this;
        
        // save instance variables
        this._subWidth = subWidth || 0;
        this._subHeight = subHeight || 0;
        this._fullScreenSubWidth = 0;
        this._fullScreenSubHeight = 0;
        this._fullscreenObject = document.getElementById(elementId);
        this._fullscreenObject._originalWidth = this._fullscreenObject.style.width;
        this._fullscreenObject._originalHeight = this._fullscreenObject.style.height;
        this._state = 0; // normal;
        
        // _fullscreenContainer = div around the full screen target iframe + the full screen button
        this._fullscreenContainer = this._fullscreenObject.parentNode; //= document.getElementsByTagName('body')[0];
        this._fullscreenButtonUrl = 'http://pinpoint.weisswo.eu/lib/icons/goFull.png';
        this._fullscreenButtonWidth = 130;
        this._fullscreenButtonHeight = 35;
        this._fullscreenButtonText = '&nbsp;Full view';
        
        this.transparentUrl = 'http://pinpoint.weisswo.eu/lib/icons/transparent.gif';
        
        this._closeButtonUrl = 'http://pinpoint.weisswo.eu/lib/icons/transparent.png';
        this._closeButtonUrl = 'http://pinpoint.weisswo.eu/lib/icons/closeFull.png';
        this._closeButtonWidth = this._fullscreenButtonWidth;
        this._closeButtonHeight = this._fullscreenButtonHeight;
        this._closeButtonText = '&nbsp;&nbsp;Normal';
        this._ie6 = navigator.userAgent.search(new RegExp("MSIE 6"))>0;
        
        this._onGoFull = onGoFull || null;
        this._onHideFull = onHideFull || null;
        
        // organize setSize
        window.onload = function () { WeissWoFullScreen.prototype.singleton._setSize(1); };
        window.onresize = function () { WeissWoFullScreen.prototype.singleton._setSize(1); };
        this._setSize(1);
    };
    
    /** 
    *    Sets individual fullscreen button for customer (overwrite defaults)
    */
WeissWoFullScreen.prototype.setFullScreenMargins = function (left, top)
    {
        this._fullScreenSubWidth = left;
        this._fullScreenSubHeight = top;
    };
    
    /** 
    *    Sets individual fullscreen button for customer (overwrite defaults)
    */
WeissWoFullScreen.prototype.setButtonTexts = function (fullscreenButtonText,normalButtonText)
    {
        this._fullscreenButtonText = fullscreenButtonText;
        this._closeButtonText = normalButtonText;
    };
    
    /** 
    *    Sets individual fullscreen button for customer (overwrite defaults)
    */
WeissWoFullScreen.prototype.setFullScreenButtonImage = function (fullscreenButtonUrl, fullscreenButtonWidth, fullscreenButtonHeight)
    {
        this._fullscreenButtonUrl = fullscreenButtonUrl;
        this._fullscreenButtonWidth = fullscreenButtonWidth;
        this._fullscreenButtonHeight = fullscreenButtonHeight;
    };
    
    /** 
    *    Sets individual close button for customer (overwrite defaults)
    */
WeissWoFullScreen.prototype.setCloseButtonImage = function (closeButtonUrl, closeButtonWidth, closeButtonHeight)    
    {
        this._closeButtonUrl = closeButtonUrl;
        this._closeButtonWidth = closeButtonWidth;
        this._closeButtonHeight = closeButtonHeight;
    };
    
    /** 
    *    Adds a button to the fullscreen object to activate full screen mode. @TODO Cosider renaming: showFullScreenButton()
    */
WeissWoFullScreen.prototype.activateFullScreen = function(activateButtonId,toggle,pngFixOff)
    {		
        this._fullscreenContainer.style.position = "relative"; // set relative position on container div
        
        if(activateButtonId)
        {
            var x = document.getElementById(activateButtonId);
            if(toggle)
                x.onclick = function () { WeissWoFullScreen.prototype.singleton.toggleFullScreen(); };
            else
                x.onclick = function () { WeissWoFullScreen.prototype.singleton.goFullScreen(); };
        }
        else
        {
            // create fullscreen button
            var l = document.createElement('a');
            l.setAttribute('href','#');
            l.onclick = function () { WeissWoFullScreen.prototype.singleton.goFullScreen(); };
            
            // create fullscreen image
            var c = document.createElement('img');
            c.style.width = this._fullscreenButtonWidth+'px';
            c.style.height = this._fullscreenButtonHeight+'px';
            if(this._ie6 && !pngFixOff)
            {
                var s = document.createElement('span');
                s.style.width = this._fullscreenButtonWidth;
                s.style.height = this._fullscreenButtonHeight;
                s.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this._fullscreenButtonUrl + "',sizingMethod='scale')";
                c.src = this.transparentUrl;
                c.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this._fullscreenButtonUrl + "',sizingMethod='scale')";
            }
            else
                c.src = this._fullscreenButtonUrl;
            
            l.appendChild(c);
            
            // create fullscreen text
            var d = document.createElement('div');
            d.innerHTML = this._fullscreenButtonText;
            l.appendChild(d);
            
            // create div container
            this._fullscreenButtonDiv = document.createElement('div');
            this._fullscreenButtonDiv.id = 'weissWoFullScreenButton';
            this._fullscreenButtonDiv.appendChild(l);
            
            //add to body
            this._fullscreenContainer.appendChild(this._fullscreenButtonDiv);
        }
        
        // prepare CLOSE button
        // create close link
        l = document.createElement('a');
        l.setAttribute('href','#');
        l.onclick = function () { WeissWoFullScreen.prototype.singleton.hideFullScreen(); };
        
        // create close image
        var b = document.createElement('img');
        b.style.width = this._closeButtonWidth+'px';
        b.style.height = this._closeButtonHeight+'px';
        if(this._ie6 && !pngFixOff)
        {
            b.src = this.transparentUrl;
            b.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this._closeButtonUrl + "',sizingMethod='scale')";
        }
        else
            b.src = this._closeButtonUrl;
        
        l.appendChild(b);
        
        // create close text
        var t = document.createElement('div');
        t.innerHTML = this._closeButtonText;
        l.appendChild(t);
        
        // create the close link div
        this._closeContainer = document.createElement('div');
        this._closeContainer.id = 'weissWoCloseButton';
        this._closeContainer.style.zIndex = '150';
        this._closeContainer.appendChild(l);
    };

WeissWoFullScreen.prototype.toggleFullScreen = function ()
    {
        if(this._state == 1)
            this.hideFullScreen();
        else
            this.goFullScreen();
    };
    
    /** 
    *    Expands iframe to full screen and give it a z-index 
    */
WeissWoFullScreen.prototype.goFullScreen = function ()
    {
        if(this._onGoFull) this._onGoFull.call(this);
        
        this._fullscreenContainer.style.position = ""; // clear relative position on container div
        
        // assign the styles to the iframe
        this._fullscreenObject.style.position = 'absolute';
        this._fullscreenObject.style.left = this._fullScreenSubWidth+'px';
        this._fullscreenObject.style.top = this._fullScreenSubHeight+'px';
        this._fullscreenObject.style.zIndex = '100';
        
        // deactivate scrollbars
        document.getElementsByTagName('html')[0].style.overflowX = 'hidden';
        document.getElementsByTagName('html')[0].style.overflowY = 'hidden';
        
        // add close link to body
        this._closeContainer.style.display = '';
        this._fullscreenObject.parentNode.appendChild(this._closeContainer);
        
        // setSize
        this._state = 1;
        this._setSize(1);
    };
    
    /** 
    *    Shrinks iframe to original size back
    */
WeissWoFullScreen.prototype.hideFullScreen = function() 
    {        
        if(this._onHideFull) this._onHideFull.call(this);
        
        this._fullscreenContainer.style.position = "relative"; // set relative position on container div
        
        // delete fullscreen objects
        this._closeContainer.style.display = 'none';
        
        // set iframe to old container and settings
        this._fullscreenObject.style.position = '';
        this._fullscreenObject.style.height = this._fullscreenObject._originalHeight;
        this._fullscreenObject.style.width = this._fullscreenObject._originalWidth;
        this._fullscreenObject.style.border = 'none';
        this._fullscreenObject.style.display = '';
        this._fullscreenObject.style.overflow = ''; // CHANGED FROM 'hidden' TO '' TO AVOID SCROLLBAR BUG ON IFRAME
        
        // reactivate scrollbars
        document.getElementsByTagName('html')[0].style.overflowX = '';
        document.getElementsByTagName('html')[0].style.overflowY = '';
        
        // set old onresize
        this._state = 0;
        this._setSize(1);
    };
    
    /** 
    *    Calculates site size parameters 
    *    @return object including pageWidth,pageHeight,windowWidth,windowHeight,scrollLeft and scrollTop
    */
WeissWoFullScreen.prototype._setSize = function(iEfIx) 
    {
        var h,w;
        
        // do not set size on normal view if no subs where defined
        if((this._subWidth == 0 && this._subHeight == 0) && this._state != 1)
            return;

        if( typeof( window.innerWidth ) == 'number' ) 
        {
            //Non-IE
            w = window.innerWidth;
            h = window.innerHeight;
            
        } 
        else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
        {
            //IE 6+ in 'standards compliant mode'
            w = document.documentElement.clientWidth;
            h = document.documentElement.clientHeight;
        }
        else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
        {
            //IE 4 compatible
            w = document.body.clientWidth;
            h = document.body.clientHeight;
        }
        
        if(this._state == 0)
        {
            w -= this._subWidth;
            h -= this._subHeight;
        }
        else if(this._state == 1)
        {
            w -= this._fullScreenSubWidth;
            h -= this._fullScreenSubHeight;
        }
        
        if(iEfIx<0 || this._fullscreenObject.style.width == w+'px' && this._fullscreenObject.style.height == h+'px') // any change? / w&h are sometimes empty
            return;
        
        this._fullscreenObject.style.width = (w-iEfIx)+'px';
        this._fullscreenObject.style.height = (h-iEfIx)+'px';
        this._fullscreenObject.scrollIntoView();
        
        // recheck for IE6/7 in transitional mode
        var me=this;
        setTimeout(function(){me._setSize(iEfIx-1)},1000); // 1000 must be same as in utils.js (!) fails if reduced!
    };
