 var $myextend = function(){var args = arguments;if(!args[1]) args = [this, args[0]];for(var property in args[1]) args[0][property] = args[1][property];return args[0];};
 var $mybrowser = {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}
 var MyClass = function(properties){var klass = function(){return this.initialize.apply(this, arguments);};$myextend(klass, this);klass.prototype = properties;klass.constructor = MyClass;return klass;};

 String.prototype.escapeRegExp = function(){return this.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');}
 String.prototype.mysubstr = function(from,len){return len>-1?this.substr(from, len):this;}
 String.prototype.format = function(a){var ret=this;for(key in a){ret=ret.replace('%'+key+'%',a[key]);}return ret;};
 Array.prototype.indexOf = function(item, from){for (var i = (from < 0) ? Math.max(0, len + from) : from, len = this.length || 0; i < len; i++){if (this[i] === item) return i;}return -1;}

 var $replace = function(element, obj){
    if(element.outerHTML) element.outerHTML = obj.outerHTML;
    else element.parentNode.replaceChild(obj, element);
    return element;
  }

 var Cookie = new MyClass({
  initialize: function(key, value){if(key!=undefined&&value!=undefined)this.set(key, value);},
        set: function(key, value, duration){value = encodeURIComponent(value);if (duration){var date = new Date();date.setTime(date.getTime() + duration * 24 * 60 * 60 * 1000);value += '; expires=' + date.toGMTString();}document.cookie = key + '=' + value;return this;},
        get: function(key){var value = document.cookie.match('(?:^|;)\\s*' + key.escapeRegExp() + '=([^;]*)');return value ? decodeURIComponent(value[1]) : false;},
        remove: function(cookie, options){this.set(cookie, '', -1);return this;}
 }); var cookie = new Cookie();

 var detectFlash = function(ver) {
    //return false; /// test mode
    if($mybrowser.ie) try{return typeof new ActiveXObject('ShockwaveFlash.ShockwaveFlash.'+ver)=='object';} catch(e){ }
    else try{ return parseInt(navigator.plugins['Shockwave Flash'].description.split(" ")[2]) >= ver; } catch(e){ }
    return false;
  }
 var isFlashDisabled = function(){return cookie.get('flash_is')=='off';}
 var setFlash = function(set){cookie.set('flash_is',(set&&set!='off')||set=='on'?'on':'off');}

 var parseFlashyVars = function(str){
   if(!str) return {};
   var ret = {};
   var arr = str.split(';');
   for (var i = 0, length = arr.length; i < length; i++){
      var a = arr[i].split(':');
      if(a[0].toLowerCase()!='urltovars'){
        if(a[0]=='rev'&&a[1]=='rnd') ret[a[0]]=parseInt(Math.random()*100000);
        else ret[a[0]]=a[1];
      } else {
        var tmp = document.location.href.split('//')[1].split('?')[0];
        tmp = tmp.substr(tmp.indexOf('/')+1,10000);
        ret[a[0]]=tmp;
      }
   }
   return ret;
 }


 var objectsSwap = function(){
    var objects = document.getElementsByTagName('object');
    var arr = [];
    for (var i = 0, length = objects.length; i < length; i++){
       arr.push(objects[i]);
    }
    for (var i = 0, length = arr.length; i < length; i++){
       objectSwap(arr[i]);
    }
 }
 var objectSwap = function(obj){
    if(!obj.getAttribute('classid')){return false;}
    if(obj.className.indexOf('donttouch')>-1){return false;}
    var vars = parseFlashyVars(obj.getAttribute('flashy'));

    var ver = parseInt(obj.getAttribute('codebase').substring(obj.getAttribute('codebase').indexOf(',')-1));
    if(isFlashDisabled()||!detectFlash(ver)){
      var child = obj.firstChild;
      var movie = 0;
      while(child&&child.tagName!='DIV'){
         if(child.tagName=='PARAM'&&child.getAttribute('name')=='movie') movie = child.getAttribute('value');

         child = child.nextSibling;
      }

      if($mybrowser.ie){
         var start = obj.innerHTML.toLowerCase().indexOf("<div");
         var len = obj.innerHTML.toLowerCase().lastIndexOf("div>");
         if(len>0&&start>0){
           var div = obj.innerHTML.substr(start, len+4);
           var imgnode = document.createElement('div');
           imgnode.innerHTML = div;
           child = imgnode.firstChild;
         } else {child = false;}
      }
      if(child){child.style.display = ''; $replace(obj, child)}
      else if(movie){
      var imgnode = document.createElement('img');
      imgnode.setAttribute('src', vars['pic']||(movie.mysubstr(0,movie.indexOf('?'))+'.'+(vars['ext']||'gif')));
      imgnode.setAttribute('width', obj.getAttribute('width'));
      imgnode.setAttribute('height', obj.getAttribute('height'));
      imgnode.onerror = function(){this.parentNode.removeChild(this);}

      $replace(obj, imgnode);
      }

    } else if($mybrowser.gecko){
      var child = obj.firstChild;
      while(child&&child.tagName!='EMBED'){ child = child.nextSibling; }
      if(child){
        if(child.getAttribute('src').indexOf('?')>-1)
          child.setAttribute('src',child.getAttribute('src')+'&revision='+vars['rev']);
        else
          child.setAttribute('src',child.getAttribute('src')+'?revision='+vars['rev']);

        if(vars['urltovars'])
          if(child.getAttribute('flashvars')) child.setAttribute('flashvars',child.getAttribute('flashvars')+'&swfURL='+vars['urltovars']);
          else child.setAttribute('flashvars','swfURL='+vars['urltovars']);
        if(obj.getAttribute('style')){child.setAttribute('style',obj.getAttribute('style'));}
        $replace(obj, child)
      }

    } else {
      var newobj = document.createElement('object');
      for(var i=0, j=obj.attributes.length; i<j; i++){
        if(obj.attributes[i].specified)
          newobj.setAttribute(obj.attributes[i].name,obj.attributes[i].value);
      }

      if($mybrowser.ie){
         // копировать стиль!!!
      }

      var param = obj.firstChild; var isflashvars = false;
      while(param){
         if(param.tagName == 'PARAM'){
          var paramnode = document.createElement('param');
          paramnode.setAttribute('name', param.getAttribute('name'));
          if(param.getAttribute('name')=='movie'&&vars['rev']){
            var tmp = (param.getAttribute('value').indexOf('?')>-1)?('&revision='+vars['rev']):('?revision='+vars['rev']);
            paramnode.setAttribute('value', param.getAttribute('value')+tmp);
          } else
            paramnode.setAttribute('value', param.getAttribute('value'));
          if(param.getAttribute('name')=='flashvars'&&vars['urltovars']){
             isflashvars = true;
             paramnode.setAttribute('value', param.getAttribute('value')+'&swfURL='+vars['urltovars']);
          }
          newobj.appendChild(paramnode);
         }
         param = param.nextSibling;
      }
      if(vars['urltovars']&&!isflashvars){
        var paramnode = document.createElement('param');
        paramnode.setAttribute('name', 'flashvars');
        paramnode.setAttribute('value', 'swfURL='+vars['urltovars']);
        newobj.appendChild(paramnode);
      }
      $replace(obj, newobj);
    }

 }


 var ff = window.onload||function(){}; window.onload = function(){objectsSwap(); ff()};
