/* ----- ----- ----- Free software Foundation - Affero Licence ----- ----- -----

devant.js - display an iframe on other site contents
    Copyright (C) 2008  Thibault Garcia (thibault.garcia@revaweb.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

----- ----- ----- Free software Foundation - Affero Licence ----- ----- ----- */

var devantId;

/* ----- ----- devantInit ----- -----
*/
function devantInit(fct_deb,fct_fin) {
	devantId=document.createElement('div');

	/* ----- ----- fct ----- ------ */
	devantId.fct_deb = fct_deb || '';
	devantId.fct_fin = fct_fin || '';
	

	/* ----- ----- devantId ----- ----- */
	devantId.style.backgroundColor='#000';
	devantId.style.position='fixed';
	devantId.style.display='none';
	devantId.style.filter='alpha(opacity=0)';
	devantId.style.opacity=0;
	devantId.style.top='0';
	devantId.style.left='0';
	devantId.style.width='100%';
	devantId.style.height='100%';
	devantId.style.margin='0';
	devantId.style.padding='0';
	devantId.style.border='0';
	devantId.style.cssFloat='none';
	devantId.onclick=function() { devantFerme() }

	devantId.devantStep=0.1;
	devantId.devantDelay=25;
	devantId.devantValue=0;
	devantId.devantTimer=null;
	devantId.devantOpacityMax=0.60;

	/* ----- ----- node_div ----- ----- */
	var node_div=document.createElement('div');
	node_div.style.position='fixed';
	node_div.style.display='none';
	node_div.style.top='0';
	node_div.style.left='0';
	node_div.style.width='100%';
	node_div.style.height='100%';
	node_div.style.opacity='1';
	node_div.style.margin='0';
	node_div.style.padding='0';
	node_div.style.border='0';
	node_div.style.cssFloat='none';
	node_div.onclick=function() { devantFerme() }

	/* ----- ----- node_table ----- ----- */
	var node_table=document.createElement('table');
	node_table.style.width='100%';
	node_table.style.height='100%';
	node_table.style.margin='0';
	node_table.style.padding='0';
	node_table.style.border='0';
	node_table.style.cssFloat='none';

	var node_tbody=document.createElement('tbody');
	var node_tr=document.createElement('tr');
	var node_td=document.createElement('td');
	node_td.style.textAlign='center';
	node_td.style.verticalAlign='middle';

	/* ----- ----- node_iframe ----- ----- */
	var node_iframe=document.createElement('iframe');
	node_iframe.setAttribute('allowTransparency','true');
	node_iframe.setAttribute('frameBorder','0');
	node_iframe.setAttribute('src','');
	node_iframe.style.width='0';
	node_iframe.style.height='0';
	node_iframe.style.background='transparent';

	/* ----- ----- finalisation ----- ----- */
	node_td.appendChild(node_iframe);
	node_tr.appendChild(node_td);
	node_tbody.appendChild(node_tr);
	node_table.appendChild(node_tbody);
	node_div.appendChild(node_table);

	devantId.devantTable=node_div;
	devantId.devantFrame=node_iframe;

	document.getElementsByTagName('body')[0].appendChild(devantId);
	document.getElementsByTagName('body')[0].appendChild(node_div);
}

/* ----- ----- devantOuvre ----- -----
*/
function devantOuvre(href,width,height) {
	if(devantId.DevantTimer) clearTimeout(devantId.DevantTimer);
	eval(devantId.fct_deb);
	devantId.devantFrame.src=href;
	devantId.style.display='block';

	devantId.devantTable.style.display='none';

	devantId.devantFrame.style.width=width;
	devantId.devantFrame.style.height=height;

	devantId.devantTimer=setTimeout('devantOpacityAdd()',devantId.devantDelay);
	return false;
}

/* ----- ----- devantOpacityAdd ----- -----
*/
function devantOpacityAdd() {
	if(devantId.devantTimer) clearTimeout(devantId.devantTimer);

	if(devantId.devantValue+devantId.devantStep<devantId.devantOpacityMax) {
		devantId.devantValue+=devantId.devantStep;
		devantId.style.opacity=devantId.devantValue;
		devantId.style.filter='alpha(opacity='+(100*devantId.devantValue)+')';

		devantId.devantTimer=setTimeout('devantOpacityAdd()',devantId.devantDelay);
	} else {
		devantId.devantValue=devantId.devantOpacityMax;
		devantId.style.opacity=devantId.devantValue;
		devantId.style.filter='alpha(opacity='+(100*devantId.devantValue)+')';
		devantId.devantTable.style.display='inline';
	}
}

/* ----- ----- devantOpacitySub ----- -----
*/
function devantOpacitySub() {
	if(devantId.devantTimer) clearTimeout(devantId.devantTimer);

	if(devantId.devantValue-devantId.devantStep>devantId.devantStep) {
		devantId.devantValue-=devantId.devantStep;
		devantId.style.opacity=devantId.devantValue;
		devantId.style.filter='alpha(opacity='+(100*devantId.devantValue)+')';

		devantId.devantTimer=setTimeout('devantOpacitySub()',devantId.devantDelay);
	} else {
		devantId.devantValue=0;
		devantId.style.display='none';
		devantId.style.opacity=0;
		devantId.style.filter='alpha(opacity=0)';
		eval(devantId.fct_fin);
	}
}
/* ----- ----- devantFerme ----- -----
*/
function devantFerme() {
	if(devantId) {
		devantId.devantFrame.src='';
		devantId.devantTable.style.display='none';
		devantId.devantTimer=setTimeout('devantOpacitySub()',devantId.devantDelay);
	}
}

/* ----- ----- devantFin ----- -----
*/
function devantFin() {
	if ((window)&&(window.parent)&&(window.parent.devantFerme)) {
		window.parent.devantFerme();
	}
}
