var LightsOut = {
    overlayId   : 'lights_out_overlay',
    overlay     : '',
    timer       : '',
    startValue  : 1,
    fadeInFunc  : "fadeIn()",
    fadeOutFunc : 'fadeOut()',
    
    getWinSizeAndScroll : function ()
    {
		var intWidth   = document.body.offsetWidth;
		var intHeight  = (typeof window.innerHeight != "undefined")? window.innerHeight : (document.documentElement && document.documentElement.clientHeight > 0)? document.documentElement.clientHeight : document.body.clientHeight;		
		var intXScroll = (typeof window.pageXOffset != "undefined")? window.pageXOffset : document.body.scrollLeft;		
		var intYScroll = (typeof window.window.pageYOffset != "undefined")? window.window.pageYOffset : (document.documentElement && document.documentElement.scrollTop > 0)? document.documentElement.scrollTop : document.body.scrollTop;
		
		return [intWidth, intHeight, intXScroll, intYScroll];
	},
	
	setOverlaySize : function ()
	{
		if(this.overlay)
		{
			var oDimBackground      = this.overlay.style;
        	var arrWinSizeAndScroll = this.getWinSizeAndScroll();
        	oDimBackground.width    = arrWinSizeAndScroll[0] + arrWinSizeAndScroll[2] + "px";
        	oDimBackground.height   = arrWinSizeAndScroll[1] + arrWinSizeAndScroll[3] + "px";
		}
	},
	
	startFade : function (direction)
	{
	    if(direction == 'fadeIn')
	    {
            this.timer = setTimeout('LightsOut.fadeIn()', 70);	        
	    }
	    else
	    {
            this.timer = setTimeout('LightsOut.fadeOut()', 70);   
	    }
	},
	
	fadeIn : function ()
	{
        if (navigator.appName.indexOf("Microsoft") != -1)
        {
            this.overlay.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='http://www.korta.is/img/fade/fade_" + this.startValue + ".png')";
        }
        else
        {
            this.overlay.style.backgroundImage = 'url(http://www.korta.is/img/fade/fade_' + this.startValue + '.png)';
        }
                    
	    if(this.startValue == 1)
	    {
	        //alert('fadeStopped');
            this.overlay.style.display = 'none';
	        this.stopFade();
	    }
	    else
	    {
            this.startValue--;
            this.timer = setTimeout('LightsOut.fadeIn()', 70);
	    }
	},
	
	fadeOut : function ()
	{
        if (navigator.appName.indexOf("Microsoft") != -1)
        {
            this.overlay.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='http://www.korta.is/img/fade/fade_" + this.startValue + ".png')";
        }
        else
        {
            this.overlay.style.backgroundImage = 'url(http://www.korta.is/img/fade/fade_' + this.startValue + '.png)';
        }

            
	    if(this.startValue == 9)
	    {
	        //alert('fadeStopped');
	        this.stopFade();
	    }
	    else
	    {
            this.startValue++;
            this.timer = setTimeout('LightsOut.fadeOut()', 70);
	    }	    
	},
	
	stopFade : function ()
	{
	    clearTimeout(this.timer);
	    //document.getElementById('lightBulb').style.visibility = '';
	},
	
	setFocus : function ()
	{
	  //  document.getElementById('lightBulb').style.visibility = 'hidden';
	    this.overlay = document.getElementById(this.overlayId);
	    
	    this.setOverlaySize();
	    
	    if(this.overlay.style.display == 'block')
	    {	        
            this.startFade('fadeIn');
            this.lightsOn();
        }
	    else
	    {
            this.overlay.style.display = 'block';    
            this.startFade('fadeOut');
            this.lightsOff();
	    }
	    
	    
	},
	
	addEvent : function (oObject, strEvent, oFunction, bCapture)
	{
		if(oObject)
		{
			if(oObject.addEventListener)
			{
				oObject.addEventListener(strEvent, oFunction, bCapture);
			}
			else if(window.attachEvent)
			{
				oObject.attachEvent(("on" + strEvent), oFunction)
			}
		}
	},
	
	lightsOff : function ()
	{
        if (navigator.appName.indexOf("Microsoft") != -1) 
        {
            flash = window['virbVideo'];
        }
        else 
        {
            flash = window.document['virbVideo'];
        }
		document.getElementById("player").style.display = 'inline';
        //var flashInfo  = flash['lightsOff']();
	},
	
	lightsOn : function ()
	{
        if (navigator.appName.indexOf("Microsoft") != -1) 
        {
            flash     = window['virbVideo'];
        }
        else 
        {
            flash     = window.document['virbVideo'];
        }
		document.getElementById("player").style.display = 'none';
	    //var flashInfo  = flash['lightsOn']();
	}	
}




// ---
LightsOut.addEvent(window, "scroll", function(){ LightsOut.setOverlaySize(); }, false);
LightsOut.addEvent(window, "resize", function(){ LightsOut.setOverlaySize(); }, false);

for (i = 0; i < 12; i++) {
	var tImage = new Image;
	tImage.src = "http://www.korta.is/img/fade/fade_"+i+".png";
}

function closePlayer() {
LightsOut.setFocus();
}

