/*  Copyright 2010 by Marco Stocco <http://www.my-w.org>
 * -----------------------------------------------------------
 *
 * Effects for the ajax loading
 *
 * This script is distributed under the GNU General Public License.
 *
 * Read the entire license text here: http://www.gnu.org/licenses/gpl.html
 */

myw.effects_ajax = {

	/* set opacity and show the loading image */
	effect_start_1 : function(_vars) {
		var d = document.getElementById(_vars.div);
		d.style.opacity = 0.7;
		d.style.filter = 'alpha(opacity=70)';
		if (d.innerHTML == '' || d.style.display == 'none') {
			d.style.display = 'none';
			/* <!--myw:loadingImg--> does not work in IE. IE deletes the comment. */
			d.innerHTML = '<span style="display:none;">myw:loadingImg</span>'+myw.ajax.getLoadingImage();
			jQuery(d).animate({height:'show'},'medium');
		} else {
			var newDiv = document.createElement('div');
			newDiv.id = _vars.div+'_myw_isChild';
			newDiv.style.position = 'absolute';
			newDiv.style.height = '0px';
			newDiv.style.width = '0px';
			
/*			newDiv.style.position = 'absolute';
			newDiv.style.left = myw.mouse_x+'px';
			newDiv.style.top = myw.mouse_y+'px';
*/
			
			newDiv.style.position = 'relative';
			newDiv.style.left = Math.round(d.offsetWidth/2)+'px';
			newDiv.style.top = '-'+d.offsetHeight+'px';

			newDiv.innerHTML = myw.ajax.getLoadingImage();
			d.appendChild(newDiv);					
		}
		
		/* execute the ajax operation */
		myw.ajax.execute2(_vars);
	},
	effect_end_1 : function(_vars) {
		var d = document.getElementById(_vars.div);
	    d.style.opacity = 1;
	    d.style.filter = 'alpha(opacity=100)';
		if (document.getElementById(_vars.div+'_myw_isChild'))
			d.removeChild(document.getElementById(_vars.div+'_myw_isChild'));
	},
	
	/* mask and show in the middle of the screen a text */
	effect_start_2 : function(_vars) {
		myw.mask_show(function(){void(0);});
		var newDiv = document.createElement('div');
		newDiv.id = 'myw_mask_loading';
		newDiv.style.position = 'absolute';
		myw.popup_center(newDiv,200,20);
		newDiv.style.border = '2px #b22222 solid';
		newDiv.style.padding = '10px';
		newDiv.style.textAlign = 'center';
		newDiv.style.zIndex = 21;
		newDiv.innerHTML = '<font style="color: #b22222;">'+myw.lang.frontend.texts.WAIT + ' ...</font>' + myw.ajax.getLoadingImage();
		document.body.appendChild(newDiv);
		
		/* execute the ajax operation */
		myw.ajax.execute2(_vars);
	},
	effect_end_2 : function() {
		if (document.getElementById('myw_mask_loading'))
			document.body.removeChild(document.getElementById('myw_mask_loading'));
		myw.mask_hide();
	}
	
};

