var LoadedLib;
if (!LoadedLib) LoadedLib={}
LoadedLib.FRS_Effects=true;


if (!LoadedLib) LoadedLib={}
LoadedLib.FRS_EffectsLibrary=true;


function CFRS_Effects()
{
	
	this.OnFinishEffect=null;
	
	
	this.ChangeOpacity = ChangeOpacity;
	
	
	this.Fade=function(ElementID, opacStart, opacEnd, millisec) 
	{
		//speed for each frame
		var speed = Math.round(millisec / 100);
		var timer = 0;
		
		if(this.OnFinishEffect !=null)
		{
			setTimeout(this.OnFinishEffect,millisec);
		}
		
		
		//determine the direction for the blending, if start and end are the same nothing happens
		if(opacStart > opacEnd) {
			for(i = opacStart; i >= opacEnd; i--) {
				setTimeout('ChangeOpacity(' + i + ',"' + ElementID + '")' , (timer * speed));
				timer++;
			}
		} else if(opacStart < opacEnd) {
			for(i = opacStart; i <= opacEnd; i++)
				{
				setTimeout('ChangeOpacity(' + i + ',"' + ElementID + '")' , (timer * speed));
				timer++;
			}
		}
	}	
}



var	FadeDIV = null;
function CFRS_EffectsLibrary()
{
	
	var BaseClass=this;
	
	if(LoadedLib.FRS_Public!=true)
	{
		alert("FRS_EffectsLibrary: Please link to FRS_Public before");
		return ;
	}
	
	this.UseLoadImage = true;
	
	
	this.FadePage = function(msSpeed)
	{
		window.onscroll = CurrectLoadFader;
		window.onresize = CurrectLoadFader;
		
		FadeDIV = GetFadeDIV();
		
		CurrectLoadFader();
		
		FadeDIV.style.visibility='visible';
		
		FRS_Effects.Fade(FadeDIV.id,0,80,msSpeed);
	}
	
	
	this.UnFadePage = function()
	{
		FinishLoadEffect();
	}
		
	
	
		
	function FinishLoadEffect()
	{
		
		FRS_Effects.OnFinishEffect = function() {
								if(FadeDIV!=null)
								{
									FadeDIV.style.visibility='hidden' 
								}
							} ; 
		
		if(FadeDIV!=null)
		{
			FRS_Effects.Fade(FadeDIV.id , 90,0,300);	
		}
		
		setTimeout("FRS_Effects.OnFinishEffect=null",300);
	}	
	
	
	function GetFadeDIV()
	{
		var FadeDIV = null;
		FadeDIV = FRS_Public.GetElement("FRS_LoadFader");
		if(FadeDIV==null)
		{
			FadeDIV = document.createElement("div");
			document.body.appendChild(FadeDIV);
			
			FadeDIV.id = "FRS_LoadFader";
			FadeDIV.style.zIndex = "1";
			FadeDIV.style.position = "absolute";
			FadeDIV.style.backgroundColor="#000000";
			ChangeOpacity(0,FadeDIV.id);
			
			if(BaseClass.UseLoadImage)
			{
				FadeDIV.innerHTML = '<img id="FRS_AjaxLoaderIMG" style="position:absolute" src="images/FRS-ajax-loader.gif" />';
			}
		}
		
		return FadeDIV
	}

}




function CurrectLoadFader()
{
	
	if(FRS_Public.GetElement("FRS_LoadFader")!=null)
	{
		FRS_Public.GetElement("FRS_LoadFader").style.height  = FRS_Public.WindowScrollMaxY()   + 'px'; 
		FRS_Public.GetElement("FRS_LoadFader").style.width = '100%'; 
		FRS_Public.GetElement("FRS_LoadFader").style.top = '0px';
		FRS_Public.GetElement("FRS_LoadFader").style.left = '0px';
		FRS_Public.GetElement("FRS_LoadFader").style.zIndex = "1"
		
	}
	
	
	if(FRS_Public.GetElement("FRS_AjaxLoaderIMG")!=null)
	{
		FRS_Public.GetElement("FRS_AjaxLoaderIMG").style.top =  FRS_Public.WindowScrollY() + (FRS_Public.PageHeight())/2 + 'px';
	}
	
	FRS_Public.GetElement("FRS_AjaxLoaderIMG").style.left= (FRS_Public.PageWidth() /2) + 'px';
}

function ChangeOpacity(opacity,ElementID)
{
	var object = FRS_Public.GetElement(ElementID).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";	
}
