// Cleaned up the code found
// http://mattroper.co.uk/2008/05/27/javascript-overlay-using-prototype-and-scriptaculous/
// The "content" param accepts the following kind of content: text, HTML, DOM element,
// and any kind of object with a toHTML or toElement method.

var DialogOverlay = Class.create({
  initialize: function(content, container) {
    // Manage arguments and assign defaults,
    container = container || document.body;
    if (null == (this.container = $(container))){
      throw("container is not valid");
    }

    // Resolve content element
    if (content && content.toElement){
      content = content.toElement();
    }

    // Content may have been hidden if it is embedded in the page
    if (Object.isElement(content)){
      $(content).show();
	}
	
    // Assign instance variables
    this.content = content;
    this.overlay = new Element('div', { 'class': 'overlay' }).hide();
    this.dialog  = new Element('div', { 'class': 'dialog'  }).hide();
    
    // Hide the overlay when clicked. Ignore clicks on the dialog.
    //this.overlay.observe('click', this.hide.bind(this));
    //this.dialog.observe('click',  function(e) { e.stop() });
    
    // Insert the elements into the DOM
    this.dialog.insert(this.content);
    this.container.insert(this.overlay).insert(this.dialog);
	
	//attacco di nuovo le classi per ie8
	this.overlay.className='overlay';
	this.dialog.className='dialog';
  },

  overlayShow: function() {
    this.overlay.appear({
      duration: 0.4,
      to: 0.5,
      afterFinish: function() {
        /*
		//se ie6 posizione il box rispetto allo scroll della pagina
		if(navigator.userAgent.indexOf('MSIE') != -1 && navigator.appVersion.indexOf('MSIE 6.') != -1){
		    if(document.compatMode && document.compatMode != "BackCompat"){
				var body = document.documentElement;
			}else{
				var body = document.body;
			} 
		    this.dialog.style.top=(body.scrollTop+100) + "px";
		}//fine ie6
		*/
		this.dialog.show();
      }.bind(this)
    });
    return this;
  },
  
  overlayHide: function() {
    this.dialog.hide();
    this.overlay.hide();
    return this;
  }
});