

function Modal(){
  
  
}

Modal.prototype = {
  
  start:function(){
    if(this.type == 'img') {
      this.preloadImage();
    }
    this.hideFlash();
    this.createModal();
  },
  preloadImage:function(){
    img = new Image();    
    img.src = this.src;    
  },
  
  setSource:function(src){
    
    this.src = src;    
    
  },
  setType:function(type){
  
    this.type = type;
  },
  
  hideFlash:function(){
  
    flash = document.getElementsByTagName('object');
    for(i=0;i<flash.length;i++){
      flash[i].className = 'hidden';
    }
  
  },
  createModal:function(){
    
    /* body->kontejner */
    
    this.output = '';
    this.modalContainer = document.createElement('div');
    this.modalContainer.id = 'modal';
       
    document.body.appendChild(this.modalContainer);
      
    /* modalni okno -> kontejner*/
    
    this.modalWindow = document.createElement('div');    
    this.modalWindow.id = 'modalWindow';
    this.modalWindow.onclick=this.closeModal;
    document.getElementById('modal').appendChild(this.modalWindow);
    
    /* div uzavreni modalu -> kontejner */
    
    this.modalCloser = document.createElement('div');    
    this.modalCloser.id = 'modal-close';
    
    document.getElementById('modal').appendChild(this.modalCloser);
    
    /* odkaz pro uzavreni -> div pro uzavreni */
    this.anchorCloser = document.createElement('a');    
    this.anchorCloser.href = '#';
    this.anchorCloser.innerHTML = 'Zavřít';
    this.anchorCloser.onclick=this.closeModal;
    
    
    document.getElementById('modal-close').appendChild(this.anchorCloser);
    
    
    
    if(this.type == 'img'){
      
      this.output = '<img src="'+this.src+'" alt="Kliknutím na obrázek jej zavřete." />';    
    }
    if(this.type == 'html'){
      this.output = this.src;
    }
    
    this.modalWindow.innerHTML = this.output;
    
 
  },
  
  closeModal:function(){
   
    flash = document.getElementsByTagName('object');
      for(i=0;i<flash.length;i++){
        flash[i].className = '';
        
      }
    document.body.removeChild(document.getElementById('modal'));      
    this.modalContainer = null;
    
  }
}
