//
// portfolio navigation
//

function pitem( title, imagename, imagecount, imagedesc ) {
  this.title = title
  this.desc = imagedesc
  this.count = imagecount
  this.thumb = document.createElement( 'img' ); //rb new Image( 40, 60 )
  this.thumbpath = "gallery/thumb/" + imagename + ".jpg"
  this.imagepath = "gallery/img/" + imagename
  this.imageext  = ".jpg"
  this.image = "gallery/img/" + imagename + "1.jpg"
}

function pcategory( title, desc ) {
  this.title = title
  this.desc  = desc
}

function pnav( category, item, pitems, listheight, tableheight ) {
  this.dynamic = ( item == -1 ) ? 1 : 0
  this.category = category
  this.item = item
  this.pitems = pitems
  this.listheight = listheight
  this.tableheight = tableheight
  this.current = ( item == -1 ) ? 0 : item
  this.zoomitem = 0

  this.pcategories = [
    new pcategory( "Tables &amp; Chairs", "Mosaic dining tables, end tables, patio tables and chairs..." ),
    new pcategory( "Clocks", "Mosaic clocks - wooden clock forms are handmade in our studio &amp; include quartz movement. 10''H x 17-1/2''W x 4''D..." ),
    new pcategory( "Mirrors", "3-D bouquet mirrors are created using individual flowers carved from plates and Capodimonte flower baskets then artfully <br />re-arranged with half a teapot, cup and saucer to create the breathtaking illusion of a whole image - approx. 24''x24''..." ),
    new pcategory( "Garden Art", "Mosaic garden walls, benches..." ),
    new pcategory( "Wall Fountains", "'Spitting image' caricature wall fountains can be custom made from color photos..." ),
    new pcategory( "Fireplace Surround", "" ),
    new pcategory( "Sculptures", "" ),
    new pcategory( "Miscellaneous", "Mosaic Address signs, garden pots, bowls, pitchers, teapots..." ),
    new pcategory( "Fred's Fish", "Fred's Fish are made from old metal trash cans, scrap tin and other recycled finds..." )
  ]

  this.getcategory = function() {
    return this.category
  }

  this.showcurrent = function( ) {
    this.showcategory( -1 )
    this.showtitle( -1 )
    this.showzoom( this.pitems[ this.current ].count, this.zoomitem )
  }

  this.showcategory = function( index ) {
    this.showdesc( this.category, index )
/*    if( index == -1 ) index = this.category
    var el = document.getElementById( 'title-pcategory' )
    el.innerHTML = ""
    el.innerHTML = this.pcategories[ index ].title
*/
  }

  this.showtitle = function( index ) {
    if( index == -1 ) index = this.current
    var el = document.getElementById( 'title-pitem' )
    el.innerHTML = ""
    el.innerHTML = this.pitems[ index ].title
  }

  this.showdesc = function( index ) {
    if( index == -1 ) index = this.category
    var el = document.getElementById( 'title-pdesc' )
    el.innerHTML = this.pcategories[ index ].desc
  }

  this.scrollup = function() {
    TALayer_scroll('p-thumbs',0,0,3,40,0,0)
    this.imageout()
  }

  this.scrolldown = function() {
    TALayer_scroll('p-thumbs',0,this.tableheight-this.listheight,3,40,0,0)
    this.imageout()
  }

  this.scrollstop = function() {
    TALayer_scroll('p-thumbs',0,0,1,1,2,0)
  }

  this.zoom = function( item ) {
    this.zoomitem = item
    if( this.zoomitem == this.pitems[this.current].count )
      this.zoomitem = 0
    if( this.dynamic )
      this.imageover( this.current )
    else
      window.location = "mosaics.asp?gallery=" + this.category + "&item=" + this.item + "&zoom=" + this.zoomitem
  }

  this.thumbitemover = function( index ) {
    this.thumbover()
    var id = 'thumb-' + index
    var el = document.getElementById( id )
    el.filters.alpha.opacity='100';
    el.style.border='1px solid #FFFFFF'
    this.showtitle( index )
  }

  this.thumbitemout = function( index ) {
    var id = 'thumb-' + index
    var el = document.getElementById( id )
    el.filters.alpha.opacity='70';
    el.style.border='0'
  }

  this.thumbover = function() {
    var el = document.getElementById( 'thumbs-mask' )
    el.filters.alpha.opacity='100'
    el.style.border='1px solid #52638C'
  }

  this.thumbout = function() {
    var el = document.getElementById( 'thumbs-mask' )
    el.filters.alpha.opacity='70'
//    el.style.border='1px solid #27395D'
  }

  this.thumbclick = function( index ) {
    if( index != -1 ) {
      this.current = index
      this.zoomitem = 0
    }
    this.imageover( index )
  }

  this.onimageload = function() {
    var el = document.getElementById( 'p-photo' )
    el.style.border='1px solid #52638C'
    el.filters.alpha.opacity='100'
  }

  this.imageover = function ( index ) {
    var el = document.getElementById( 'p-photo' )
    if( index != -1 ) {
      el.filters.alpha.opacity='20'
      el.style.border='1px solid #27395D'
      this.showzoom( this.pitems[ index ].count, this.zoomitem )
      el.onload=this.onimageload
      el.src = this.pitems[ index ].imagepath + (this.zoomitem + 1) + this.pitems[ index ].imageext
    }
    else
      this.onimageload()
  }

  this.imageout = function () {
    this.thumbover()
    var el = document.getElementById( 'p-photo' )
    el.filters.alpha.opacity='20'
    el.style.border='1px solid #27395D'
  }

  this.showzoom = function( count, current ) {
    var i, el, id, imgel
    for( i = 2; i <= 5; i++ ) {
      id = 'nav-zoom' + i
      el = document.getElementById( id )
      el.className = ( count >= i && count > 1 ) ? 'divon' : 'divoff'
      id = 'img-zoom' + i
      el = document.getElementById( id )
      el.src = 'img/nav_zoom' + (i) + '.gif'
//      el.src = ( current == i-1 ) ? 'img/nav_select.gif' : 'img/nav_zoom' + (i) + '.gif'
    }
  }

  this.preloadthumbs = function() {
    var i
    for( i = 0; i < this.pitems.length; i++ )
       this.pitems[i].thumb.src = this.pitems[i].thumbpath
  }

  this.writethumbs = function() {
    var i
    for( i = 0; i < this.pitems.length; i++ ) {
      if( this.dynamic )
        document.write( '<img class="thumb-img" id="thumb-' + i + '" src="' + this.pitems[i].thumb.src + '" onmouseover="mypnav.thumbitemover('+i+')" onmouseout="mypnav.thumbitemout('+i+')" onclick="javascript:mypnav.thumbclick(' + i + ')" alt="'+ ((this.pitems[i].desc == "")?this.pitems[i].title:this.pitems[i].desc) +'" /><br /><img src="img/spacer.gif" width="120" height="2" /><br />' )
      else
        document.write( '<a href="mosaics.asp?gallery=' + this.category + '&item=' + i + '"><img class="thumb-img" id="thumb-' + i + '" src="' + this.pitems[i].thumb.src + '" onmouseover="mypnav.thumbitemover('+i+')" onmouseout="mypnav.thumbitemout('+i+')" alt="'+ ((this.pitems[i].desc == "")?this.pitems[i].title:this.pitems[i].desc) +'" /></a><br /><img src="img/spacer.gif" width="120" height="2" /><br />' )
    }
  }

  this.writephoto = function( item, zoom ) {
    this.showcurrent()
    if( this.dynamic )
        document.write( '<img id="p-photo" src="' + this.pitems[0].imagepath + "1" + this.pitems[0].imageext + '" onmouseover="mypnav.imageover(-1)" onload="mypnav.onimageload()" />' )
    else
        document.write( '<img id="p-photo" src="' + this.pitems[item].imagepath + (parseInt(zoom) + 1) + this.pitems[item].imageext + '" onmouseover="mypnav.imageover(-1)" onload="mypnav.onimageload()" />' )
  }
}

//
// scroll image table
//

function TALayer_scroll(el, x, y, a, b, c, s) { //vTA
  var g,elo=el,f="",m=false,d="";x=parseInt(x);y=parseInt(y);
  var t = 'g.TAscroll = setTimeout("TALayer_scroll(\''+elo+'\','; 
  g=document.getElementById(el)
  d=(document.layers)?g:g.style;
  if (parseInt(s)>0) {
    eval(t+x+','+y+','+a+','+b+','+c+',0)",' + s+')');
    return;
  }
  var xx=(parseInt(d.left))?parseInt(d.left):0;
  var yy=(parseInt(d.top))?parseInt(d.top):0;
  if(parseInt(c)==1) {x+=xx;y+=yy;m=true;c=0;}
  else if (c==2) {m=false;clearTimeout(g.TAscroll);}
  else {var i=parseInt(a);
  if (eval(g.moved)){clearTimeout(g.TAscroll);}
  if (xx<x){xx+=i;m=true;if(xx>x){xx=x;}}
  if (xx>x){xx-=i;m=true;if(xx<x){xx=x;}}
  if (yy<y){yy+=i;m=true;if(yy>y){yy=y;}}
  if (yy>y){yy-=i;m=true;if(yy<y){yy=y;}}}
  if (m) {if((navigator.appName=="Netscape") && parseInt(navigator.appVersion)>4){
    xx+="px";yy+="px";}
  d.left=xx;d.top=yy;g.moved=true;eval(t+x+','+y+','+a+','+b+','+c+',0)",'+b+')');
  }else {g.moved=false;}
}

// <_ehcquerystring.js>

//
// query search string in page url
// http://www.eggheadcafe.com/articles/20020107.asp
//

function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
		else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
			return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; } 
}

function queryString(key){
	var page = new PageQuery(window.location.search);
	return unescape(page.getValue(key)); 
}

// <end _ehcquerystring.js>
