/*-------------------------------GLOBAL VARIABLES------------------------------------*/

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
var yPos = 0;
var	xPos = 0;
var LightBoxFadeIn;

/*----------------------------------------------------------------------------------------*/
function RodneyLightBoxInitialize ()
   { 
        getBrowserInfo(); 
        addLightboxMarkup(); 
   }

/*-----------------------------------------------------------------------------------------------*/
//Browser detect script origionally created by Peter Paul Koch at http://www.quirksmode.org/

function getBrowserInfo() {
	if (checkIt('konqueror')) {
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser 	= "Safari"
	else if (checkIt('omniweb')) browser 	= "OmniWeb"
	else if (checkIt('opera')) browser 		= "Opera"
	else if (checkIt('webtv')) browser 		= "WebTV";
	else if (checkIt('icab')) browser 		= "iCab"
	else if (checkIt('msie')) browser 		= "Internet Explorer"
	else if (!checkIt('compatible')) {
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS) {
		if (checkIt('linux')) OS 		= "Linux";
		else if (checkIt('x11')) OS 	= "Unix";
		else if (checkIt('mac')) OS 	= "Mac"
		else if (checkIt('win')) OS 	= "Windows"
		else OS 								= "an unknown operating system";
	}
}
function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
//------------------------------------------------------------------------------
function SpawnLightBox ( OutputString, FadeIn )
{
  
  if (browser == 'Internet Explorer')
    {
	    getScroll();
	    prepareIE('100%', 'hidden');  
	    setScroll(0,0);
	    hideSelects('hidden');
	}
	if ( FadeIn )
	{
	    LightBoxFadeIn = true;
	}
	displayLightbox ('block');
	document.getElementById('LightBoxContent').innerHTML = OutputString;
}
//--------------------------------------------------------------------------
function LooseLightBox ()
{
  if (browser == 'Internet Explorer')
    {
	    hideSelects('visible');
	    setScroll(0, yPos);
		prepareIE("auto", "auto");
	}
	displayLightbox ('none');
}
//------------------------------------------------------------------------
function getScroll()
    {
		if (self.pageYOffset) 
		    {
			    yPos = self.pageYOffset;
		    } 
		else if (document.documentElement && document.documentElement.scrollTop)
		    {
		        yPos = document.documentElement.scrollTop; 
		    } 
		else if (document.body) 
		    {
			    yPos = document.body.scrollTop;
		    }
	}
//-------------------------------------------------------------------------
function prepareIE (height, overflow)
    {
		bod = document.getElementsByTagName('body')[0];
		bod.style.height = height;
		bod.style.overflow = overflow;
  
		htm = document.getElementsByTagName('html')[0];
		htm.style.height = height;
		htm.style.overflow = overflow; 
	}
//---------------------------------------------------------------------
function setScroll (x, y)
{
		window.scrollTo(x, y); 
}
//-----------------------------------------------------------------------
function hideSelects (visibility)
{
	selects = document.getElementsByTagName('select');
	for(i = 0; i < selects.length; i++) {
		selects[i].style.visibility = visibility;
	}
}
//------------------------------------------------------------------------
function displayLightbox (display)
{
    if(display != 'none')
    {
        document.getElementById("lightbox").innerHTML = "<div id='LightBoxContent'></div>";
    }
    else if (typeof (srvUrl) != 'undefined' && srvUrl != '') {
        window.location.href = srvUrl;
    }
    else if (typeof (timeoutUrl) != 'undefined' && timeoutUrl != '') {
        window.location.href = timeoutUrl;
    }

	
	if ( LightBoxFadeIn )
	    {
	        
	        if ( display == 'block' )
	            {
	                document.getElementById('overlay').style.display = display;
	                document.getElementById('lightbox').style.display = display;
	                setOpacity ( document.getElementById('overlay'), 0 ); 
	                AnimateFade ( document.getElementById('overlay'), 20, 70 );
        	        
	                setOpacity ( document.getElementById('lightbox'), 0 ); 
	                AnimateFade ( document.getElementById('lightbox'), 20, 100 );
	             }
	          else
	            {
	                AnimateFade ( document.getElementById('overlay'), -20, 70 );
	                AnimateFade ( document.getElementById('lightbox'), -20, 100 );
	            }
	    }
	 else
	    {
	        document.getElementById('overlay').style.display = display;
	        document.getElementById('lightbox').style.display = display;
	    }

	

}
//------------------------------------------------------------------------
function AnimateFade ( Element, AmountFade, Brightness )
{
    if ( AmountFade < 0 )
        {
            if ( getOpacity ( Element )* 100 +  AmountFade < 0 )
                {
                   	Element.style.display = 'none';
                   return;
                }
         }
    else
        {
             if ( getOpacity ( Element ) * 100 +  AmountFade > Brightness )
                {
                   return;
                }
        }
    setOpacity ( Element,  parseFloat ( getOpacity ( Element ) ) +  parseFloat( AmountFade / 100 )  );   
    setTimeout ("AnimateFade ( document.getElementById ('" + Element.id + "'), " + AmountFade + " , " + Brightness + ")", 100 )
    
}
//------------------------------------------------------------------------
function addLightboxMarkup() 
{
    

	bod = document.getElementsByTagName('body')[0];
	
	overlay 			= document.createElement('div');
	
	overlay.id		= 'overlay';
	if (browser == 'Internet Explorer')
	{
	    overlay.attachEvent('onclick',LooseLightBox );
	}
	else
	{
	    overlay.addEventListener('click',LooseLightBox,false);
	} 
	
	lb					= document.createElement('div');
	lb.id				= 'lightbox';
	lb.className 	= 'loading';

	lb.innerHTML	= '<div id="lbLoadMessage">' +
						  '<p>Loading</p>' +
						  '</div>';
    
    
	bod.appendChild(overlay);


	bod.appendChild(lb);
}
//-----------------------------------------------------------------------
function getOpacity(element)
{
  var opacity = null;
  //Detect browser for later use
var Mybrowser = undefined;

if(navigator.userAgent.indexOf("MSIE")!=-1)
  Mybrowser = "IE";
else
  Mybrowser = "Mozilla";
  
  //Get the opacity based on the current browser used
  if(Mybrowser=="IE") {
    filter = element.style.filter;
    if(filter) {
      alpha = filter.split("alpha(opacity=");
      opacity = alpha[1].substr(0,(alpha[1].length-1))/100;
    }
  }
  else {
    opacity = element.style.opacity;
  }
    
  return opacity;
}
//-------------------------------------------------------------------------
//Sets an element's opacity
function setOpacity(element, o)
{
    var Mybrowser = undefined;

    if(navigator.userAgent.indexOf("MSIE")!=-1)
      Mybrowser = "IE";
    else
      Mybrowser = "Mozilla";
  //Set the opacity based on the current browser used
  if(Mybrowser=="IE") {
    element.style.filter = "alpha(opacity=" + (o*100) + ")";
  }
  else {
    element.style.opacity = o;
  }
}
/*
function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}
*/

