function imgData( thisname, file_name, x_size, y_size, thumbnail, placename ){
  
  this.instname = thisname;
  this.len = 1;
  this.imglst = new Array();
  this.imglst[0] = new imgDetail( file_name, x_size, y_size, thumbnail, placename );
  this.maxpic = 6;
  this.tagpic = "topimg";
  this.tagtext = "imgexp1";
  this.textcls = new Array();
  this.textcls[0] = "text1_var";
  this.textcls[1] = "text2_var";
  this.tagtext_ext = "imgexp2";
  this.textextcls = new Array();
  this.textextcls[0] = "text3_var";
  this.textextcls[1] = "text4_var";
  this.picmenucls = new Array();
  this.picmenucls[0] = "picmenu_var";
  this.picmenucls[1] = "picmenu_var";
  this.pnode;
  this.tagbottom = "addinfo";
  this.currentpic = 1;
  this.dammypic = "../../images/window.gif";
  this.markcolor = "#C06E7D";
  this.recreation = false;
  
  this.addImg = addImg;
  this.showTn = showTn;
  this.markSelect = markSelect;
  this.deleteSel = deleteSel;
  this.showImg = showImg;
  this.setTextcls = setTextcls;
  this.setTextextcls = setTextextcls;
  this.setPicmenucls = setPicmenucls;
  
  function addImg( file_name, x_size, y_size, thumbnail, placename ){
    this.imglst[this.len] = new imgDetail( file_name, x_size, y_size, thumbnail, placename );
    this.len++;
  }
  
  function showTn( parent, bordercolor ){
    this.pnode = parent;
    var node = document.getElementById( parent );
    while( node && node.lastChild ){
       node.removeChild( node.lastChild );
    }
    var i;
    for( i=0; i<this.len; i++ ){
       var linknode = document.createElement( 'a' );
       linknode.setAttribute( 'href', "javascript:" + this.instname + ".showImg(" + i + ")" );
       node.appendChild( linknode );
       node.childNodes[i].style.position = "absolute";
       node.childNodes[i].style.left = (76*i + 1) + 'px';
       node.childNodes[i].style.top = 1 + 'px';
       var imgnode = document.createElement( 'img' );
       imgnode.setAttribute( 'border', '0' );
       imgnode.setAttribute( 'height', 75 );
       imgnode.setAttribute( 'width', 75 );
       imgnode.setAttribute( 'src', this.imglst[i].tn );
       node.childNodes[i].appendChild( imgnode );
       node.childNodes[i].childNodes[0].style.top = 0;
       node.childNodes[i].childNodes[0].style.left = 0;
       //if( i == 0 ){
       //   this.markSelect( node.childNodes[i] );
       //}
    }
    for( ; i<this.maxpic; i++ ){
       var divnode = document.createElement( 'div' );
       node.appendChild( divnode );
       node.childNodes[i].style.position = "absolute";
       node.childNodes[i].style.left = (76*i + 1) + 'px';
       node.childNodes[i].style.top = 1 + 'px';
       node.childNodes[i].style.width = 75 + 'px';
       node.childNodes[i].style.height = 75 + 'px';
       node.childNodes[i].style.borderStyle = "solid";
       node.childNodes[i].style.borderWidth = "1px";
       node.childNodes[i].style.borderColor = bordercolor;
    }
    this.markSelect( node, 0 );
  }
  
  function markSelect( node, index ){
    var divnode = document.createElement( 'div' );
    node.appendChild( divnode );
    node.lastChild.style.position = "absolute";
    node.lastChild.style.left = node.childNodes[index].style.left;
    node.lastChild.style.top = node.childNodes[index].style.top;
    node.lastChild.style.width = 75 + 'px';
    node.lastChild.style.height = 75 + 'px';
    node.lastChild.style.borderStyle = "dashed";
    node.lastChild.style.borderWidth = "5px";
    //node.lastChild.style.borderColor = "#7AAB45";
    node.lastChild.style.borderColor = this.markcolor;
  }
  
  function deleteSel( node ){
    node.removeChild( node.lastChild );
  }
  
  function showImg( index ){
    //if( index == (this.currentpic-1) ){return;}
    
    var node = document.getElementById( this.pnode );
    this.deleteSel( node );
    this.markSelect( node, index );
    this.currentpic = index+1;
    
    document.all[this.tagbottom].innerHTML = this.imglst[index].place;
    var obj1 = document.getElementById( this.tagtext );
    //var obj2 = document.getElementById( this.tagtext_ext ).style;
    var obj2 = document.getElementById( this.tagtext_ext );
    var obj3 = document.getElementById( "picmenu" );
    if( this.imglst[index].x > this.imglst[index].y ){
       obj1.className = this.textcls[1];
       //obj2.visibility = "visible";
       obj2.className = this.textextcls[1];
       obj3.className = this.picmenucls[1];
       if( this.recreation == true ){
          document.getElementById( "topimg" ).className = "imagerecreation";
       }
    }else{
       obj1.className = this.textcls[0];
       //obj2.visibility = "hidden";
       obj2.className = this.textextcls[0];
       obj3.className = this.picmenucls[0];
       if( this.recreation == true ){
          document.getElementById( "topimg" ).className = "image";
       }
    }
       //document.getElementById( "picmenu" ).style.className = "picmenu_recreation2";
    eval( 'document.' + this.tagpic + '.src="' + this.dammypic + '"' );
    eval( 'document.' + this.tagpic + '.width=' + this.imglst[index].x );
    eval( 'document.' + this.tagpic + '.height=' + this.imglst[index].y );
    eval( 'document.' + this.tagpic + '.src="' + this.imglst[index].name + '"' );
  }
  
  function setTextcls( cls1, cls2 ){
    this.textcls[0] = cls1;
    this.textcls[1] = cls2;
    this.recreation = true
  }
  
  function setTextextcls( cls1, cls2 ){
    this.textextcls[0] = cls1;
    this.textextcls[1] = cls2;
  }
  
  function setPicmenucls( cls1, cls2 ){
    this.picmenucls[1] = cls1;
    this.picmenucls[0] = cls2;
  }
}

function imgDetail( file_name, x_size, y_size, thumbnail, place ){
    this.name = file_name;
    this.x = x_size;
    this.y = y_size;
    this.tn = thumbnail;
    this.place = place;
    return this;
}

function displayText( titleid, textid ){
  
  this.titlesecid = titleid;
  this.storysecid = textid;
  this.data = new Array();
  
  this.addData = addData;
  this.showTitle = showTitle;
  this.showTitleonly = showTitleonly;
  this.deleteChild = deleteChild;
  this.dispText = dispText;
  
  var count = 0;
  
  function addData( _title, _subtitle, _titleexp, _storytitle, _story ){
    this.data[count++] = new textData( _title, _subtitle, _titleexp, _storytitle, _story );
  }
  
  function showTitle( index, bchgscroll ){
    this.showTitleonly( index );
    pnode = document.getElementById( this.storysecid );
    pnode.getElementsByTagName( 'h1' )[0].firstChild.nodeValue = this.data[index].storytitle;
    //pnode.getElementsByTagName( 'p' )[0].firstChild.nodeValue = this.data[index].story;
    this.deleteChild( pnode.getElementsByTagName( 'p' )[0] );
    if( bchgscroll == true ){
       scroll( 0, 0 );
    }
    var str = new String( this.data[index].story );
    this.dispText( pnode.getElementsByTagName( 'p' )[0], str );
  }
  
  function showTitleonly( index ){
    var pnode = document.getElementById( this.titlesecid );
    pnode.getElementsByTagName( 'h1' )[0].firstChild.nodeValue = this.data[index].title;
    pnode.getElementsByTagName( 'h2' )[0].firstChild.nodeValue = this.data[index].subtitle;
    var tagp = pnode.getElementsByTagName( 'p' )[0];
    this.deleteChild( tagp );
    var str = new String( this.data[index].titleexp );
    dispText( tagp, str );
  }
  
  function deleteChild( node ){
    while(1){
       if( node.firstChild != undefined ){
          node.removeChild( node.firstChild );
       }else{
          break;
       }
    }
  }
  
  function dispText( node, str ){
    while(1){
       var rtn = str.indexOf( '\n' );
       var tmpstr;
       if( rtn != -1 ){
          tmpstr = str.substring( 0, rtn );
          str = str.substring( rtn+1, str.length );
       }else{
          tmpstr = str;
       }
       var textnode = document.createTextNode( tmpstr );
       node.appendChild( textnode );
       if( rtn != -1 ){
          var brnode = document.createElement( 'br' );
          node.appendChild( brnode );
       }else{
          break;
       }
    }
  }
}

function textData( _title, _subtitle, _titleexp, _storytitle, _story ){

  this.title = _title;
  this.subtitle = _subtitle;
  this.titleexp = _titleexp;
  this.storytitle = _storytitle;
  this.story = _story;
  
  return this;
}
