// ============================================================================
// Utility method binding functions taken from
// http://www.brockman.se/writing/method-references.html.utf8
// ============================================================================
var browser = new Browser();

function concat()
{
  var result = [];

  for (var i = 0; i < arguments.length; i++)
    for (var j = 0; j < arguments[i].length; j++)
      result.push(arguments[i][j]);

  return result;
}

// ============================================================================
function withoutFirst(sequence)
{
  result = [];

  for (var i = 1; i < sequence.length; i++)
    result.push(sequence[i]);

  return result;
}

// ============================================================================

function Cons(element, sequence)
{
  return concat([element], sequence);
}

// ============================================================================
Function.prototype.bind = function (object)
{
  var method = this;
  var preappliedArguments = withoutFirst(arguments);
  return function ()
  {
    return method.apply(object, concat(preappliedArguments, arguments));
  }
}

// ============================================================================
Function.prototype.bindEventListener = function (object) {
  var method = this;
  var preappliedArguments = withoutFirst(arguments);
  return function (event)
  {
    return method.apply(object, Cons(event || window.event, preappliedArguments));
  }
}

// ============================================================================

function setAlphaPNG( p_imgTag, p_src )
{
  if ( browser.isIE )
  {
    p_imgTag.src = '/img/pixel.gif';
    p_imgTag.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader"+
                            "(src='"+p_src+"',sizingMethod='image')";
      //# "image": Keep the original size of the image.
      //# "scale": Stretch or compress the image to the container boundaries.
      //# "crop": Crop the image to the container dimensions.
  } else
  {
    p_imgTag.src = p_src;
  }
}

// ============================================================================

function setAlphaBackgroundPNG( p_Tag, p_src )
{
  if ( browser.isIE )
  {
    p_Tag.style.backgroundImage = 'none';
    p_Tag.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader"+
                         "(src='"+p_src+"',sizingMethod='scale')";
  } else
  {
    p_Tag.style.backgroundImage = "url('"+p_src+"')";
  }
}

// ============================================================================
// Determine browser and version.
function Browser()
{
  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.isOP    = false;
  this.name    = navigator.appName;
  this.version = null;

  ua = navigator.userAgent;
  //alert(navigator.vendor);

  // Firefox:
  // Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6

  // Explorer:
  // Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)

  // Opera:
  // Mozilla/4.0 (compatibile; MSIE 6.0; Windows NT 5.1; en) Opera 8.50

  if ((navigator.userAgent).indexOf("Opera")!=-1)
  {
    this.isOP = true;
  } else
  if (navigator.appName=="Netscape")
  {
    this.isNS = true;
    //s = "Netscape6/";
    //this.version = parseFloat(ua.substr(i + s.length));
  } else
  if ( (navigator.appName).indexOf("Microsoft") != -1 )
  {
    this.isIE = true;
    //s = "MSIE";
    //this.version = parseFloat(ua.substr(i + s.length));
  }

  return;
}

