
function w( href ) {
  window.open( href );
  return false;
}

function showq( q ) {
  document.getElementById( q ).style.display = 'inline';
}

function hideq( q ) {
  document.getElementById( q ).style.display = 'none';
}

function setOpacity( obj, opacity ) {
  opacity = opacity == 100 ? 99.999 : opacity;

  // IE/Win
  obj.style.filter = "alpha(opacity:" + opacity + ")";

  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity / 100;

  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity / 100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity / 100;
}

function fadeInOpacity( objId, opacity ) {
  if ( document.getElementById ) {
    obj = document.getElementById( objId );
    if ( opacity < 100 ) {
      setOpacity( obj, opacity );
      opacity += 10;
      window.setTimeout( "fadeInOpacity('" + objId + "', " + opacity + ")", 100 );
    }
  }
}

function fadeOutOpacity( objId, opacity ) {
  if ( document.getElementById ) {
    obj = document.getElementById( objId );
    if ( opacity >= 0 ) {
      setOpacity( obj, opacity );
      opacity -= 10;
	    if ( opacity > 0 ) {
        window.setTimeout( "fadeOutOpacity('" + objId + "', " + opacity + ")", 100 );
	    } else {
		    obj.style.visibility = 'hidden';
	    }
    }
  }
}

function fadeInText( objId, aObjId, fR, fG, fB, pR, pG, pB, aR, aG, aB ) {
  if ( document.getElementById ) {
    obj = document.getElementById( objId );
    aObj = document.getElementById( aObjId );
    if ( fR > pR || fG > pG || fB > pB || fR > aR || fG > aG || fB > aB ) {
      obj.style.color = "rgb( " + fR + ", " + fG + ", " + fB + " )";
	  afR = fR < aR ? aR : fR;
	  afG = fG < aG ? aG : fG;
	  afB = fB < aB ? aB : fB;
      aObj.style.color = "rgb( " + afR + ", " + afG + ", " + afB + " )";
	  fR -= 25;
	  fR = fR < pR ? pR : fR;
      fG -= 25;
	  fG = fG < pG ? pG : fG;
      fB -= 25;
	  fB = fB < pB ? pB : fB;
      window.setTimeout( "fadeInText('" + objId + "', '" + aObjId + "', " + fR + ", " + fG + ", " + fB + ", " + pR + ", " + pG + ", " + pB + ", " + aR + ", " + aG + ", " + aB + ")", 100 );
    }
  }
}

function onlydigits( e )
{
  var unicode = e.charCode ? e.charCode : e.keyCode;

  if ( unicode != 8 && unicode != 9 ) {    // BACKSPACE and TAB allowed
    if ( unicode < 48 || unicode > 57 ) {  // only numbers
      return false;
    }
  }

  return true;
}

function onlydigitsordot( e )
{
  var unicode = e.charCode ? e.charCode : e.keyCode;

  if ( unicode != 8 && unicode != 9 && unicode != 46 ) {    // BACKSPACE and TAB and '.' allowed
    if ( unicode < 48 || unicode > 57 ) {  // only numbers
      return false;
    }
  }

  return true;
}

function lpad( number, len )
{
  var str = '' + number;
  while ( str.length < len )
  {
    str = '0' + str;
  }
  return str;
}

function emphasize( o )
{
  var p = document.getElementById( 'contentnav' );
  var tags = p.getElementsByTagName('a');
  for ( var i = 0 ; i < tags.length ; i++ )
  {
    var a = tags[i];
    a.className = a.className.replace( /\bemphasize\b/, '' );
  }
  o.className += ' emphasize';
}


var start = 1;

function showthumbnails( j )
{
  start = 1;
  if ( j ) start = j;

  for ( i = 1 ; i <= 6 ; i++ )
  {
    if ( document.getElementById( 'thumb' + i ) )
    {
      document.getElementById( 'thumb' + i ).style.display = 'none';
    }
  }

  if ( typeof subimagecounts !== 'undefined' )
  {
    howmany = subimagecounts[img-1];
    basename = imagebasename || 'wedding';
    filetype = imagefiletype || 'jpg';
    imgbasename = 'images/' + basename + lpad( img, 2 ) + 'thumb-';

    for ( i = start ; i < start + howmany ; i++ )
    {
      if ( document.getElementById( 'thumbimg' + i ) )
      {
        document.getElementById( 'thumbimg' + i ).src = imgbasename + i + '.' + filetype;
      }
      if ( document.getElementById( 'thumb' + i ) )
      {
        document.getElementById( 'thumb' + i ).style.display = 'inline';
      }
    }
  }
}

var ident = false;
var press = false;
var bambino = false;

function showimageno( n, k )
{
  img = n;
  basename = imagebasename || 'wedding';
  filetype = imagefiletype || 'jpg';
  imgname = 'images/' + basename + lpad( n, 2 );
  if ( k ) imgname += '-' + k;
  imgname += '.' + filetype;
  if ( document.getElementById( 'contentimagegrid' ) )
  {
    document.getElementById( 'contentimagegrid' ).style.display = 'none';
  }
  document.getElementById( 'contentimage' ).style.display = 'inline';
  document.getElementById( 'contentimage' ).src = imgname;
  document.getElementById( 'contentimage' ).width = ( ident || press || k == 1 ? 547 : 800 );
  if ( document.getElementById( 'contentcustom' ) )
  {
    if ( document.getElementById( 'contentpress' ) )
    {
      document.getElementById( 'contentpress' ).style.width = '814px';
      document.getElementById( 'contentpress' ).style.paddingRight = '32px';
    }

    if ( document.getElementById( 'previousnextnav' ) )
    {
      document.getElementById( 'previousnextnav' ).style.display = 'inline';
    }

    document.getElementById( 'contentcustom' ).style.display = ( ident || press || k == 1 ? 'inline' : 'none' );

    if ( ident || press || k == 1 )
    {
      document.getElementById( 'contentcustomh3' ).innerHTML = cch3[n];

      if ( press )
      {
        document.getElementById( 'contentcustomh4' ).innerHTML = cch4[n];
      }

      document.getElementById( 'contentcustomtext' ).innerHTML = cctext[n];
    }

//    document.getElementById( 'contentimage' ).style.marginLeft = ( k == 1 ? '253px' : '0' );
  }

  if ( !press )
  {
    emphasize( document.getElementById( 'contentnav' + n ) );

    if ( !bambino )
    {
      showthumbnails( start );
    }
  }

  ident = false;
  press = false;
  bambino = false;
}

function showidentimageno( n )
{
  ident = true;
  showimageno( n );
  document.getElementById( 'nextpreviousidentity' ).style.display = 'inline';
}

function shownextidentimage()
{
  ident = true;
  shownextimage();
}

function showprevidentimage()
{
  ident = true;
  showprevimage();
}

function showbambinoimageno( n )
{
  bambino = true;
  showimageno( n );
  document.getElementById( 'nextpreviousbambino' ).style.display = 'inline';
}

function shownextbambinoimage()
{
  bambino = true;
  shownextimage();
}

function showprevbambinoimage()
{
  bambino = true;
  showprevimage();
}


function showpressimageno( n )
{
  press = true;
  showimageno( n );
}

function showthumbimageno( k )
{
  showimageno( img, k );
}

function shownextpressimage()
{
  press = true;
  shownextimage();
}

function showprevpressimage()
{
  press = true;
  showprevimage();
}

function shownextimage()
{
  if ( ++img > imagecount ) img = 1;
  showimageno( img );
}

function showprevimage()
{
  if ( --img < 1 ) img = imagecount;
  showimageno( img );
}





function showclementineimageno( n )
{
  img = n;
  basename = imagebasename || 'clementinecat';
  filetype = imagefiletype || 'png';
  imgname = 'images/' + basename + lpad( n, 2 );
  imgname += '.' + filetype;

  document.getElementById( 'contentimage' ).style.display = 'inline';
  document.getElementById( 'contentimage' ).src = imgname;
  document.getElementById( 'contentimage' ).alt = cch3[n];

  if ( document.getElementById( 'contenttext' ) )
  {
    document.getElementById( 'contenttext' ).innerHTML = cctext[n];
  }

  if ( document.getElementById( 'contenturl' ) )
  {
    document.getElementById( 'contenturl' ).href = ccurl[n];
  }
}

function shownextclementineimage()
{
  if ( ++img > imagecount ) img = 1;
  showclementineimageno( img );
}

function showprevclementineimage()
{
  if ( --img < 1 ) img = imagecount;
  showclementineimageno( img );
}






function showclementinedesignimageno( n )
{
  img = n;
  basename = imagebasename;
  filetype = imagefiletype || 'jpg';
  imgname = 'images/' + basename + lpad( n, 2 );
  imgname += '.' + filetype;

  document.getElementById( 'contentimage' ).src = imgname;
//  document.getElementById( 'contentimage' ).alt = cch3[n];
}

