foo = {
  
  /*core*/
  $: function(e){
    /* short version for document.getelementbyId */
    if (typeof e == 'string')
      return document.getElementById(e);
    else
      return e;
  },
    
  /* создание объекта для поддержки цепочек getFirst getNext getPrevious и удобной обработки действий над объектами DOM */
  $$: function(e){
    return new foo.ext.create(this.$(e));
  },
  
  /*готовность dom элементов на странице*/
  addEvent: function(fn){
    this.domready.add(fn);
  },
  
  // crossbrowser domready thanks to -- Dean Edwards/Matthias Miller/John Resig --
  // http://deanedwards.me.uk/weblog/2006/06/again/
  domready:{
    init: function(){
      var _fn = function(){
        // domready activated
        // 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 (this._timer) clearInterval(this._timer);

        //do stuff
        for(var i = this.hash.length;i--;)
          this.hash[i].call();
      }.wrap(this);
      
      /* for Mozilla/Opera9 */
      if (document.addEventListener)
      	document.addEventListener("DOMContentLoaded", _fn, false);
      
      /* for Internet Explorer */
      /*@cc_on @*/
      /*@if (@_win32)
          	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
          	var script = document.getElementById("__ie_onload");
          	script.onreadystatechange = function() {
          		if (this.readyState == "complete") {
          			_fn(); // call the onload handler
          		}
          	};
              /*@end @*/

      /* for Safari */
      if (/WebKit/i.test(navigator.userAgent)) // sniff
      	this._timer = setInterval(function(){
      		if (/loaded|complete/.test(document.readyState))
      			_fn(); // call the onload handler
      	}, 10);

      /* for other browsers */
      window.onload = _fn;
    },
    
    hash:[],
    
    add:function(fn){
      this.hash.push(fn);
    }
  },
  
  /* инициализация доп функций */
  preload:function(pref){
  
    if(pref && !window[pref])
      window[pref] = function(e){
        return foo.$$(e);
      };
  
    if(!window['$'])
      $ = function(e){
        return foo.$(e);
      };
    
    Function.prototype.wrap = function(scope){
      var _ = this;
      return function(){
        return _.apply(scope, arguments);
      }
    };
  },

  init:function(prefix){
    this.preload(prefix);
    this.domready.init();
  }
};

foo.init();

function fooSetCookie( name, value, expires, path, domain, secure ){
  // set time, it's in milliseconds
  var today = new Date();
  today.setTime( today.getTime() );

  /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
  if ( expires )
    expires = expires * 1000 * 60 * 60 * 24;
  var expires_date = new Date( today.getTime() + (expires) );

  document.cookie = name + "=" +escape( value ) +
  ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
  ( ( path ) ? ";path=" + path : "" ) +
  ( ( domain ) ? ";domain=" + domain : "" ) +
  ( ( secure ) ? ";secure" : "" );
};

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function fooGetCookie( check_name ){
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ ){
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ){
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
		return null;
};

function winSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return {'width':myWidth,'height':myHeight};
};

function getScrollXY() {
  var scrOfX = document.body.scrollWidth;
  var scrOfY = document.body.scrollHeight;
  return {'x':scrOfX,'y':scrOfY};
};

window.onload = function(){
//foo.addEvent(function(){
  if(fooGetCookie("kmkonkurs"))
    return;
  var _ = document.createElement('div');
  _.id = "overlay";
  _.style.height = getScrollXY().y + 'px';
  _.style.width = getScrollXY().x + 'px';
  _.style.width = '100%';
  _.style.position = 'absolute';
  _.style.zIndex = '100';
  _.style.top = '0px';
  _.style.left = '0px';
  _.style.backgroundColor = '#000';
  _.style.opacity = '0.3';
  _.style.display='block';
  _.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=30)';
  document.body.appendChild(_);
  
  /* ie6 */
  //if (typeof document.body.style.maxHeight == "undefined"){
    _ = document.createElement('iframe');
    _.id = "ifoverlay";
    _.style.height = getScrollXY().y + 'px';
    _.style.width = getScrollXY().x -5 + 'px';
    _.style.position = 'absolute';
    _.style.zIndex = '100';
    _.style.top = '0px';
    _.style.left = '0px';
    _.style.opacity = '0';
    _.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
    document.body.appendChild(_);
  //}
  
  var _ = document.createElement('div');
  _.style.top = '-1500px';
  _.style.left = '-1500px';
  if (typeof document.body.style.maxHeight == "undefined")
    _.style.position = 'absolute';
  else
    _.style.position = 'fixed';
  _.style.zIndex = '120';

  _.innerHTML = '<input type="button" id="dkmkonkurs" style="'+
    'position:absolute;'+
    'top:5px;'+
    'right:5px;'+
    'z-index:1;'+
    'font-family:\'Tahoma\';'+
    'font-size:12px;"'+
    //'text-decoration:underline;"'+
    /* на домен km.ru */
    //(/MSIE/.test(navigator.userAgent)?'onclick="fooSetCookie(\'kmkonkurs\',\'1\',365,\'/\');':'onclick="fooSetCookie(\'kmkonkurs\',\'1\',365,\'/\',\'km.ru\');')+
    /* на домен ***.km.ru */
    (/MSIE/.test(navigator.userAgent)?'onclick="fooSetCookie(\'kmkonkurs\',\'1\',365);':'onclick="fooSetCookie(\'kmkonkurs\',\'1\',365);')+
    "$('kmkonkurs').style.display='none';"+
    "$('dkmkonkurs').style.display='none';"+
    "$('overlay').style.display='none';"+
    "if($('ifoverlay'))$('ifoverlay').style.display='none';"+
    'return false;" value="Закрыть опрос">'+
    
    '<iframe id="kmkonkurs" style="'+
    'border:1px gray solid;'+
    'background-color:white;'+
    'width:530px;'+
    'height:370px;" frameborder="0" scrolling="no" src="http://konkurs.km.ru/kmportals/"></iframe>';
    
  document.body.appendChild(_);
  _.style.top = winSize().height/2 - _.offsetHeight/2 + 'px';
  _.style.left = winSize().width/2 - _.offsetWidth/2 + 'px';
  if (typeof document.body.style.maxHeight == "undefined")
    setInterval(function(){
      _.style.top = winSize().height/2 - _.offsetHeight/2 + document.body.scrollTop + 'px';
      _.style.left = winSize().width/2 - _.offsetWidth/2 + 'px';
    }.wrap(_),1000);
};