//=========Прелоад для rollower=========================
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* Musicmaker Image Uploader */
function highlight(field){field.focus();field.select()}var url="http://imageshack.us/";var title="Musicmaker Image Uploader";function favorites(){if(document.all)window.external.AddFavorite(url,title)}function disableme(what){what=document.getElementById(what);what.disabled=true;what.value="Загружается..."}var buttonname='"Обзор..."';function showoptions(what){var ext=what.value.substr(what.value.length-3,3).toLowerCase();switch(ext){case'jpg':case'peg':case'png':case'gif':case'bmp':case'tif':case'iff':document.getElementById('resizeoptions').style.display='';document.getElementById('filetypeerror').style.display='none';document.getElementById('butan').disabled=false;document.getElementById('butan').value='Начать загрузку';break;case'swf':document.getElementById('resizeoptions').style.display='none';document.getElementById('filetypeerror').style.display='none';document.getElementById('butan').disabled=false;document.getElementById('butan').value='Начать загрузку';break;default:document.getElementById('resizeoptions').style.display='none';document.getElementById('filetypeerror').style.display='';document.getElementById('butan').disabled=true;document.getElementById('butan').value='Недопустимый тип файла';break}}function toggleuploadmode(file){if(file){document.getElementById('upfile').style.display='block';document.getElementById('upurl').style.display='none';document.getElementById('upform').action='http://www.imageshack.us/index.php'}else{document.getElementById('upfile').style.display='none';document.getElementById('upurl').style.display='block';document.getElementById('upform').action='http://www.imageshack.us/transload.php'}}function focusfield(fl){if(fl.value=="вставьте url картинки сюда"){fl.value='';fl.style.color='black'}}

/* Попап-сообщения с форума в центральном блоке */
function topicPopup(id,uname) {
var post_id = id;
var sAuthor = uname;

document.observe('dom:loaded', function () {
    new Tip(post_id, {
        title: 'Последнее сообщение',
        ajax: {
            url: 'ajaxed_blocks/get_topic.php',
            options: {
                method: 'get',
                parameters: "post_id="+post_id+"&author="+sAuthor,
                onComplete: function () {}
            }
        },
        className: 'silver',
        viewport: 'true',
        width: 'auto',
        hook: {
            tip: 'topLeft',
            target: 'bottomLeft'
        },
        delay: '0.4',
        effect: 'appear'
    })
});
}

/* РАДИО ПОПАП */
function wimpyPopPlayer(theFile,id,stuff) {
  window.open(theFile,id,stuff);
}

/* ХИНТ */
function hidehint(what, el) {
	$(el).fade({ duration: 0.5 });
}
function show_alert(field, button) {
    selField = field;
    var buttonElement = $(button);
    var iLeftPos = getOffsetLeft(buttonElement);
    var iTopPos = getOffsetTop(buttonElement) + (buttonElement.offsetHeight + 3);
    $(field).style.left = (iLeftPos) + "px";
    $(field).style.top = (iTopPos) + "px";
    $(field).value = button;
	
	$(field).setStyle({display: 'block', cursor: 'move'});
	new Effect.Opacity(field, { from: 0.0, to: 1.0, duration: 0.5 });
	new Draggable(field, { revert: false, scroll: window });
}
function showhint(text, button) {
    $('alert_text').innerHTML = text;
    show_alert('alert', button)
}
function getOffsetTop(obj) {
    var top = obj.offsetTop;
    while ((obj = obj.offsetParent) != null) {
        top += obj.offsetTop
    }
    return top
}
function getOffsetLeft(obj) {
    var top = obj.offsetLeft;
    while ((obj = obj.offsetParent) != null) {
        top += obj.offsetLeft
    }
    return top
}

/* Поиск в истории shoutbox */
function shoutboxsearch() {
  var sSearch = $F("shoutsearch_input");
  
  if (sSearch.length <3)
  {
    $('error_empty').hide();
    $('error_length').slideDown({ duration: 0.5, fps:50 });
	setTimeout('$("error_length").slideUp({ duration: 0.5, fps:50, queue: "end" })', 3500);
    return false;
  }

  if (sSearch == "Найти сообщение")
  {
	$('error_length').hide();
	$('error_empty').slideDown({ duration: 0.5, fps:50 });
	setTimeout('$("error_empty").slideUp({ duration: 0.5, fps:50, queue: "end" })', 3500);
    return false;
  }
  
	$('ShoutSearch_searching').slideDown({ duration: 0.5, fps:50 });
	//$('ShoutSearch_results').hide();
	$('list_block').hide();
	$('list_block_desc').hide();
	
  new Ajax.Updater('ShoutSearch_results', 'ajaxed_blocks/ajax_shoutboxsearch.php',
    { method: 'get',
      parameters: { search: sSearch },
      onComplete: function () {
        $('ShoutSearch_results').show();
		setTimeout('$("ShoutSearch_searching").slideUp({ duration: 0.5, fps:50, queue: "end" })', 1000);
        $('list_block').hide();
        $('list_block_desc').hide();
      }
    }
  );
}

/* Поиск похожих тем на форуме */
function searchsame() {
  var sSearch = $F("subject");
  
  if (sSearch.length <3)
  {
    $('error_empty').hide();
    $('error_length').slideDown({ duration: 0.5, fps:50 });
	setTimeout('$("error_length").slideUp({ duration: 0.5, fps:50, queue: "end" })', 3500);
    return false;
  }
  
	$('searching').slideDown({ duration: 0.5, fps:50 });
  
  new Ajax.Updater('search_results', 'ajaxed_blocks/ajax_forummatch.php',
    { method: 'get',
      parameters: { search: sSearch },
      onComplete: function () {
        setTimeout('$("searching").slideUp({ duration: 0.5, fps:50, queue: "end" })', 1000);
        $('search_results').appear({ duration: 0.5 });
      }
    }
  );
}

/* Поиск заголовков на всех страницах (верхний) аякс */
function topsearch() {
  var sSearch = $F("topsearch_input");
  
  if (sSearch.length <3)
  {
    $('error_empty').hide();
    $('error_length').slideDown({ duration: 0.5, fps:50 });
	setTimeout('$("error_length").slideUp({ duration: 0.5, fps:50, queue: "end" })', 3500);
    return false;
  }

	$('searching').slideDown({ duration: 0.5, fps:50 });
  
  new Ajax.Updater('search_results', 'ajaxed_blocks/ajax_mainsearch.php',
    { method: 'get',
      parameters: { search: sSearch },
      onComplete: function () {
        setTimeout('$("searching").slideUp({ duration: 0.5, fps:50, queue: "end" })', 1000);
        $('search_results').appear({ duration: 0.5 });
      }
    }
  );
}

/* Поиск заголовков на главной аякс */
function mainsearch() {
  var sSearch = $F("search_input");
  
  if (sSearch.length <3)
  {
    $('error_empty').hide();
    $('error_length').slideDown({ duration: 0.5, fps:50 });
	setTimeout('$("error_length").slideUp({ duration: 0.5, fps:50, queue: "end" })', 3500);
    return false;
  }

  if (sSearch == "Быстрый поиск")
  {
	$('error_length').hide();
	$('error_empty').slideDown({ duration: 0.5, fps:50 });
	setTimeout('$("error_empty").slideUp({ duration: 0.5, fps:50, queue: "end" })', 3500);
    return false;
  }

	$('searching').slideDown({ duration: 0.5, fps:50 });
  
  new Ajax.Updater('search_results', 'ajaxed_blocks/ajax_mainsearch.php',
    { method: 'get',
      parameters: { search: sSearch },
      onComplete: function () {
        setTimeout('$("searching").slideUp({ duration: 0.5, fps:50, queue: "end" })', 1000);
        $('search_results').appear({ duration: 0.5 });
      }
    }
  );
}

/* Поиск заголовков форума аякс */
function forumsearch() {
  var sSearch = $F("search_input");
  
  if (sSearch.length <3)
  {
    $('forumerror_empty').hide();
    $('forumerror_length').appear({ duration: 0.5 });
	setTimeout('$("forumerror_length").fade({ duration: 0.5, fps:50, queue: "end" })', 3000);
    return false;
  }

  if (sSearch == "Быстрый поиск по названию темы")
  {
	$('forumerror_length').hide();
	$('forumerror_empty').appear({ duration: 0.5 });
	setTimeout('$("forumerror_empty").fade({ duration: 0.5, fps:50, queue: "end" })', 3000);
    return false;
  }
  
	$('forumsearching').show();
  
  new Ajax.Updater('forumsearch_results', 'ajaxed_blocks/ajax_forumsearch.php',
    { method: 'get',
      parameters: { search: sSearch },
      onComplete: function () {
        $('forumsearch_results').appear({ duration: 0.5 });
        $('forumsearching').fade();
      }
    }
  );
}

/* Поиск файлов */
function downloadsearch() {
  var sSearch = $F("search_input");
  
  if (sSearch.length <3)
  {
    $('error_empty').hide();
    $('error_length').slideDown({ duration: 0.5, fps:50 });
	setTimeout('$("error_length").slideUp({ duration: 0.5, fps:50, queue: "end" })', 3500);
    return false;
  }

  if (sSearch == "Поиск в этом разделе")
  {
	$('error_length').hide();
	$('error_empty').slideDown({ duration: 0.5, fps:50 });
	setTimeout('$("error_empty").slideUp({ duration: 0.5, fps:50, queue: "end" })', 3500);
    return false;
  }

	$('searching').show();
  
  new Ajax.Updater('search_results', 'ajaxed_blocks/ajax_SearchDownloads.php',
    { method: 'get',
      parameters: { search: sSearch },
      onComplete: function () {
        setTimeout('$("searching").slideUp({ duration: 0.5, fps:50, queue: "end" })', 1000);
        $('search_results').appear({ duration: 0.5 });
      }
    }
  );
}

/* Поиск похожих файлов аякс */
function SearchSameFiles() {
  var sSearch = $F("search_input");
  
  if (sSearch.length <3)
  {
    $('error_empty').hide();
    $('error_length').appear({ duration: 0.5 });
	setTimeout('$("error_length").fade({ duration: 0.5, fps:50, queue: "end" })', 3000);
    return false;
  }

 
  $('search_results').hide();
  $('searching').show();
  
  new Ajax.Updater('search_results', 'ajaxed_blocks/ajax_SearchSameFiles.php',
    { method: 'get',
      parameters: { search: sSearch },
      onComplete: function () {
        $('search_results').show();
        $('searching').hide();
      }
    }
  );
}

/* Показ дополнительных строк в MMShouBox */
function MoreShouts(name,step,nomer) {
  var sLimit= step;
  var sCookie= name;
  var sNomer= nomer;
  
  $('MoreShouts_results'+nomer).hide();
  $('splitter'+nomer).hide();
  $('first_search'+nomer).hide();
  $('MoreShouts_searching'+nomer).show();
  
  new Ajax.Updater('MoreShouts_results'+nomer, 'ajaxed_blocks/ajax_moreshouts.php',
    { method: 'get',
      parameters: { 
		limit: sLimit,
		provname: sCookie,
		nomer: sNomer
		},
      onComplete: function () {
        $('MoreShouts_results'+nomer).appear({ duration: 1.0 });
        $('splitter'+nomer).show();
        $('MoreShouts_searching'+nomer).hide();
        $('first_search'+nomer).hide();
      }
    }
  );
}
