var RedBox = {

  showInline: function(id)
  {
    this.showOverlay();
    new Effect.Appear('RB_window', {duration: 0.4, queue: 'end'});        
    Element.scrollTo('RB_window');
    this.cloneWindowContents(id);
  },

  loading: function()
  {
    this.showOverlay();
    Element.show('RB_loading');
    this.setWindowPosition();
  },

  addHiddenContent: function(id)
  {
    this.removeChildrenFromNode($('RB_window'));
    this.moveChildren($(id), $('RB_window'));
    Element.hide('RB_loading');
    new Effect.Appear('RB_window', {duration: 0.4, queue: 'end'});  
    Element.scrollTo('RB_window');
    this.setWindowPosition();
  },

  close: function()
  {
    new Effect.Fade('RB_window', {duration: 0.4});
    new Effect.Fade('RB_overlay', {duration: 0.4});
  },

  showOverlay: function()
  {
    if ($('RB_redbox'))
    {
      Element.update('RB_redbox', "");
      new Insertion.Top($('RB_redbox'), '<div id="RB_window" style="display: none;"></div><div id="RB_overlay" style="display: none;"></div>');  
    }
    else
    {
      new Insertion.Bottom(document.body, '<div id="RB_redbox" align="center"><div id="RB_window" style="display: none;"></div><div id="RB_overlay" style="display: none;"></div></div>');      
    }
    new Insertion.Top('RB_overlay', '<div id="RB_loading" style="display: none"></div>');  

    this.setOverlaySize();
    new Effect.Appear('RB_overlay', {duration: 0.4, to: 0.6, queue: 'end'});
  },

  setOverlaySize: function()
  {
    if (window.innerHeight && window.scrollMaxY)
    {  
      yScroll = window.innerHeight + window.scrollMaxY;
    } 
    else if (document.body.scrollHeight > document.body.offsetHeight)
    { // all but Explorer Mac
      yScroll = document.body.scrollHeight;
    }
    else
    { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
      yScroll = document.body.offsetHeight;
    }
    $("RB_overlay").style['height'] = yScroll +"px";
  },

  setWindowPosition: function()
  {
    var pagesize = this.getPageSize();  
  
    $("RB_window").style['width'] = 'auto';
    $("RB_window").style['height'] = 'auto';

    var dimensions = Element.getDimensions($("RB_window"));
    var width = dimensions.width;
    var height = dimensions.height;        
    
    $("RB_window").style['left'] = ((pagesize[0] - width)/2) + "px";
    $("RB_window").style['top'] = ((pagesize[1] - height)/2) + "px";
	
  },


  getPageSize: function() {
    var de = document.documentElement;
    var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
    var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
  
    arrayPageSize = new Array(w,h) 
    return arrayPageSize;
  },

  removeChildrenFromNode: function(node)
  {
    while (node.hasChildNodes())
    {
      node.removeChild(node.firstChild);
    }
  },

  moveChildren: function(source, destination)
  {
    while (source.hasChildNodes())
    {
      destination.appendChild(source.firstChild);
    }
  },

  cloneWindowContents: function(id)
  {
    var content = $(id).cloneNode(true);
    content.style['display'] = 'block';
    $('RB_window').appendChild(content);  

    this.setWindowPosition();
  },
  
  
    showInline2: function(id, numId){
    this.showOverlay();
    // new Effect.Appear('RB_window', {duration: 0.4, queue: 'end'});        
    Element.scrollTo('RB_window');
    this.cloneWindowContents2(id, numId);
    },
  
  cloneWindowContents2: function(id, numId)
 {
     var content = $(id); //.cloneNode(true);
     this.content_parentNode = content.parentNode;
     this.div_id=id;
     content.style['display'] = 'block';
     $('RB_window').appendChild(content);
     document.getElementById('RB_window').style.display = "block";
     this.setWindowPosition();
     if (id == 'redbox_share'){document.getElementById('Saveassetid').value=numId;}
    	if (id == 'redbox_uploading'){document.getElementById('Saveassetid').value=numId;}
 },
 close2: function()
 {
     new Effect.Fade('RB_window', {duration: 0.3});
     new Effect.Fade('RB_overlay', {duration: 0.3});
     $('RB_window').lastChild.style.display='none';
     document.getElementById('RB_window').style.display = "none";
     if (this.content_parentNode)
     {
        this.content_parentNode.appendChild($('RB_window').lastChild);
         $(this.div_id).style.display='none';
     }
 //this.showSelectBoxes();
}
  /*	cloneWindowContents2: function(id, numId){

  	//var old_assetid = $('assetid');
  	//var old_colleagueName   = $('colleagueName');
  	//var old_colleagueEmail     = $('colleagueEmail');
  	//var old_campaignId   = $('campaignId');
  	//var old_newCampaignName     = $('newCampaignName');
 	//END SAFARI HACK FOR CLONING THE FORM ELEMENTS /
 	//var content = $(id).cloneNode(true);
 	// SAFARI HACK FOR CLONING THE FORM ELEMENTS /
  	//if (old_assetid) old_assetid.id += '_old';
  	//if (old_colleagueName)   old_colleagueName.id   += '_old';
  	//if (old_colleagueEmail)     old_colleagueEmail.id     += '_old';
  	//if (old_campaignId) old_campaignId.id += '_old';
  	//if (old_newCampaignName) old_newCampaignName.id += '_old';
  	
    //var content = $(id).cloneNode(true);
    //content.style['display'] = 'block';
    //$('RB_window').appendChild(content);  
    this.setWindowPosition();
    
    document.getElementById(id).style.display = 'block';
    
  },
  
  close2: function(id)
  {
  	//var old_assetid = $('assetid_old');
  	//var old_colleagueName   = $('colleagueName_old');
  	//var old_colleagueEmail     = $('colleagueEmail_old');
  	//var old_campaignId   = $('campaignId_old');
  	//var old_newCampaignName     = $('newCampaignName_old');
 	//END SAFARI HACK FOR CLONING THE FORM ELEMENTS /
 	//var content = $(id).cloneNode(true);
 	// SAFARI HACK FOR CLONING THE FORM ELEMENTS /
  	//if (old_assetid) old_assetid.id += 'assetid';
  	//if (old_colleagueName)   old_colleagueName.id   += 'colleagueName';
  	//if (old_colleagueEmail)     old_colleagueEmail.id     += 'colleagueEmail';
  	//if (old_campaignId) old_campaignId.id += 'campaignId';
  	//if (old_newCampaignName) old_newCampaignName.id += 'newCampaignName';
  
  	document.getElementById(id).style.display = 'none';
  
    //new Effect.Fade('RB_window', {duration: 0.4});
    //new Effect.Fade('RB_overlay', {duration: 0.4});
  }*/
}