/**
 * @author rgaumond
 */



function processing()
{
	try{
			loading_info.clear();
			function_initiated("showVeil");
			function_initiated("removeVeil");
			veil_on = true;
			showVeil();					
			hide_index();
			$("wait_image").src = pathToImages + "/wait.gif";
			$("wait_image").style.display="block";
			place_veil();
			place_wait_animation();	
	}catch(e){alert("error in function processing(ceremony_utilities.js) . Error:"+e)}
}

function processed(from)
{
	try{
		
		var not_completed=" ";

		if (pre_loading_completed()) {
			removeVeil();
			$("wait_image").style.display="none";
		}
		else {
			var the_incomplete_list = loading_info.findAll(function(fn){return fn.completed==false});
			the_incomplete_list.each(function(fn2){not_completed+=fn2.id+" not completed<br/>  ";});
			processed.delay(global_delay,"trying again");
		}
	}catch(e){alert("error in function processed(ceremony_utilities.js) . Error:"+e)}
}

function showVeil()
{
try{	
	if(loading_info.findAll(function(fn){return (fn.completed == false && fn.id=="showVeil")}).size() == 0)
		function_initiated("showVeil");	
	try {
		veil.fader.stop();
		
	}catch(e){}
	
	var targetedOpacity = 60;
	var stepsSize = 20;
	
	veil.style.display = "block";
	veil.style.height = document.viewport.getHeight();
	veil.style.width = document.viewport.getWidth();
	veil.style.top = document.body.scrollTop;
	veil.fader = new PeriodicalExecuter(function() {
		var fade = false;
		var currentOpacity;
		//Modifying value for IE
			if(IE)
			{
				try{currentOpacity = veil.filters.alpha.opacity;}
				catch(exception){currentOpacity=0;}	
			}
			else
			{	
				if (veil.style.opacity=="")
					currentOpacity = "0";
				else
					currentOpacity =  veil.style.opacity*100;
			}
			
			if (((currentOpacity-stepsSize)<targetedOpacity)
						||(targetedOpacity==currentOpacity)|| currentOpacity>targetedOpacity )//do nothing 
				{
					veil.style.display="block";
					veil.style.filter="alpha(opacity=0)";//initialing IE
					if(IE)
						veil.style.filter="alpha(opacity=80)";//
					else
						veil.style.opacity=targetedOpacity/100;	
					veil_on = true;
					veil.fader.stop();
					fade = false;
					function_completed("showVeil");							
					return;					
				}
				else if (currentOpacity < targetedOpacity) 
				{
						if(IE)
						 	veil.style.filter="alpha(opacity="+(currentOpacity+stepsSize)+")";
						else
							veil.style.opacity=(currentOpacity+stepsSize)/100;
						fade = true;		
				}
			},0.1);
	}catch(e){alert("error in function showVeil(ceremony_utilities.js) . Error:"+e)}
}

function removeVeil()
{
	try{
		if(loading_info.findAll(function(fn){return (fn.completed == false && fn.id=="removeVeil")}).size() == 0)
			function_initiated("removeVeil");
		
		veil.style.display = "block";
		
		try {
			(veil.fader.stop())
		}catch(e){}
	
		veil.fader = new PeriodicalExecuter(function() {
		var fade = false;
		var currentOpacity;
		var steps = 30;
		//Modifying value for IE
			if(IE)
			{
				try{currentOpacity = veil.filters.alpha.opacity;}
				catch(exception){currentOpacity=60;}	
			}
			else
			{	
				if (veil.style.opacity=="")
					currentOpacity = "60";
				else
					currentOpacity =  veil.style.opacity*100;
			}
			
			if (((currentOpacity-steps)<0)
						||(currentOpacity==0)|| currentOpacity<0 )//do nothing 
				{
					veil.style.display="none";
					veil.style.filter="alpha(opacity=0)";//initialing IE
					if(IE)
						veil.style.filter="alpha(opacity=0)";//
					else
						veil.style.opacity=0;					
					veil_on = false;
					veil.fader.stop();
					fade = false;
					function_completed("removeVeil");							
					return;					
				}
				else if (currentOpacity > 0) 
				{
						if(IE)
						 	veil.style.filter="alpha(opacity="+(currentOpacity-steps)+")";
						else
							veil.style.opacity=(currentOpacity-steps)/100;
						fade = true;		
				}
			},0.1);

	}catch(e){alert("error in function removeVeil(veils.js). Error:"+e)}
}

function void_processing_veil()
{
	var the_veil_interval = interval_effect_array.find(function(the_object){return the_object.objectToFade_ID=="veil"});
	
	window.clearInterval(the_veil_interval._interval);
	
}

function place_veil()
{
	try{
		if(veil_on)
		{
			veil.style.width = document.viewport.getDimensions().width;
			veil.style.height = document.viewport.getDimensions().height;
			

			if ( theBody.scrollTop<=(theBody.scrollHeight - parseInt(veil.style.height)))
				veil.style.top = theBody.scrollTop;
			else
				veil.style.top =theBody.scrollHeight - parseInt(veil.style.height);
		
			if ( theBody.scrollLeft<=(theBody.scrollWidtht - parseInt(veil.style.width)))
				veil.style.top = theBody.scrollLeft;
			else
				veil.style.top =theBody.scrollWidtht - parseInt(veil.style.width);
		}	
		//alert(parseInt(veil.style.top)+"  "+theBody.scrollTop+" "+theBody.scrollHeight)
	}catch(e){}
}





function clear_container()
{
	container.innerHTML="";
	
}

function place_wait_animation()
{
	if($("wait_image").style.display=="block")
		center_element_in_viewport($("wait_image"));
}



