function checkImage(imgSrc,dimension)
{
  var newImg = new Image();
  newImg.src = imgSrc;
  height = newImg.height;
  width = newImg.width;  
  if (height > width)
     return 'height="' + dimension + '"';
  else
     return 'width="' + dimension + '"';    

}

function onGetStock(restriction) {
  var images, image, href, width, height, limiter, title, source;
  var html = '';
  for (var x = 0, len = items.length; x < len; ++x) {		 
    if (restriction && (restriction != items[x].CATEGORY) )
       continue;
    href = 'index.php?location=item&item=' + items[x].S_ID;
    if (restriction)
      href += '&art=' + restriction;
    source = items[x].SOURCE;
    href += '&source=' + source;
    if (source == 2)
        images = imageroot2;
      else
        images = imageroot;
    image = images + '/items/' + items[x].S_ID + '.JPG';
    
    title = items[x].TITLE;
    html += '<div class="gallery_floatpic" onclick="window.location=\'' + href + '\'">';
    html += '<div class="imageheight2">';    
    html += '<a href="' + href + '">';
    html += '<img src="' + image + '" alt="' + title + '" border="0" onload="setImageDimension(this,130)" /></a>';    
    html += '</div>';    
    html += '<br><p>' + title + '</p>';
    html += '</div>';  
  }
  $('displaypic').innerHTML = html;
  if (restriction) {
     $('restrict_none').removeClassName('artist_type_header_active');
     $('restrict_none').addClassName('artist_type_header');
     
     var menus = $$('#artist_page_full_width_top span');
     menus.each(function(s) {
        if (s.innerHTML == restriction) {
           s.addClassName('artist_type_header_active');
           s.removeClassName('artist_type_header');
        } else {
           s.addClassName('artist_type_header');
           s.removeClassName('artist_type_header_active');
        }
      });
     
  } else {          
     var menus = $$('#artist_page_full_width_top span');
     menus.each(function(s) {        
           s.addClassName('artist_type_header');
           s.removeClassName('artist_type_header_active');        
      });
     $('restrict_none').addClassName('artist_type_header_active');
     $('restrict_none').removeClassName('artist_type_header');
  }
}

function onGetEventStock(event, items) {
  var images, image, href, width, height, limiter, title, source;
  var html = '';
  for (var x = 0, len = items.length; x < len; ++x) {		 
    href = 'index.php?location=item&item=' + items[x].S_ID;
    source = 2;
    href += '&source=' + source;    
    images = imageroot2;
    image = images + '/items/' + items[x].S_ID + '.JPG';
    
    title = items[x].TITLE;
    html += '<div class="gallery_floatpic" onclick="window.location=\'' + href + '\'">';
    html += '<div class="imageheight2">';    
    html += '<a href="' + href + '"><img src="' + image + '" alt="' + title + '" border="0" onload="setImageDimension(this,130)" /></a>';
    html += '</div>';    
    html += '<br><p>' + title + '</p>';
    html += '</div>';  
  }
  $('displaypic').innerHTML = html;
}

function setImageDimension(image,dimension) {
  var height = image.height;
  var width = image.width;  
  if (height > width)
     image.height=dimension;
  else
     image.width=dimension;
}


function onGetArtists(args) {
//args: category,subcategory,page

  var imgfolder, image;
  var href, width, height;
  var title, source, name, title, cat, id, cid, start, end, hovercall;
  var html = '<div id="displaypic">';
  
  if (args.page) {
     start = (args.page * 12) - 12;
     end = start + 12;
     page = args.page;
  } else {
     start = 0;
     end = 12;
     page = 1;
  }
  
  pages = Math.ceil(artists.length / 12);
  if (pages > 1)
    $('navtools').show();      

  for (var i = start, len = artists.length; i < len && i < end; ++i) {		 
    name = artists[i].FULL_NAME;
    title = artists[i].TITLE.gsub('"', '');
    title = title.gsub('\'', '\\\'');
    title = title.escapeHTML();
    cat = artists[i].CATEGORY;
    id = artists[i].S_ID;
    source = artists[i].SOURCE;
    cid = artists[i].C_ID;
    
    href = 'index.php?location=artist&artist=' + cid;
    if (args.category)
      href += '&type=' + args.category;
    if (args.subcategory)
      href += '&subtype=' + args.subcategory;
    if (artists[i].SUB_ID)
      href += '&sub=' + artists[i].SUB_ID;
    href += '&source=' + source;
    if (source == 2)
      imgfolder = imageroot2;
    else
      imgfolder = imageroot;
    image = imgfolder + '/artists/' + cid + '.JPG';
    
    hovercall = '\'' + name + '\', ' + id + ', \'' + title + '\', \'' + cat + '\', ' + source;    
    
    //html += '<a href="' + href + '">';
    html += '<div class="gallery_floatpic" onmouseover="artistHover(' + hovercall + ')" onclick="window.location=\'' + href + '\'">';
    html += '<div class="imageheight">';
    html += '<a href="' + href + '">';
    html += '<img src="' + image + '" onload="setImageDimension(this,130)" border="0">';
    html += '</a>';
    html += '</div><!-- imageheight -->';
    html += '<p>' + name + '</p>';
    html += '</div><!-- gallery-floatpic -->';
    //html += '</a>';  
  }
  html += '</div><!-- displaypic -->';    
  
  $('left_images').innerHTML = html;
  
  $('page').innerHTML = page;
  $('pages').innerHTML = pages;
}

function onGetItems(subtype) {
  var images, image, href, width, height, limiter, title, source;
  var html = '';
  for (var x = 0, len = items.length; x < len; ++x) {		 
    href = 'index.php?location=item&item=' + items[x].S_ID;
    source = items[x].SOURCE;
    href += '&source=' + source;
    if (source == 2)
        images = imageroot2;
      else
        images = imageroot;
    image = images + '/items/' + items[x].S_ID + '.JPG';
    //limiter = checkImage(image, 130);
    title = items[x].TITLE;
    artistId = items[x].C_ID;
    artist =items[x].FULL_NAME;
    //html += '<a href="' + href + '">';
    html += '<div class="gallery_floatpic" style="height:195px" onclick="window.location=\'' + href + '\'">';
    html += '<div class="imageheight2">';
    html += '<a href="' + href + '">';
    html += '<img src="' + image + '" alt="' + title + '" border="0" onload="setImageDimension(this,130)"/>';
    html += '</a>';
    html += '</div>';    
    html += '<br><p>' + title + '<br>' + artist + '</p>';
    html += '</div>';
    //html += '</a>';  
  }
  $('displaypic').innerHTML = html;
}
