//<![CDATA[
// Created in Shogo.Ru
var makeColors = function(){var self=this; if(this.isMSIE) self.init(); else if(this.isSafari) this.observe(window, 'load', function(){self.init()}); else this.observe(window, 'DOMContentLoaded', function(){self.init()})}
makeColors.prototype = {
  els: ['source','kists','baloons'],
  isMSIE: ((document.all && document.all.item && !(window.opera && document.getElementById)) ? true : false),
  isSafari: (navigator.vendor && navigator.vendor.toLowerCase().indexOf('apple')>=0 ? true : false),
  imgcache: {},
  init: function() {
    this.fixPNG();
    var allL = this.getChilds(this.els[1]), allB = this.getChilds(this.els[2]);
    this.createCache(allL,true);
    this.createCache(allB);
    this.activate(allL,true);
    this.activate(allB);
},
  observe: function(n, e, h) {
    if(n.addEventListener) n.addEventListener(e, h, false);
    else if(n.attachEvent) n.attachEvent('on'+e, h);
    return n;
},
  createCache: function(ar, lb) {
    for (var i=0; i<ar.length; i++) {
      if (lb) var im = this.getNewSrc(ar[i].firstChild,true); else var im = this.getNewSrc(ar[i].firstChild);
      this.imgcache[im] = new Image();
      this.imgcache[im].src = im;
      document.body.appendChild(this.imgcache[im]);
      this.imgcache[im].style.display = 'none'; }
},
  getChilds: function(el, cls) {
    if (!el) return false;
    var el = document.getElementById (el), ret = [];
    for (var i=0; i<el.childNodes.length; i++) {
      if ((el.childNodes[i].nodeType == 1) && (!cls || (el.childNodes[i].className == cls))) ret.push (el.childNodes[i]); }
    return ret;
},
  activate: function(els, lb) {
    var self = this;
    for (var i=0; i<els.length; i++) {
      var obj = els[i].firstChild;
      obj.style.cursor = 'pointer';
      this.observe(obj, 'click', function(e) {
        e.returnValue = false;
        e.cancelBubble = true;
        if(e.preventDefault)  e.preventDefault();
        if(e.stopPropagation) e.stopPropagation();
        if (lb) self.logosCh(e.target || e.srcElement); else self.balsCh(e.target || e.srcElement);
      });
    }
},
  getNewSrc: function(obj, lb) {
    var sR = obj.src, newSrc = false;
    if (lb) newSrc = sR.replace(/(.*)kist_(.*)\.gif/gim, "$1logo_$2\.png"); else newSrc = sR.replace(/(.*)\.gif/gim, "$1_bg\.png");
    return newSrc;
},
  fixPNG: function() {
    if (this.isMSIE) {
      var out = document.getElementById(this.els[0]).firstChild, old = out.src;
      out.src = 'i/sp.gif';
      out.runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+old+'",sizingMethod="scale")'; }
},
  logosCh: function(s) {
    document.getElementById(this.els[0]).firstChild.src = this.getNewSrc(s,true);
    this.fixPNG();
},
  balsCh: function(s) {
    document.getElementById(this.els[0]).style.background = 'url("'+this.getNewSrc(s)+'")';
}
};makeColors = new makeColors();
//]]>
