function openUrl(myUrl) {
  var openerIsClosed = (window.opener) ? window.opener.closed : true;
  if (openerIsClosed) {
    newMiniWindow = window.open(myUrl,"newMiniWindow","left=0,top=0,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
    newMiniWindow.focus();
  }
  else {
    opener.location = myUrl;
  }
}

//thumbnail.jsp


function writeThumbnailImg(myThumbnailNr, tdWidth, tdHeight, frameX, frameY){
  var myThumbData = '    <td valign="top" width="' + tdWidth + '">';
  if (tdHeight != null) {
    myThumbData += '<img src="' + rootpath + '/_common/_img/1x1_trans.gif' + '" width="' + tdWidth + '" height="' + tdHeight + '" /><br />';
  }
  if (myThumbnailNr <= gallery.length) {
    myThumbData += '<a href="detail_view.jsp?img=' + (myThumbnailNr-1) + '&" onmouseover="setHighlightFrame(' + frameX + ',' + frameY + '); self.status=\'\'; return true" onmouseout="killHighlightFrame(); self.status=\'\';return true;" onfocus="this.blur()"><img src="' + rootpath + gallery[(myThumbnailNr-1)]["thumbImgPath"] + '" width="82" height="62" border="0" /></a>';
  }
  myThumbData += '</td>';
  return myThumbData;
}

function initThumbnailImg() {
  thumbDynLayer = new Array ();
  thumbDynLayer[0] = new Array ();
  thumbDynLayer[0]['thumbs'] = DynLayer.getInline("thumb1ImageLayer");
  thumbDynLayer[1] = new Array ();
  thumbDynLayer[1]['thumbs'] = DynLayer.getInline("thumb2ImageLayer");
  thumbDynLayer[2] = new Array ();
  thumbDynLayer[2]['thumbs'] = DynLayer.getInline("thumb3ImageLayer");
  thumbDynLayer[3]  = new Array ();
  thumbDynLayer[3]['thumbs'] = DynLayer.getInline("thumb4ImageLayer");

  var j = 0;
  for (i=0; i<Math.ceil(gallery.length / 15); i++){

    thumbnailData = new Array ();
    thumbnailData[i]   = '';
    thumbnailData[i]  += '<table cellpadding="0" cellspacing="0" width="661" border="0">'
                      +  '  <tr>'
                      +  '    <td valign="top" width="15"><img src="' + rootpath + '/_common/_img/1x1_trans.gif' + '" width="204" height="1" /></td>'
                      +  writeThumbnailImg((j+1),90,9,369,52)
                      +  writeThumbnailImg((j+2),97,8,459,51)
                      +  writeThumbnailImg((j+3),95,5,556,48)
                      +  writeThumbnailImg((j+4),93,3,651,46)
                      +  writeThumbnailImg((j+5),82,null,744,43)
                      +  '  </tr>'
                      +  '</table>'
                      +  '<img src="' + rootpath + '/_common/_img/1x1_trans.gif' + '" width="1" height="33" /><br />'

                      +  '<table cellpadding="0" cellspacing="0" width="462" border="0">'
                      +  '  <tr>'
                      +  '    <td valign="top" width="4"><img src="' + rootpath + '/_common/_img/1x1_trans.gif' + '" width="9" height="1" /></td>'
                      +  writeThumbnailImg((j+6),90,4,174,151)
                      +  writeThumbnailImg((j+7),95,3,263,150)
                      +  writeThumbnailImg((j+8),101,4,358,151)
                      +  writeThumbnailImg((j+9),89,3,459,152)
                      +  writeThumbnailImg((j+10),82,null,549,147)
                      +  '  </tr>'
                      +  '</table>'
                      +  '<img src="' + rootpath + '/_common/_img/1x1_trans.gif' + '" width="1" height="41" /><br />'
                      +  '<table cellpadding="0" cellspacing="0" width="500" border="0">'
                      +  '  <tr>'
                      +  '    <td valign="top" width="4"><img src="' + rootpath + '/_common/_img/1x1_trans.gif' + '" width="47" height="1" /></td>'
                      +  writeThumbnailImg((j+11),92,null,211,254)
                      +  writeThumbnailImg((j+12),91,null,303,254)
                      +  writeThumbnailImg((j+13),91,1,394,255)
                      +  writeThumbnailImg((j+14),97,null,485,254)
                      +  writeThumbnailImg((j+15),82,null,582,254)
                      +  '  </tr>'
                      +  '</table>';
    thumbDynLayer[i]['thumbs'].setHTML(thumbnailData[i]);
    j += 15;
  }
  thumbDynLayer[actualThumb]['thumbs'].setVisible(1);
}


// detail.jsp

function initMainImg() {
  mainImageDynLayer  = DynLayer.getInline("mainImageLayer");

  var myRange    = ((actualImg-1>0) ? actualImg-2 : 0);
  var myRangeMax = ((myRange+4 >= gallery.length) ? gallery.length : myRange+5);
  for(i=myRange; i < myRangeMax; i++){
    pictures.addImage("mainImg"+i,gallery[i]['mainImgPath']);
  }
}

function openThumbnailPage(myUrl) {
  myPage = Math.ceil((actualImg+1) / 15)-1;
  top.location.href = myUrl + "?thumbPage=" + myPage;
}

var imageNavigation = '';
var pageText1        = '';
var pageText2        = '';

function nextThumb(myNr) {
  actualThumb = myNr;
  for (i=0; i<Math.ceil(gallery.length / 15); i++){
    thumbDynLayer[i]['thumbs'].setVisible(0);
  }
      
  thumbDynLayer[actualThumb]['thumbs'].setVisible(1);
      
  numberOfImages = gallery.length;
  numberOfPages  = Math.ceil(numberOfImages / 15);
  
  
  imageNavigation += '<table cellpadding="0" cellspacing="0" border="0">';
  imageNavigation += '  <tr>';
  
  if(actualThumb == 0) {
    imageNavigation += '    <td valign="top" width="13"><img src="' + rootpath + '/_common/_img/arrow_prev_13x12_ffffff_ff6600-i.gif' + '" width="13" height="12" /></a></td>';
  } else {
    imageNavigation += '    <td valign="top" width="13"><a href="javascript:nextThumb((actualThumb-1))" onmouseover="mouseOver(\'prevImg\');self.status=\'\'; return true" onmouseout="mouseOut(\'prevImg\');self.status=\'\';return true;" onfocus="this.blur()"><img src="' + rootpath + '/_common/_img/arrow_prev_13x12_ffffff_ff6600.gif' + '" width="13" height="12" border="0" name="prevImg" id="prevImg" /></a></td>';
  }
  
  imageNavigation += '    <td valign="top" width="10"><img src="' + rootpath + '/_common/_img/1x1_trans.gif' + '" width="10" height="1" /></td>';
  imageNavigation += '    <td valign="top" class="colorffffff"><span class="font11line13">'+ pageText1 +'&nbsp;' + (actualThumb+1) +'&nbsp;' + pageText2 +'&nbsp;' + numberOfPages + '</span></td>';
  imageNavigation += '    <td valign="top" width="9"><img src="' + rootpath + '/_common/_img/1x1_trans.gif' + '" width="9" height="1" /></td>';
  
  if(actualThumb < (numberOfPages - 1)) {
    imageNavigation += '    <td valign="top" width="13"><a href="javascript:nextThumb((actualThumb+1))" onmouseover="mouseOver(\'nextImg\');self.status=\'\'; return true" onmouseout="mouseOut(\'nextImg\');self.status=\'\';return true;" onfocus="this.blur()"><img src="' + rootpath + '/_common/_img/arrow_next_13x12_ffffff_ff6600.gif' + '" width="13" height="12" border="0" name="nextImg" id="nextImg" /></a></td>';
  } else if(actualThumb == (numberOfPages - 1)) {
    imageNavigation += '    <td valign="top" width="13"><img src="' + rootpath + '/_common/_img/arrow_next_13x12_ffffff_ff6600-i.gif' + '" width="13" height="12" /></td>';
  } else {
    imageNavigation += '    <td valign="top" width="13"><a href="javascript:nextThumb((actualThumb+1))" onmouseover="mouseOver(\'nextImg\');self.status=\'\'; return true" onmouseout="mouseOut(\'nextImg\');self.status=\'\';return true;" onfocus="this.blur()"><img src="' + rootpath + '/_common/_img/arrow_next_13x12_ffffff_ff6600-i.gif' + '" width="13" height="12" border="0" name="nextImg" id="nextImg" /></a></td>';
  }
  
  imageNavigation += '  </tr>';
  imageNavigation += '</table>';
  
  imgNavigationDynLayer.setHTML(imageNavigation);
  imageNavigation  = '';
  
  
  
  preloadActiveImages();
  //setImageSrc("mainImg",gallery[actualImg]['mainImgPath']);

}



function nextImg(myNr) {
  actualImg   = myNr;
  numberOfImages = gallery.length;
  numberOfPages  = numberOfImages;
  
  
  imageNavigation += '<table cellpadding="0" cellspacing="0" border="0">';
  imageNavigation += '  <tr>';
  
  if(actualImg == 0) {
    imageNavigation += '    <td valign="top" width="13"><img src="' + rootpath + '/_common/_img/arrow_prev_13x12_ffffff_ff6600-i.gif' + '" width="13" height="12" /></a></td>';
  } else {
    imageNavigation += '    <td valign="top" width="13"><a href="javascript:nextImg((actualImg-1))" onmouseover="mouseOver(\'prevImg\');self.status=\'\'; return true" onmouseout="mouseOut(\'prevImg\');self.status=\'\';return true;" onfocus="this.blur()"><img src="' + rootpath + '/_common/_img/arrow_prev_13x12_ffffff_ff6600.gif' + '" width="13" height="12" border="0" name="prevImg" id="prevImg" /></a></td>';
  }
  
  imageNavigation += '    <td valign="top" width="10"><img src="' + rootpath + '/_common/_img/1x1_trans.gif' + '" width="10" height="1" /></td>';
  imageNavigation += '    <td valign="top" class="colorffffff"><span class="font11line13">' + pageText1 + '&nbsp;' + (actualImg+1) + '&nbsp;' + pageText2 + '&nbsp;' + numberOfImages + '</span></td>';
  imageNavigation += '    <td valign="top" width="9"><img src="' + rootpath + '/_common/_img/1x1_trans.gif' + '" width="9" height="1" /></td>';
  
  if(actualImg < (numberOfPages - 1)) {
    imageNavigation += '    <td valign="top" width="13"><a href="javascript:nextImg((actualImg+1))" onmouseover="mouseOver(\'nextImg\');self.status=\'\'; return true" onmouseout="mouseOut(\'nextImg\');self.status=\'\';return true;" onfocus="this.blur()"><img src="' + rootpath + '/_common/_img/arrow_next_13x12_ffffff_ff6600.gif' + '" width="13" height="12" border="0" name="nextImg" id="nextImg" /></a></td>';
  } else if(actualImg == (numberOfPages - 1)) {
    imageNavigation += '    <td valign="top" width="13"><img src="' + rootpath + '/_common/_img/arrow_next_13x12_ffffff_ff6600-i.gif' + '" width="13" height="12" /></td>';
  } else {
    imageNavigation += '    <td valign="top" width="13"><a href="javascript:nextImg((actualImg+1))" onmouseover="mouseOver(\'nextImg\');self.status=\'\'; return true" onmouseout="mouseOut(\'nextImg\');self.status=\'\';return true;" onfocus="this.blur()"><img src="' + rootpath + '/_common/_img/arrow_next_13x12_ffffff_ff6600-i.gif' + '" width="13" height="12" border="0" name="nextImg" id="nextImg" /></a></td>';
  }
  
  imageNavigation += '  </tr>';
  imageNavigation += '</table>';
  
  imgNavigationDynLayer.setHTML(imageNavigation);
  imageNavigation  = '';
  
  preloadActiveImages();
  
  var myRange    = ((actualImg-1>0) ? actualImg-2 : 0);
  var myRangeMax = ((myRange+4 >= gallery.length) ? gallery.length : myRange+5);
  for(i=myRange; i < myRangeMax; i++){
    pictures.addImage("mainImg"+i,gallery[i]['mainImgPath']);
  }
  setImageSrc("mainImg",gallery[actualImg]['mainImgPath']);

}






