var CORE = new Object();

var NatashaKapustina = false;
var NatashaPosting = false;
var LocalStartup = false;
var StartupQueue = new Array();

var FlashIsStaging = false;

var Chat = false;

CORE.init = function()
 {
  if (CORE.inited)
   return;

  CORE.inited = true;

  CORE.indication = 0;

  CORE.IE6 = false;

  CORE.originalTitle = document.title;
  CORE.flashing = false;
  CORE.flashCountdown = 0;

  if (Prototype.Browser.IE)
   CORE.IE6 = parseFloat(navigator.appVersion.split('MSIE')[1]) < 7 ? true : false;

  if (Tooltips)
   Tooltips.init();

  if (Player)
   Player.init();

/*
  if (CORE.IE6)
   {
    document.getElementsByClassName('iesucks').each(function(poElement)
     {
      alert(poElement);

      var cBGImg = poElement.currentStyle.backgroundImage;
      var cImage = cBGImg.substring(cBGImg.indexOf('"') + 1, cBGImg.lastIndexOf('"'));

      poElement.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + cImage + "', sizingMethod='scale')";
      poElement.style.backgroundImage = "none";
     });
   }
*/

//  if (GodsFinger)
//   GodsFinger.load('/login/?ajax=1');

  if (CORE.resizer)
   CORE.resizer();

  CORE.DisableKeyNav = false;
  CORE.goPrevious = false;
  CORE.goNext = false;

  if (KolbaskinStartsHere)
   setTimeout(KolbaskinStartsHere, 1);

  if (GodsFinger)
   GodsFinger.init();

  if (MISC)
   MISC.InstallRowsOver();

  if (LocalStartup)
   setTimeout(LocalStartup, 1);

  StartupQueue.push(CORE.FlashInit);

  for (var k = 0; k < StartupQueue.length; k++)
   {
    setTimeout(StartupQueue[k], 1);
   }

  Event.observe(document, 'keydown', function(event)
   {
    event = event ? event : window.event;

    if (!CORE.DisableKeyNav)
     if (event.ctrlKey)
      {
       switch (event.keyCode)
        {
         case 37:
          if (CORE.goPrevious)
           CORE.goPrevious();
          else if (a = $("previous_page"))
           if (a.href != '#')
            location.href = a.href;
         break;
         case 39:
          if (CORE.goNext)
           CORE.goNext();
          else if (a = $("next_page"))
           if (a.href != '#')
            location.href = a.href;
         break;
        }
      }
   });
 }

CORE.FlashInit = function()
 {
  var e = false;

  if (e = $('flash0'))
   new Effect.Highlight(e, { keepBackgroundImage: true });
 }

CORE.Title = function(s)
 {
  CORE.flashTitle = s;
  CORE.flashCountdown = 3; //9;

  document.title = CORE.flashTitle;

  if (CORE.flashTimeout)
   clearTimeout(CORE.flashTimeout);

  CORE.flashTimeout = setTimeout(CORE.TitleFlasher, 4000);
 }

CORE.TitleFlasher = function()
 {
  if (CORE.flashCountdown > 0)
   {
    CORE.flashCountdown--;

    if (CORE.flashCountdown == 0)
     {
      document.title = CORE.originalTitle;
     }
    else
     {
      if (CORE.flashCountdown % 2 == 0)
       {
        document.title = CORE.flashTitle;

        CORE.flashTimeout = setTimeout(CORE.TitleFlasher, 425);
       }
      else if (CORE.flashCountdown % 2 == 1)
       {
        document.title = '...';

        CORE.flashTimeout = setTimeout(CORE.TitleFlasher, 200);
       }
     }
   }
 }

CORE.WhatIsPodcasting = function(id)
 {
  if (!CORE.wipSeqID)
   CORE.wipSeqID = 1;

  CORE.wipSeqID++;

  if (CORE.wipSeqID > CORE.PodcastingIs.length)
   CORE.wipSeqID = 1;

  $(id).innerHTML = CORE.PodcastingIs[CORE.wipSeqID - 1];

  return false;
 }

CORE.PLi = function(k)
 {
  var b = $('pl' + k + '_1');
  b._pli_className = b.className;
  b.className = b.className + ' over';

  if (b2 = $('pl' + k + '_2')) b2.className = b.className;
  if (b3 = $('pl' + k + '_3')) b3.className = b.className;
 }

CORE.PLo = function(k)
 {
  var b = $('pl' + k + '_1');
  b.className = b._pli_className;

  if (b2 = $('pl' + k + '_2')) b2.className = b.className;
  if (b3 = $('pl' + k + '_3')) b3.className = b.className;
 }

CORE.resizer = function()
 {
  // featured podcasts
/*
  if (fp = $('featured_podcasts'))
   {
    var w = Element.getWidth($('mainmeter')) - 60;

    UniScroll.delta = w / 2;

    fp.style.width = w + 'px';
   }
*/
 }

CORE.StartIndication = function()
 {
  CORE.indication++;

  if (CORE.indication == 1)
   {
    var indicator = $('indicator');

    if (indicator)
     {
      indicator.className = 'indicator';
      indicator.style.display = 'block';
     }
   }
 }

CORE.StopIndication = function(error)
 {
  CORE.indication--;

  if (CORE.indication == 0)
   {
    var indicator = $('indicator');

    if (indicator)
     indicator.style.display = 'none';
   }

  if (error)
   {
    var indicator = $('indicator');

    if (indicator)
     {
      indicator.className = 'indicator indicator_error';
      indicator.style.display = 'block';
     }
   }
 }

CORE.StopIndicationWithSuccess = function()
 {
  CORE.StopIndication(false);

  if(Tooltips){
    Tooltips.close();
    Tooltips.rescan_delayed();
   }
 }

CORE.StopIndicationWithError = function()
 {
  CORE.StopIndication(true);

  if(Tooltips){
    Tooltips.close();
    Tooltips.rescan_delayed();
   }
 }

CORE.CommunityOperation = function(operation_container, communityID, operation, hash, after_operation_container)
 {
  CORE.StartIndication();

  new Ajax.Updater(operation_container,
                   '/ajax/community_operation.html',
                   { asynchronous: true,
                     method: 'POST',
                     onSuccess: function() {
                      if ((CORE.CommunityOperationCallback) && (!after_operation_container))
                       CORE.CommunityOperationCallback(operation_container, communityID, operation, hash);
                      CORE.StopIndicationWithSuccess();
                      if (after_operation_container)
                       CORE.CommunityOperation(after_operation_container, communityID, 'refresh', hash);
                     },
                     onFailure: CORE.StopIndicationWithError,
                     parameters: 'operation_container=' + encodeURIComponent(operation_container) + '&' +
                                 'communityID=' + encodeURIComponent(communityID) + '&' +
                                 'operation=' + encodeURIComponent(operation) + '&' +
                                 'hash=' + encodeURIComponent(hash) + '&' +
                                 'digest=' + digest,
                     evalScripts: true });

  return false;
 }

CORE.UserOperation = function(operation_container, userID, operation, hash)
 {
  CORE.StartIndication();

  new Ajax.Updater(operation_container,
                   '/ajax/user_operation.html',
                   { asynchronous: true,
                     method: 'POST',
                     onSuccess: function() {
                      if (CORE.UserOperationCallback)
                       CORE.UserOperationCallback(operation_container, userID, operation, hash);
                      CORE.StopIndicationWithSuccess();
                     },
                     onFailure: CORE.StopIndicationWithError,
                     parameters: 'operation_container=' + encodeURIComponent(operation_container) + '&' +
                                 'userID=' + encodeURIComponent(userID) + '&' +
                                 'operation=' + encodeURIComponent(operation) + '&' +
                                 'hash=' + encodeURIComponent(hash) + '&' +
                                 'digest=' + digest,
                     evalScripts: true });

  return false;
 }

CORE.Bookmark = function(template, kind, kindID, value, hash)
 {
  CORE.StartIndication();

  new Ajax.Updater('bookmark' + template + kind + kindID,
                   '/ajax/bookmark_operation.html',
                   { asynchronous: true,
                     method: 'POST',
                     onSuccess: function() {
                      if (CORE.BookmarkOperationCallback)
                       CORE.BookmarkOperationCallback(template, kind, kindID, value, hash);
                      CORE.StopIndicationWithSuccess();
                     },
                     onFailure: CORE.StopIndicationWithError,
                     parameters: 'template=' + encodeURIComponent(template) + '&' +
                                 'kind=' + encodeURIComponent(kind) + '&' +
                                 'kindID=' + encodeURIComponent(kindID) + '&' +
                                 'value=' + encodeURIComponent(value) + '&' +
                                 'hash=' + encodeURIComponent(hash) + '&' +
                                 'digest=' + digest,
                     evalScripts: true });

  return false;
 }

CORE.CommunityRights = function(template, communityID, kind, value, userID, hash)
 {
  CORE.StartIndication();

  for (k = 1; k <= 5; k++)
   $('cb' + k + '_' + userID).disabled = true;
  
  new Ajax.Updater('user' + template + userID,
                   '/ajax/community_rights_operation.html',
                   { asynchronous: true,
                     method: 'POST',
                     onSuccess: function() {
                      if (CORE.CommunityRightsOperationCallback)
                       CORE.CommunityRightsOperationCallback(template, communityID, kind, value, userID, hash);
                      CORE.StopIndicationWithSuccess();
                     },
                     onFailure: CORE.StopIndicationWithError,
                     parameters: 'operation_container=' + encodeURIComponent(template) + '&' +
                                 'communityID=' + encodeURIComponent(communityID) + '&' +
                                 'kind=' + encodeURIComponent(kind) + '&' +
                                 'value=' + encodeURIComponent(value) + '&' +
                                 'userID=' + encodeURIComponent(userID) + '&' +
                                 'hash=' + encodeURIComponent(hash) + '&' +
                                 'digest=' + digest,
                     evalScripts: true });

  return false;
 }

CORE.Recommendation = function(template, kind, kindID, value, hash)
 {
  CORE.StartIndication();

  new Ajax.Updater('recommendation' + template + kind + kindID,
                   '/ajax/recommendation_operation.html',
                   { asynchronous: true,
                     method: 'POST',
                     onSuccess: function() {
                      if (CORE.RecommendationOperationCallback)
                       CORE.RecommendationOperationCallback(template, kind, kindID, value, hash);
                      CORE.StopIndicationWithSuccess();
                     },
                     onFailure: CORE.StopIndicationWithError,
                     parameters: 'template=' + encodeURIComponent(template) + '&' +
                                 'kind=' + encodeURIComponent(kind) + '&' +
                                 'kindID=' + encodeURIComponent(kindID) + '&' +
                                 'value=' + encodeURIComponent(value) + '&' +
                                 'hash=' + encodeURIComponent(hash) + '&' +
                                 'digest=' + digest,
                     evalScripts: true });

  return false;
 }

CORE.CommunityPostRequestOperation = function(operation_container, communityID, operation, hash)
 {
  CORE.StartIndication();

  new Ajax.Updater(operation_container,
                   '/ajax/community_post_request_operation.html',
                   { asynchronous: true,
                     method: 'POST',
                     onSuccess: function() {
                      if (CORE.CommunityPostRequestOperationCallback)
                       CORE.CommunityPostRequestOperationCallback(operation_container, communityID, operation, hash);
                      CORE.StopIndicationWithSuccess();
                      //CORE.CommunityOperation('profile_tools', communityID, 'refresh', hash);
                     },
                     onFailure: CORE.StopIndicationWithError,
                     parameters: 'operation_container=' + encodeURIComponent(operation_container) + '&' +
                                 'communityID=' + encodeURIComponent(communityID) + '&' +
                                 'operation=' + encodeURIComponent(operation) + '&' +
                                 'hash=' + encodeURIComponent(hash) + '&' +
                                 'digest=' + digest,
                     evalScripts: true });

  return false;
 }

CORE.PostModerationOperation = function(operation_container, container_type, postID, communityID, operation, hash, special)
 {
  CORE.StartIndication();

  Selector.findChildElements($(operation_container), ['input']).each(function(e) {
   e.disabled = true;
  });

  new Ajax.Updater(operation_container,
                   '/ajax/community_post_moderation_operation.html',
                   { asynchronous: true,
                     method: 'POST',
                     onSuccess: function() {
                      if (CORE.CommunityPostModerationOperationCallback)
                       CORE.CommunityPostModerationOperationCallback(operation_container, container_type, postID, communityID, operation, hash, special);
                      CORE.StopIndicationWithSuccess();
                     },
                     onFailure: CORE.StopIndicationWithError,
                     parameters: 'operation_container=' + encodeURIComponent(operation_container) + '&' +
                                 'container_type=' + encodeURIComponent(container_type) + '&' +
                                 'postID=' + encodeURIComponent(postID) + '&' +
                                 'communityID=' + encodeURIComponent(communityID) + '&' +
                                 'operation=' + encodeURIComponent(operation) + '&' +
                                 'hash=' + encodeURIComponent(hash) + '&' +
                                 'special=' + encodeURIComponent(special) + '&' +
                                 'digest=' + digest,
                     evalScripts: true });

  return false;
 }

CORE.PerformWarner = function(id, operation, kind, kindID, hash)
 {
  CORE.StartIndication();

  Selector.findChildElements($(id), ['input']).each(function(e) {
   e.disabled = true;
  });

  new Ajax.Request('/ajax/warner_operation.html',
                   { asynchronous: true,
                     method: 'POST',
                     onSuccess: function(r) {
                      CORE.StopIndicationWithSuccess();

                      var e = $(id);
                      e.parentNode.removeChild(e);

                      if (Selector.findChildElements($('warners'), ['.warner']).length == 0)
                       $('warners').style.display = 'none';
                     },
                     onFailure: CORE.StopIndicationWithError,
                     parameters: 'operation=' + encodeURIComponent(operation) + '&' +
                                 'kind=' + encodeURIComponent(kind) + '&' +
                                 'kindID=' + encodeURIComponent(kindID) + '&' +
                                 'hash=' + encodeURIComponent(hash) + '&' +
                                 'digest=' + digest,
                     evalScripts: true });

  return false;
 }

CORE.SubscribeEmailToCommunity = function(container, communityID, i, b)
 {
  CORE.StartIndication();

  var email = i.value;

  Selector.findChildElements($(container), ['input']).each(function(e) {
   e.disabled = true;
  });

  new Ajax.Updater(container,
                   '/ajax/community_email_subscribe_operation.html',
                   { asynchronous: true,
                     method: 'POST',
                     onSuccess: function(r) {
                      CORE.StopIndicationWithSuccess();
                     },
                     onFailure: CORE.StopIndicationWithError,
                     parameters: 'container=' + encodeURIComponent(container) + '&' +
                                 'communityID=' + encodeURIComponent(communityID) + '&' +
                                 'email=' + encodeURIComponent(email) + '&' +
                                 'digest=' + digest,
                     evalScripts: true });

  return false;
 }

CORE.CommentReply = function(A,B){
  if(!NatashaPosting){
    var C=$("commentform");
    if(!C){
      return false
     }
    C.parentNode.removeChild(C);
    if(NatashaKapustina){
      NatashaKapustina.style.display="inline"
     }
    $("ch"+A).appendChild(C);
    C.style.display="";
    (NatashaKapustina=$("ct"+A)).style.display="none";
    $("replyto").value=A;
    $("commentpreview").style.display="none";
    if (!B)
     {
      setTimeout(function()
       {
        $('comment').focus();
       }, 1);
     }
   }
  return false
 }

CORE.CommentSubmitSuccess = function(A){
  var B=$("commentform");
  var C=$("commentprogressc");
  NatashaPosting=false;
  $("cs1").disabled=false;
  $("cs2").disabled=false;
  $("comment").value="";
  B.style.display="block";
  C.setAttribute("id","commentprogressd");
  C.parentNode.removeChild(C);

  CORE.CommentReply(0, true);

  if (Tooltips)
   Tooltips.rescan_delayed();
 }

CORE.CommentSubmit = function(){
  NatashaPosting=true;

  var A=$("commentform");
  A.style.display="none";

  if (cp = $("commentprogress"))
   {
    cp = cp.cloneNode(false);
    cp.setAttribute("id", "commentprogressc");
    cp.style.display = "inline";
    $("ch" + $("replyto").value).appendChild(cp);
   }

  $("cs1").disabled = true;
  $("cs2").disabled = true;
  $("commentpreview").style.display = "none";

  new Ajax.Updater("cp"+$("replyto").value,"/ajax/comment.html",{asynchronous:true,method:"POST",onSuccess:CORE.CommentSubmitSuccess,evalScripts:true,parameters:"digest="+digest+"&"+Form.serialize($("commentformm"))});
  return false
 }

CORE.CommentDeleteSuccess = function(A){
  var B=$("commentform");
  NatashaPosting=false;
  $("cs1").disabled=false;
  $("cs2").disabled=false;
  if($("comment")){
    $("comment").value=""
   }
  B.style.display="block";
  CORE.CommentReply(0,true);
  $(A.request.wtf).innerHTML=A.responseText;
  if(Tooltips){
    Tooltips.rescan_delayed();
   }
 }

CORE.CommentDelete = function(A,C,Spam){
  CORE.CommentReply(A,true);
  NatashaPosting=true;
  var B=$("commentform");
  if(cp=$("commentprogress")){
    cp=cp.cloneNode(false);
    cp.setAttribute("id","commentprogressc");
    cp.style.display="inline";
    $("ch"+A).appendChild(cp);
    $("ct"+A).style.display="none"
   }
  B.style.display="none";
  $("cs1").disabled=true;
  $("cs2").disabled=true;
  $("commentpreview").style.display="none";
  (new Ajax.Request("/ajax/comment.html",{asynchronous:true,method:"POST",onSuccess:CORE.CommentDeleteSuccess,parameters:"digest="+digest+"&delete=1&spam="+Spam+"&"+Form.serialize($("commentformm"))})).wtf="cp"+C;
  return false
 }

CORE.CommentThreadSuccess = function(A){
  var B=$("commentform");
  NatashaPosting=false;
  $("cs1").disabled=false;
  $("cs2").disabled=false;
  B.style.display="block";
  CORE.CommentReply(0,true);
  $(A.request.wtf).innerHTML=A.responseText;
  if(Tooltips){
    Tooltips.rescan_delayed();
   }
 }

CORE.CommentThread = function(A,C){
  CORE.CommentReply(A,true);
  NatashaPosting=true;
  var B=$("commentform");
  if(cp=$("commentprogress")){
    cp=cp.cloneNode(false);
    cp.setAttribute("id","commentprogressc");
    cp.style.display="inline";
    $("ch"+A).appendChild(cp);
    $("ct"+A).style.display="none"
   }
  if(B){
    B.style.display="none";
    $("cs1").disabled=true;
    $("cs2").disabled=true;
    $("commentpreview").style.display="none";
    (new Ajax.Request("/ajax/comment.html",{asynchronous:true,method:"POST",onSuccess:CORE.CommentDeleteSuccess,parameters:(wtf="digest="+digest+"&thread=1&"+Form.serialize($("commentformm")))})).wtf="cp"+C
   }
  else{
    (new Ajax.Request("/ajax/comment.html",{asynchronous:true,method:"POST",onSuccess:CORE.CommentDeleteSuccess,parameters:(wtf="digest="+digest+"&thread=1&comment[replyto]="+A)})).wtf="cp"+C
   }
  return false
 }

CORE.CommentPreviewSuccess = function(A){
  if(Tooltips){
    Tooltips.rescan_delayed();
   }
 }

CORE.CommentPreview = function(){
  $("commentpreview").innerHTML="";
  $("commentpreview").style.display="block";
  if(B=$("commentprogress")){
    var B=B.cloneNode(false);
    B.setAttribute("id","commentprogressc");
    B.style.display="inline";
    var A=document.createElement("div");
    A.style.textAlign="center";
    A.style.padding="10px";
    A.appendChild(B);
    $("commentpreview").appendChild(A)
   }
  new Ajax.Updater("commentpreview","/ajax/comment.html",{asynchronous:true,method:"POST",onSuccess:CORE.CommentPreviewSuccess,parameters:"digest="+digest+"&preview=1&"+Form.serialize($("commentformm"))})
 }

CORE.CommentPreviewKeyhandler = function(A){
  if(A){
    if((A.ctrlKey)&&((A.keyCode==10)||(A.keyCode==13))){
      CORE.CommentSubmit()
     }
   }
 }

CORE.CommentSubscribeSuccess = function(A){
  A.request.wtf.innerHTML=A.responseText;
  if(Tooltips){
    Tooltips.close();
    Tooltips.rescan_delayed();
   }
 }

CORE.CommentSubscribe = function(A){
  var B=$("csub"+A);
  B.innerHTML="";
  (new Ajax.Request("/ajax/comment_subscribe.html",{asynchronous:true,method:"POST",onSuccess:CORE.CommentSubscribeSuccess,parameters:"digest="+digest+"&commentownerID="+A})).wtf=B;
  return false
 }

CORE.CommentsOver = function(li)
 {
  if (!li._hovered)
   {
    li._hovered = true;
    li._className = li.className;
    li.className = 'comment_hover ' + li.className;
   }
 }
 
CORE.CommentsOut = function(li)
 {
  if (li._hovered)
   {
    li._hovered = false;
    li.className = li._className;
   }
 }

CORE.CommentScroll = function(A)
 {
  setTimeout(function()
   {
    Effect.ScrollToEx($('c' + A), { duration: 0.2, offset: -50 });

    new Effect.Highlight($('c' + A), { keepBackgroundImage: true });
    //$('c' + A).parentNode.parentNode.className = "comment comment_hilight";
   },
  150);
 }

CORE.FlashIcon = function(id, timeout)
 {
  var e = false;

  if (e = $(id))
   {
    if (e.className.substr(-7, 7) != '_active')
     {
      e._savedClass = e.className;

      setTimeout(function()
       {
        e.className = e.className + '_active';

        setTimeout(function()
         {
          e.className = e._savedClass;

          setTimeout(function()
           {
            e.className = e.className + '_active';

            setTimeout(function()
             {
              e.className = e._savedClass;
             }, 215);
           }, 215);
         }, 215);
       }, timeout);
     }
   }
 }

CORE.FlashIcons = function()
 {
  var delay = 0;
  var no = 0;

  for (var k = 1; k <= 11; k++)
   if ($('iconflash' + k))
    {
     CORE.FlashIcon('iconflash' + k, 400 + no * delay);
     no++;
    }
 }

CORE.DKN = function(wtf, yarr)
 {
  CORE.DisableKeyNav = yarr;
 }

CORE.realOffset = function(element)
 {
  var valueT = 0, valueL = 0;
  var valueTm = 0, valueLm = 0;

  CORE.realOffsetFixed = false;

  if (element)
   {
    var e = element;

    do {
     valueT += element.offsetTop  || 0;
     valueL += element.offsetLeft || 0;

     if (element.style.position == 'fixed')
      {
       CORE.realOffsetFixed = true;
       break;
      }

     element = element.offsetParent;
    } while (element);

    element = e;

    do {
     valueTm -= element.scrollTop  || 0;
     valueLm -= element.scrollLeft || 0;

     if (!(element = element.parentNode)) break;
     if (element.tagName.toUpperCase() == 'BODY') break;
     if (element.tagName.toUpperCase() == 'HTML') break;
    } while (true);
   }

  return Element._returnOffset(valueL + valueLm, valueT + valueTm);
 }

CORE.ValidEvent = function(event)
 {
  var e = Event.findElement(event);

  if (e)
   {
    var t = e.tagName.toUpperCase();

    if ((t == 'A') || (t == 'FORM') || (t == 'INPUT') || (t == 'LABEL'))
     return true;
   }

  return false;
 }

CORE.RenderPlayer = function(id, width, height, param, value)
 {
  if ($(id + '_container'))
   {
    var playa = false;

    if (FlashIsStaging)
     playa = new SWFObject(FlashIsStaging + "?" + Math.random(), id, width, height, "9", "");
    else
     playa = new SWFObject(__IMGURL + 'swf/playa.swf', id, width, height, "9", "");

    playa.addParam('swliveconnect', true);
    playa.addParam('allowscriptaccess', 'always');
    playa.addParam('allowfullscreen', 'true');
    playa.addParam('wmode', 'transparent');

    if (FlashIsStaging)
     playa.addVariable('debug', '1');

    playa.addVariable(param, value);

    //alert('CORE.RenderPlayer inserting value = ' + value);

    playa.write(id + '_container');
   }
  else if (FlashIsStaging)
   alert('no container for ' + id);
 }

CORE.SetAnchor = function(anchor)
 {
  window.location.replace('#' + anchor);
 }

CORE.GetAnchor = function()
 {
  return window.location.hash.substr(1);
 }

CORE.LoadTwitter = function(id, twitter, common_hash)
 {
  new Ajax.Updater(id,
                   '/ajax/twitter.html',
                   { asynchronous: true,
                     method: 'GET',
                     parameters: 'twitter=' + encodeURIComponent(twitter) + '&common_hash=' + encodeURIComponent(common_hash),
                     onSuccess: Tooltips.rescan_delayed });
 }

CORE.ShareOnFacebook = function(url, title)
 {
  var w = window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(url) + '&t=' + encodeURIComponent(title), 'rpodshr', 'width=700,height=400,left=100,top=10,resizable=yes,scrollbars=yes,status=no');

  if ((w == null) || (w == undefined))
   {
   }
  else 
   {
    try { w.focus(); } catch (wtf) { }
   }

  return false;
 }

CORE.ShareOnBuzz = function(url, title)
 {
  var w = window.open('http://www.google.com/reader/link?url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title), 'rpodshr', 'width=700,height=400,left=100,top=10,resizable=yes,scrollbars=yes,status=no');

  if ((w == null) || (w == undefined))
   {
   }
  else 
   {
    try { w.focus(); } catch (wtf) { }
   }

  return false;
 }

CORE.ShareOnVK = function(url, title)
 {
  var w = window.open('http://vkontakte.ru/share.php?url=' + encodeURIComponent(url), 'rpodshr', 'width=700,height=400,left=100,top=10,resizable=yes,scrollbars=yes,status=no');

  if ((w == null) || (w == undefined))
   {
   }
  else 
   {
    try { w.focus(); } catch (wtf) { }
   }

  return false;
 }

CORE.ShareOnYaRu = function(url, title)
 {
  var w = window.open('http://wow.ya.ru/posts_add_link.xml?URL=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title), 'rpodshr', 'width=700,height=400,left=100,top=10,resizable=yes,scrollbars=yes,status=no');

  if ((w == null) || (w == undefined))
   {
   }
  else 
   {
    try { w.focus(); } catch (wtf) { }
   }

  return false;
 }

CORE.ShareOnMyMail = function(url, title)
 {
  var w = window.open('http://connect.mail.ru/share?share_url=' + encodeURIComponent(url), 'rpodshr', 'width=700,height=400,left=100,top=10,resizable=yes,scrollbars=yes,status=no');

  if ((w == null) || (w == undefined))
   {
   }
  else 
   {
    try { w.focus(); } catch (wtf) { }
   }

  return false;
 }

CORE.EmbedPodcast = function(postID)
 {
  GodsFinger.load('/ajax/embed_podcast.html?postID=' + postID);

  return false;
 }

CORE.PlaceholderFocus = function(i)
 {
  i.className = 'placeholder_focused';

  if (i.value == i.getAttribute('placeholder'))
   i.value = '';
 }

CORE.PlaceholderBlur = function(i)
 {
  if (i.value == '')
   {
    i.value = i.getAttribute('placeholder');
    i.className = 'placeholder';
   }
 }

CORE.CheckEnter = function(B,A)
 {
  var C=0;
  if(window.event){
    C=B.keyCode
   }
  else{
    if(B.which){
      C=B.which
     }
   }
  if(C==13){
    A();
    return false
   }
  else{
    return true
   }
 }

CORE.NoEnter = function(A)
 {
  var B=0;
  if(window.event){
    B=A.keyCode
   }
  else{
    if(A.which){
      B=A.which
     }
   }
  return(B==13?false:true)
 }

CORE.featuredGo = function(step)
 {
  if (step != 0)
   {
    $('featured' + CORE.featuredCurrent).style.display = 'none';

    CORE.featuredCurrent += step;

    $('featured' + CORE.featuredCurrent).style.display = '';
   }

  $('featprev').style.display = $('featured' + (CORE.featuredCurrent - 1)) ? 'block' : 'none';
  $('featnext').style.display = $('featured' + (CORE.featuredCurrent + 1)) ? 'block' : 'none';

  return false;
 }

CORE.TextAreaAutoSize = function(id, maxHeight)
 {
  var inputElement = $(id);
  var textarea = inputElement;
  var initialHeight = textarea.getHeight();
  var currentHeight = -1;
  var currentTimer = false;

  var div = document.createElement('DIV');
  div.id = textarea.id + '_hidden';

  textarea.insert({'after': div});

  div.setStyle({'display'       : 'none',
                'width'         : textarea.getWidth() ?
                                    (textarea.getWidth() + "px") :
                                    textarea.getStyle('width'),
                'whiteSpace'    : 'pre-wrap',
                'fontFamily'    : textarea.getStyle('fontFamily'),
                'fontSize'      : textarea.getStyle('fontSize'),
                'lineHeight'    : textarea.getStyle('lineHeight'),
                'paddingTop'    : textarea.getStyle('paddingTop'),
                'paddingLeft'   : textarea.getStyle('paddingLeft'),
                'paddingRight'  : textarea.getStyle('paddingRight'),
                'paddingBottom' : textarea.getStyle('paddingBottom'),
                'marginTop'     : textarea.getStyle('marginTop'),
                'marginLeft'    : textarea.getStyle('marginLeft'),
                'marginRight'   : textarea.getStyle('marginRight'),
                'marginBottom'  : textarea.getStyle('marginBottom'),
                'borderTop'     : textarea.getStyle('borderTop'),
                'borderLeft'    : textarea.getStyle('borderLeft'),
                'borderRight'   : textarea.getStyle('borderRight'),
                'borderBottom'  : textarea.getStyle('borderBottom')
               });

  var timerHandler = function()
   {
    currentTimer = false;

    if (initialHeight == 0)
     initialHeight = textarea.getHeight();

    div.innerHTML = $F(textarea).replace(/&/g, '&amp;')
                                .replace(/</g, '&lt;') +
//                                .replace(/\n/g, '<br />') +
                                '<br />z';

    var newHeight = Math.max(initialHeight, div.getHeight());

    if (maxHeight)
     newHeight = Math.min(newHeight, maxHeight);

    if (newHeight != currentHeight && newHeight != 0) 
     {
      textarea.setStyle({ 'height': newHeight + 'px' });
      currentHeight = newHeight;
     }
   }

  var eventHandler = function(ev)
   {
    if (!currentTimer)
     setTimeout(timerHandler, 250);
   }

  textarea.observe('change', eventHandler);
  textarea.observe('keyup', eventHandler);

  timerHandler();
 }

CORE.TextAreaColorer = function(b, id)
 {
  if ((s = b.options[b.selectedIndex].value) != '')
   CORE.TextAreaStyler(b, id, "<font color=\"" + s + "\">", "</font>"); 

  b.selectedIndex = 0;

  return false;
 }

CORE.TextAreaBolder = function(b, id)
 {
  return CORE.TextAreaTagger(b, id, "<b>", "</b>");
 }

CORE.TextAreaItalicer = function(b, id)
 {
  return CORE.TextAreaTagger(b, id, "<i>", "</i>");
 }

CORE.TextAreaUnderliner = function(b, id)
 {
  return CORE.TextAreaTagger(b, id, "<u>", "</u>");
 }

CORE.TextAreaListUL = function(b, id)
 {
  return CORE.TextAreaPut(id, '<ul><li></ul>');
 }

CORE.TextAreaLinker = function(b, id)
 {
  var c = CORE.TextAreaGetCursor($(id) ? $(id) : id);

  if (c.start == c.end)
   {
    if (!(enterURL = prompt('Введите адрес страницы', "http://")))
     return false;

    if (!(enterTITLE = prompt('Введите текст ссылки', "Описание страницы")))
     return false;
   
    return CORE.TextAreaPut(id, '<a href="' + enterURL + '">' + enterTITLE + '</a>');
   }
  else
   {
    if (!(enterURL = prompt('Введите адрес страницы', "http://")))
     return false;

    return CORE.TextAreaInsertPair(false, id, '<a href="' + enterURL + '">', '</a>');
   }
 }

CORE.TextAreaFonter = function(b, id)
 {
  if ((s = b.options[b.selectedIndex].value) != '')
   CORE.TextAreaStyler(b, id, "<font size=\"" + s + "\">", "</font>"); 

  b.selectedIndex = 0;

  return false;
 }

CORE.TextAreaTool = function(b, id, url)
 {
  return GodsFinger.load(url + '&id=' + encodeURIComponent(id));
 }

CORE.TextAreaCutter = function(b, id)
 {
  return CORE.TextAreaPut(id, '<cut>');
 }

CORE.TextAreaPut = function(id, s)
 {
  return CORE.TextAreaInsertPair(false, id, s, '');
 }

CORE.TextAreaStyler = function(b, id, open, close)
 {
  return CORE.TextAreaInsertPair(false, id, open, close);
 }

CORE.TextAreaTagger = function(b, id, open, close)
 {
  return CORE.TextAreaInsertPair(b, id, open, close);
 }

CORE.TextAreaGetCursor = function(C)
 {
  var A = {
   start: 0,
   end: 0,
   fixup: 0
  };

  if (C.setSelectionRange)
   {
    A.start = C.selectionStart;
    A.end = C.selectionEnd;
   }
  else
   {
    if (!document.selection)
     {
      return 0;
     }
    else
     {
      if (document.selection && document.selection.createRange)
       {
        var B = document.selection.createRange();
        var D = B.duplicate();

        try
         {
          D.moveToElementText(C)
         }
        catch (F)
         {
         }

        D.setEndPoint("EndToEnd", B);

        var E = 0;

        for (k = 0; k < D.text.length; k++)
         {
          if (D.text.charCodeAt(k) == 13)
           {
            E++
           }
         }

        A.start = D.text.length - B.text.length;
        A.end = A.start + B.text.length;
        A.fixup = E;
       }
     }
   }

  return A;
 }

CORE.TextAreaSetCursor = function(E,D,A,C)
 {
  if (E.createTextRange)
   {
    var B = E.createTextRange();
    B.move("character", D - C);
    B.select();
   }
  else
   {
    if (E.selectionStart)
     E.setSelectionRange(D, A);
   }
 }

CORE.TextAreaInsertPair = function(H,B,K,D)
 {
  var I = $(B)?$(B):B;
  var G = I.scrollTop;
  var E = CORE.TextAreaGetCursor(I);
  var J = 0;

  I.focus();

  if ((E.start == E.end) && (H))
   {
    if (!H.srcvalue)
     H.srcvalue = H.value;

    if ((H) && (H.tagged=!H.tagged))
     {
      I.value = I.value.substring(0, E.start) + K + I.value.substr(E.start);
      J = E.start + K.length;
     }
    else
     {
      I.value = I.value.substring(0, E.start) + D + I.value.substr(E.start);
      J = E.start + D.length;
     }

    CORE.TextAreaSetCursor(I, J, J, E.fixup)

    H.value = H.tagged ? (H.srcvalue + '*') : H.srcvalue;
   }
  else
   {
    var C = I.value.substring(0,E.start);
    var A = I.value.substring(E.start,E.end);
    var F = I.value.substring(E.end);

    I.value = C + K + A + D + F;

    var J = String(C + K + A + D).length;

    CORE.TextAreaSetCursor(I, J, J, E.fixup)
   }

  if (G)
   I.scrollTop = G;

  return false;
 }

Object.extend(Event,
 {
  _domReady : function() 
   {
    if (arguments.callee.done) return;
    arguments.callee.done = true;

    if (this._timer)  clearInterval(this._timer);
    
    this._readyCallbacks.each(function(f) { f() });
    this._readyCallbacks = null;
   },
  onDOMReady : function(f) 
   {
    if (!this._readyCallbacks) {
      var domReady = this._domReady.bind(this);
      
      if (document.addEventListener)
        document.addEventListener("DOMContentLoaded", domReady, false);
        
        /*@cc_on @*/
        /*@if (@_win32)
            document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
            document.getElementById("__ie_onload").onreadystatechange = function() {
                if (this.readyState == "complete") domReady(); 
            };
        /*@end @*/
        
        if (/WebKit/i.test(navigator.userAgent)) { 
          this._timer = setInterval(function() {
            if (/loaded|complete/.test(document.readyState)) domReady(); 
          }, 10);
        }
        
        Event.observe(window, 'load', domReady);
        Event._readyCallbacks =  [];
    }
    Event._readyCallbacks.push(f);
   }
 });

Event.onDOMReady(CORE.init);

