﻿// Shadow box script
var ref;
var faderef;
var maxh = 0; 
var fadev=1;
var currentHeight;
//Expand speed (smaller the faster)
var exSp = 5;
//Fade speed (smaller the faster)
var fSP = 25;

function SBgetHeight(d)
{
    if(d.style.display!='none'&& d.style.display!='')
    {
	    return d.offsetHeight;
    }
        d.style.overflow = 'visible';
		viz = d.style.visibility;
		d.style.visibility = 'hidden';
		o = d.style.display;
		d.style.display = 'block';	
		r = parseInt(d.offsetHeight);				
		d.style.display = o;
		d.style.visibility = viz;
		return r;
}
function SBgetWidth(d)
{
    if(d.style.display!='none'&& d.style.display!='')
    {
	    return d.offsetWidth;
    }
        d.style.overflow = 'visible';
		viz = d.style.visibility;
		d.style.visibility = 'hidden';
		o = d.style.display;
		d.style.display = 'block';	
		r = parseInt(d.offsetWidth);				
		d.style.display = o;
		d.style.visibility = viz;
		return r;
}
function expandTimer(div,img)
{   
	var d = document.getElementById(div);
	if(currentHeight < d.maxh)
	{
	    working = true;
		v = Math.round((d.maxh-currentHeight)/exSp);
		v = (v<1) ? 1 :v ;
		v = (currentHeight+v);
		d.style.height = v+'px';
		currentHeight=v;
	}
	else
	{
	    working = false;
		d.style.height = d.maxh;
		if(currentWidth < d.maxw)
	    {
	        working = true;
		    v = Math.round((d.maxw-currentWidth)/exSp);
		    v = (v<1) ? 1 :v ;
		    v = (currentWidth+v);
		    d.style.width = v+'px';
		    currentWidth=v;
	    }
	    else
	    {
	        clearInterval(faderef);
	        faderef=setInterval('SBfade("'+img+'");',2);
		    d.style.width = d.maxw;
		    clearInterval(ref);
	    }
	}
}

function collapseTimer(div,img)
{
	var d = document.getElementById(div);
	
	if(currentWidth>0)
	{	    
		v = Math.round(currentWidth/exSp);
		v = (v<1) ? 1 :v ;
		v = (currentWidth-v);
		currentWidth=v;
		d.style.width = v+'px';
	}
	else
	{
		d.style.width = "0px";
		if(currentHeight>0)
	    {	    
		    v = Math.round(currentHeight/exSp);
		    v = (v<1) ? 1 :v ;
		    v = (currentHeight-v);
		    currentHeight=v;
		    d.style.height = v+'px';
	    }
	    else
	    {
		    d.style.height = "";
		    d.style.width = "";
		    d.style.display='none';
		    clearInterval(ref);
	    }
	}
}
function SBfade(id)
{
    var d = document.getElementById(id);
    if (fadev/fSP <= 1)
    {
	    d.style.opacity = (fadev/fSP);
		d.style.filter= 'alpha(opacity='+(fadev*100/fSP)+');';
	    fadev++;
	}
	else
	{
	    fadev=1;
	    clearInterval(faderef);
	}   
}
function pageWidth() 
{
    return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}

function pageHeight() 
{
    return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}

function posLeft() 
{
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;
}

function posTop() 
{
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
}
