


// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var has_init = false;

function init() {

  if (typeof log != "undefined")
    log('init');

  if (has_init) return;
	
  has_init = true;

  // quit if this function has already been called
  if (arguments.callee.done) return;

  // flag this function so we don't do the same thing twice
  arguments.callee.done = true;

  // kill the timer
  if (_timer) clearInterval(_timer);


  if (typeof LoadBasket != "undefined")
    LoadBasket();

  try {
    sign = new Sign();
    sign.fixed_price = 0;
  } 
  catch (e) {
  }

  if (typeof pre_load_page != "undefined") {
    pre_load_page();
  }

  if (typeof  init_js_sign != "undefined")
    init_js_sign();
		
  if (typeof load_page != "undefined") {
    load_page();
  }

  if (typeof log != "undefined")
    log('init done');
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", init, false);
}

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
  var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
      init(); // call the onload handler
    }
  }, 10);
}

/* for other browsers */
window.onload = init; 

if(!Array.indexOf){
  Array.prototype.indexOf = function(obj){
    for(var i=0; i<this.length; i++){
      if(this[i]==obj){
        return i;
      }
    }
    return -1;
  }
}
/*
if(!String.indexOf){
	    String.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}
*/

var Prototype = {
  Version: '1.6.0.1',

  Browser: {
    IE:     !!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
  },

  BrowserFeatures: {
    XPath: !!document.evaluate,
    ElementExtensions: !!window.HTMLElement,
    SpecificElementExtensions:
    document.createElement('div').__proto__ &&
    document.createElement('div').__proto__ !==
    document.createElement('form').__proto__
  },

  ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
  JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,

  emptyFunction: function() { },
  K: function(x) {
    return x
  }
};


function launch(file,name,winwidth,winheight)      
{ 
  var string= 
  "width=" + winwidth + ",height=" + winheight +
  "toolbar=no, directories=no, menubar=no, resizable=yes, dependent=yes, scrollbars=yes"  

  hwnd = window.open(file, name, string);

  if (navigator.appName == "Netscape") { 
    hwnd.focus() 
  } 
} 

function $$(element) {
  if (arguments.length > 1) {
    for (var i = 0, elements = [], length = arguments.length; i < length; i++)
      elements.push($(arguments[i]));
    return elements;
  }
  if (Object.isString(element))
    element = document.getElementById(element);
  return element;
}

function $A(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) return iterable.toArray();
  var length = iterable.length, results = new Array(length);
  while (length--) results[length] = iterable[length];
  return results;
}

Object.extend = function(destination, source) {
  for (var property in source)
    destination[property] = source[property];
  return destination;
};


Object.extend(Object, {

  keys: function(object) {
    var keys = [];
    for (var property in object)
      keys.push(property);
    return keys;
  },
  isString: function(object) {
    return typeof object == "string";
  },

  isFunction: function(object) {
    return typeof object == "function";
  }
}
);


/* Based on Alex Arnell's inheritance implementation. */
var Class = {
  create: function() {
    var parent = null, properties = $A(arguments);
    if (Object.isFunction(properties[0]))
      parent = properties.shift();

    function klass() {
      this.initialize.apply(this, arguments);
    }

    Object.extend(klass, Class.Methods);
    klass.superclass = parent;
    klass.subclasses = [];

    if (parent) {
      var subclass = function() { };
      subclass.prototype = parent.prototype;
      klass.prototype = new subclass;
      parent.subclasses.push(klass);
    }

    for (var i = 0; i < properties.length; i++)
      klass.addMethods(properties[i]);

    if (!klass.prototype.initialize)
      klass.prototype.initialize = Prototype.emptyFunction;

    klass.prototype.constructor = klass;

    return klass;
  }
};

Class.Methods = {
  addMethods: function(source) {
    var ancestor   = this.superclass && this.superclass.prototype;
    var properties = Object.keys(source);

    if (!Object.keys({
      toString: true
    }).length)
      properties.push("toString", "valueOf");

    for (var i = 0, length = properties.length; i < length; i++) {
      var property = properties[i], value = source[property];
      if (ancestor && Object.isFunction(value) &&
        value.argumentNames().first() == "$super") {
        var method = value, value = Object.extend((function(m) {
          return function() {
            return ancestor[m].apply(this, arguments)
          };
        })(property).wrap(method), {
          valueOf:  function() {
            return method
          },
          toString: function() {
            return method.toString()
          }
        });
      }
      this.prototype[property] = value;
    }

    return this;
  }
};

function getOffset(what)
{
  result = [];
  if (what == null) return;
		
		
  result.x = what.offsetLeft;
  result.y = what.offsetTop;
  result.w = what.offsetWidth;
  result.h = what.offsetHeight;
		
  parentEl = what.offsetParent
  while (parentEl != null)
  {
    result.x += parentEl.offsetLeft;
    result.y += parentEl.offsetTop;
    parentEl = parentEl.offsetParent;
  }

  return result;
}

function drop_down(id, x_diff, millisec){
  var speed = Math.round(millisec / 100);
  var timer = 0;

  for(var i = 0; i < x_diff; i++) {
    setTimeout("changeTopPosition(" + (i * 3) + ",'" + id + "')",(timer * speed));
    timer++;
  }
  setTimeout("changeTopPosition(0,'" + id + "')",(timer * speed));
}

function opacity(id, opacStart, opacEnd, millisec) {
	
  //speed for each frame
  var speed = Math.round(millisec / 100);
  var timer = 0;

  //determine the direction for the blending, if start and end are the same nothing happens
  if(opacStart > opacEnd) {
    for(i = opacStart; i >= opacEnd; i--) {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
      timer++;
    }
  } else if(opacStart < opacEnd) {
    for(i = opacStart; i <= opacEnd; i++)
    {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
      timer++;
    }
  }
  else
  {
    for(i = opacStart; i >= 0; i--) {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
      timer++;
    }
    for(i = 0; i <= opacStart; i++) {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
      timer++;
    }
  }
}

function to_opacity(id, opacEnd, millisec){
  var object = document.getElementById(id).style;
	
  if (object.opacity != (opacEnd / 100))
  {
    opacity(id, object.opacity * 100, opacEnd, millisec);
  }
}

function opacity_link(id, link)
{
  opacity(id, 100, 0, 100);
  setTimeout("document.location = '" + link + "';", 100);
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
  var object = document.getElementById(id).style;
  object.opacity = (opacity / 100);
  object.MozOpacity = (opacity / 100);
  object.KhtmlOpacity = (opacity / 100);
  if (opacity != 100)
    object.filter = "alpha(opacity=" + opacity + ")";
  else
    object.filter = "";
			
  if (opacity == 1)
    object.visibility = "visible";
} 

function changeTopPosition(top_position, id) {
  var object = document.getElementById(id).style;
  object.top = top_position + "px";
}

function show_image(_image)
{
  changeOpac(0, 'large_img_div')
  $$('large_img').src = '';
  $$('large_img').src = '/images/example/' + _image + '.jpg';
  $$('large_img_div').style.display = "block";
  opacity('large_img_div', 0, 100, 600)
}

function hide_image()
{
  changeOpac(0, 'large_img_div')
  $$('large_img_div').style.display = "none";
}

/**
 * This function returns an array of objects that contain the information about call stack.
 */
function callstack() {
  function StackFrame(funcName, funcSource, flName, lnNumber) {
    this.functionName = funcName;
    this.functionSource = funcSource;
    this.fileName = flName;
    this.lineNumber = lnNumber;
  }
  StackFrame.prototype.toString = function() {
    return 'at ' + this.functionName + '(' + this.fileName + ':' +  this.lineNumber + ')' ;
  };
  StackFrame.prototype.toHtml = function() {
    return '<table border="0">' +
    '<tr valign="top"><td><b>Name:  </b></td><td>'           + this.functionName                + '</td></tr>' +
    '<tr valign="top"><td><b>File:  </b></td><td>'           + this.fileName                    + '</td></tr>' +
    '<tr valign="top"><td><b>Line:  </b></td><td>'           + this.lineNumber                  + '</td></tr>' +
    '<tr valign="top"><td><b>Source:</b></td><td>' +
    ( this.functionSource ?
      '<pre>' + this.functionSource.toString().replace(/\</g, '&lt;').replace(/\>/g, '&gt;') + '</pre>' :
      'unavailable')                                                                            + '</td></tr>' +
    '</table>'
  ;

  };
  var stackFrameStrings = new Error().stack.split('\n');
  // remove first two stack frames
  stackFrameStrings.splice(0,2);
  var stackFrames = [];
  for (var i in stackFrameStrings) {
    // a stack frame string split into parts
    var stackFrame = stackFrameStrings[i].split('@');
    if (stackFrame && stackFrame.length == 2) {
      stackFrames.push(
        // Stackframe object
        new StackFrame(stackFrame[0],
          eval(stackFrame[0].replace(callstack.sansParenthesisRE,'')),
          stackFrame[1].match(callstack.fileNameLineNumberRE)[1], // first group
          stackFrame[1].match(callstack.fileNameLineNumberRE)[2]  // second group
          )
        );
    }
  }
  return stackFrames;
}
callstack.sansParenthesisRE = /[(][^)]*[)]/;
callstack.fileNameLineNumberRE = /(.*):(\d+)$/;

function color_to_text(_color)
{
  switch (_color.toLowerCase())
  {
    case "#e4e4e4":
      return $$('c_frosted').innerHTML;
    case "#f0f0f0":
      return $$('c_transparent').innerHTML;
    case "#fefefe":
      return "";

    case "#bbb":
      return $$('c_silver').innerHTML;
    case "#ddd":
      return $$('c_aluminium').innerHTML;
    case "#141414":
    case "#000":
      return $$('c_black').innerHTML;
    case "#fff":
      return $$('c_white').innerHTML;
    case "#004f86":
      return $$('c_blue').innerHTML;
    case "#f00":
    case "#c4271d":
      return $$('c_red').innerHTML;
    case "#009251":
      return $$('c_green').innerHTML;
    case "#ff0": 
    case "#fee900":
      return $$('c_yellow').innerHTML;
    case "#e15616":
      return $$('c_orange').innerHTML;
    case "#554585":
      return $$('c_purple').innerHTML;
    case "#4f575b":
      return $$('c_grey').innerHTML;
    case "#daa520":
      return $$('c_gold').innerHTML;
  }

  return _color;
}

