/*
formulaire chargé en Ajax
- vigobody = id du body
- pagemask = id du masque gris
- mainform = id du conteneur de formulaire
*/

function shadowbox(openID, formURL, widthelem){

    this.openID = openID;
    this.formURL = formURL;
    this.widthelem = widthelem;
	var fu = this;
	
	$('#' + this.openID).click(function(){
	    fu.showmask();
		var request = $.ajax({
			type: 'GET',
			async : true,
			url: fu.formURL,
			dataType : 'html',
			success: function(response){
				fu.showform(response);					
			},
			error: function(obj, msg, e){
			    alert(e);
			},
	   		complete: function(obj, msg){
	            if(typeof(formlaunch) != 'function') return;
				formlaunch(); //fonction pouvant être lancée une fois le form chargé
	        }								
		});			
	});

	$('.form-cancel').live('click', function(){
		$('#mainform').css('display', 'none');						
	    $('#pagemask').css('display', 'none');			
    });
 
    this.getBodyDims = function(){
        return {width : $('#junglebody').width(), height : $('#junglebody').height()};	
	}
	
    this.showmask = function(){
        var dims = this.getBodyDims(); 	
		$('#pagemask').width(dims.width + 'px');	
		$('#pagemask').height(dims.height + 'px');				
		$('#pagemask').css('display', 'block');												
	    $('#pagemask').fadeTo(0, 0);		
	    $('#pagemask').fadeTo(300, 0.8);
    }
	
    this.showform = function(html){
		$('#mainform').html(html);	
        var width = $('#mainform').width();	
        var height = $('#mainform').height();				
        var dims = this.getBodyDims();
		var left = 0.5*(dims.width - width);
		var top = 100;		
		$('#mainform').css('left', left + 'px');					
		$('#mainform').css('top', top + 'px');								
		$('#mainform').css('display', 'block');
	}				
	
}	


