var _HTMLAltBox='';
var _idBoxAlt = 'altBox';

//Custom the ALT and Observe the element
function pimpMyAlt() {
	this.myBox = '';
	this.element = '';
	this.content = '';
	this.bfx = '';
	this.status = 'off';
	this.positionX = '';
	this.positionY = '';

	this.init = function(myElement,myContent,myContainer,posX,posY){
					//alert(myContent.constructor == Array);
					//alert(typeOf(myContent));
					this.element = $(myElement);
					this.content = myContent;
					this.myBox = $(myContainer);
					this.bfx = this.move.bindAsEventListener(this);
					this.positionX = posX | 15;
					this.positionY = posY | 0;
				};
	
	this.observe = function(){
					Event.observe(this.element, 'mouseover' , this.over.bindAsEventListener(this));
					Event.observe(this.element, 'mouseout' , this.out.bindAsEventListener(this));
				};
				
	this.over = function(event){
					var myDiv = Event.findElement(event)
					if (this.status == 'off'){
							this.myBox.innerHTML = this.content;
							this.myBox.show();
							Event.observe(this.element, 'mousemove', this.bfx);
							this.status = 'on';
					}
				};

	this.out = function(event){
					var myDiv =  $((event.relatedTarget) ? event.relatedTarget : event.toElement ); //browser dipendent !!!
					if (myDiv){
						if (!$(myDiv).descendantOf(this.element)){
							this.myBox.innerHTML = '';
							this.myBox.hide();
							Event.stopObserving(this.element, 'mousemove', this.bfx);
							this.status = 'off';
						}
					}
				};

	this.move = function(event){
					this.myBox.style.left = ((event.clientX + this.positionX) + (document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft)) + 'px' ;
					this.myBox.style.top = ((event.clientY + this.positionY) + (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop)) +'px';
				};
				

	//Build the ALT Box
	this.buildAltBox = function(filename,idBox){
						new Ajax.Request(filename,{
												onComplete: function(requester){
																_HTMLAltBox = requester.responseText;
																if (_HTMLAltBox!=''){
																	if ((idBox == '') || (!idBox)){
																		idBox = _idBoxAlt;
																	}
																	if (_HTMLAltBox!=''){
																		_HTMLAltBox = _HTMLAltBox.replace(/{{idBox}}/g,idBox);
																		new Insertion.Bottom(document.body,_HTMLAltBox);
																	}

																}
															}
											});
	};
	
	//Append the ALT Box in the body
	this.appendAltBox = function(idBox){
						if ((idBox == '') || (!idBox)){
							idBox = _idBoxAlt;
						}
						
						var AZA;
						alert('1AZA'+AZA);						
						if (_HTMLAltBox!=''){
						alert('2AZA'+AZA);						
							_HTMLAltBox = _HTMLAltBox.replace(/{{idBox}}/g,idBox);
							AZA = new Insertion.Bottom(document.body,_HTMLAltBox);
							alert('3AZA'+AZA);
							
						}
	};
}










//****************** FADE *******************************************

var IS_Fade = Class.create({
    divPtr: '',
    /*class: '',
    rotatorImg: '',
    message: '',*/
    
    init: function (divToBeCovered, className, rotatorImg, message) {
		var myHTMLFade
		var myWidth = divToBeCovered.clientWidth+2;
		var myHeight = divToBeCovered.clientHeight+2;
		var oElement = divToBeCovered;
		var myTop = 0;
		var myLeft = 0;
		while( oElement!= null ) {
			myTop += oElement.offsetTop;
			myLeft += oElement.offsetLeft;
			oElement = oElement.offsetParent;
		}
        
        /*divPtr = crea DIV utilizzando eventualmente class, rotator e message
		prende x,y,altezza e larghezza di divTobeCovered        
		imposta larghezza e altezza (anche sotituendo attributi di class)
		imposta lo stile del newDiv ad absolute (anche sotituendo attributi di class)
		imposta posizione top/left
		*/
	
		myHTMLFade = '<div class="'+className+'" style="display:none;position:absolute;top:'+myTop+'px;left:'+myLeft+'px;width:'+myWidth+'px;height:'+myHeight+'px;">';
		if (rotatorImg) {
			myHTMLFade = myHTMLFade + '<div class="fadeImg"><img src="/st193/images/loading.gif" width="32" height="32" ><br>'+message+'</div>';
		}
		myHTMLFade = myHTMLFade + '<div class="fadeBody"></div>';
		myHTMLFade = myHTMLFade + '</div>';

		new Insertion.Top(document.body,myHTMLFade);
		this.divPtr = $(document.body).firstChild;

    },
 
    showFade: function () {
        if (this.divPtr == null) return; 
        $(this.divPtr).show();
    },
 
    hideFade: function () {
        if (this.divPtr == null) return;
        $(this.divPtr).hide();
    },
 
    removeFade: function () {
        if (this.divPtr == null) return; 
		document.body.removeChild($(this.divPtr));
		this.divPtr = null;
    }
 
});


//***************************** END FADE ************************************	


