/****************************************
  ImgBar V1.0
  Copyright (C) 2007   Steve H
  http://www.fullvolume.co.uk/
  
  Instructions for use:
  http://www.fullvolume.co.uk/scripts/imgbar/
  ****************************************
  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  http://www.gnu.org/copyleft/gpl.html
****************************************/

var osize;
var hsize;
var icur;

function set_stylebar(imgbar,l,h,u_step,d_step,u_time,d_time) {
    var stylebar = document.getElementById(imgbar);
    var links = stylebar.getElementsByTagName('a');
    var img;
    
    if (!u_step) {u_step = 2;}
    if (!d_step) {d_step = -1;}
    if (!u_time) {u_time = 25;}
    if (!d_time) {d_time = 30;}
    if (u_step < 0) {u_step = u_step * -1;}
    if (d_step > 0) {d_step = d_step * -1;}
    osize = l;
    hsize = h;
    
    for (var x=0;x<links.length;x++) {
        img = links[x].getElementsByTagName('img')[0];
        img.setAttribute('id','sbimg_' + x);
        img.height = osize;
        img.onmouseover = function () {
            icur = this.id;
            setTimeout("sizestep(\"" + this.id + "\"," + hsize + "," + u_step + "," + u_time + ")",50);
        }
        img.onmouseout = function () {
            icur = this.id;
            setTimeout("sizestep(\"" + this.id + "\"," + osize + "," + d_step + "," + d_time + ")",50);
        }
    }
}

function sizestep(id,until,step,time,check,err) {
    var obj = document.getElementById(id);
    if (check) {
        if ( (check != obj.height) && (id == icur) ) {
            return; // Don't conflict bigger and smaller
        } else if (check != obj.height) {
            if ( (err > ((hsize-osize)+2)) && (step > 0) ) {
                return; // Panic
            }
            if (!err) {err = 0;}
            err = err + 1;
        }
    } else {
        if ( (step > 0) && (id != icur) ) {
            return; // Moved on already, what's the point?
        }
    }
    if (step < 0) {
        if (obj.height <= until) {
            obj.height = until;
            return;
        }
    } else {
        if (obj.height >= until) {
            obj.height = until;
            return;
        }
    }
    obj.height = obj.height + step;
    setTimeout("sizestep(\"" + obj.id + "\"," + until + "," + step + "," + time + "," + obj.height + "," + err + ")",time);
}