this.imagePreview = function()
{
   var xOffset_left=42; //якщо зображення зліва (враховувати товщину border)
   var xOffset_right=35; //якщо зображення справа
   var yOffset=10;
   var img1_width=1;
   var img1_height=1;
   var dw=$(window).width()/2;
   var dh=$(document).height()/2;
   var top=0;
   var left=0;
   //--
   $("a.img_big_preview").hover(function(e){
      //розмір анімованого бара завантаження
      img1_width=220;
      img1_height=19;
      //--
      $("body").append("<p id='img_big_preview'><img src='/img/loading-2.gif' width='220' height='19' alt='Загрузка...' /></p>");
      //--
      top=e.pageY-yOffset;
      //if (e.pageX<dw) {left=e.pageX+xOffset;} else {left=e.pageX-xOffset-img1_width;}
      if (e.pageX<dw) {left=e.pageX+xOffset_right;} //показувати картинку справа
      else {left=e.pageX-xOffset_left-img1_width;} //показувати картинку зліва
      //--
      $("#img_big_preview").css("top", top+"px");
      $("#img_big_preview").css("left", left+"px");
      //$("#img_big_preview").fadeIn("fast");
      $("#img_big_preview").show();

      //--

      //в інакшому випадку після зменшення вікна після першого виклику розміри прев`ю не перераховуються
      dw=$(window).width()/2;
      dh=$(window).height()/2;
      //--
      var img1_src='';
      //Визначення шляху до зображення для прев`ю
      //з title посиланя <a href="..." title="img1_src">
      img1_src=this.title;
      if (img1_src=='')
      {
         //з href посиланя <a href="img1_src">
         img1_src=this.href;
      }
      var img1=new Image();
      img1.onload = function()
      {
      	//wait(1);
      	img1_width=this.width;
      	img1_height=this.height;
      	if (img1_width>dw || img1_height>dh)
      	{         	//Визначення розмірів прев`ю
            w_ratio=img1_width/dw;
            h_ratio=img1_height/dh;
            if (w_ratio>h_ratio)
            {
               img1_width = Math.round(img1_width/w_ratio);
               img1_height = Math.round(img1_height/w_ratio);
            }
            else
            {
               img1_width = Math.round(img1_width/h_ratio);
               img1_height = Math.round(img1_height/h_ratio);
            }
      	}
         //--
         $('#img_big_preview').html("<img src='"+img1_src+"' width='"+img1_width+"' height='"+img1_height+"' alt='Быстрый предпросмотр' />");
         //--
         top=Math.round(e.pageY-yOffset-(img1_height/2));
         $("#img_big_preview").css("top", top+"px");
         if (e.pageX<dw) {left=e.pageX+xOffset_right;} else {left=e.pageX-xOffset_left-img1_width;}
         $("#img_big_preview").css("left", left+"px");
         $("#img_big_preview").css("width", img1_width+"px");
         $("#img_big_preview").css("height", img1_height+"px");
         //--
         $("#img_big_preview").show();
      }
      img1.src=img1_src; //сначала нужно задать обработчик события, и только потом делать действия, которые могут привести к возникновению этого события
    },

   function()
   {
     $("#img_big_preview").remove();
   });

   $("a.img_big_preview").mousemove(function(e)
   {
         top=Math.round(e.pageY-yOffset-(img1_height/2));
         $("#img_big_preview").css("top", top+"px");
         if (e.pageX<dw) {left=e.pageX+xOffset_right;} else {left=e.pageX-xOffset_left-img1_width;}
         $("#img_big_preview").css("left", left+"px");
   });
};


/*  http://share42.com/  *social* */
function share42(u,t){if(!u)u=location.href;if(!t)t=document.title;u=encodeURIComponent(u);t=encodeURIComponent(t);
var s=new Array('http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk='+u+'&title='+t+'" title="Сохранить закладку в Google"','http://memori.ru/link/?sm=1&u_data[url]='+u+'&u_data[name]='+t+'" title="Сохранить закладку в Memori.ru"','http://www.liveinternet.ru/journal_post.php?action=n_add&cnurl='+u+'&cntitle='+t+'" title="Опубликовать в LiveInternet"','http://vkontakte.ru/share.php?url='+u+'" title="Поделиться В Контакте"','http://www.mister-wong.ru/index.php?action=addurl&bm_url='+u+'&bm_description='+t+'" title="Сохранить закладку в Мистер Вонг"','http://connect.mail.ru/share?url='+u+'&title='+t+'" title="Поделиться в Моем Мире@Mail.Ru"','http://twitter.com/home?status='+t+' - '+u+'" title="Добавить в Twitter"','http://www.facebook.com/sharer.php?u='+u+'&t='+t+'" title="Поделиться в Facebook"','http://www.friendfeed.com/share?title='+t+' - '+u+'" title="Добавить в FriendFeed"','http://delicious.com/save?url='+u+'&title='+t+'" title="Сохранить закладку в Delicious"','http://www.livejournal.com/update.bml?event='+u+'&subject='+t+'" title="Опубликовать в LiveJournal"','http://bobrdobr.ru/add.html?url='+u+'&title='+t+'" title="Забобрить"','http://digg.com/submit?url='+u+'" title="Добавить в Digg"','http://bookmarks.yahoo.com/toolbar/savebm?u='+u+'&t='+t+'" title="Добавить в Yahoo! Закладки"','http://www.odnoklassniki.ru/dk?st.cmd=addShare&st._surl='+u+'&title='+t+'" title="Добавить в Одноклассники"','http://www.myspace.com/Modules/PostTo/Pages/?u='+u+'&t='+t+'" title="Добавить в MySpace"','http://zakladki.yandex.ru/newlink.xml?url='+u+'&name='+t+'" title="Добавить в Яндекс.Закладки"');
for(i=0;i<s.length;i++)document.write('<a style="display:inline-block;width:16px;height:16px;margin:0 7px 0 0;background:url(http://'+window.location.hostname+'/share42/icons.png) -'+16*i+'px 0" href="'+s[i]+'" target="_blank"></a>')}


/*GOOGLE MAPS*/
// http://prime-code.ru/google/google-maps/sobytiya-v-google-maps-javascript-api-v3/
function google_maps_initialize(google_maps_lat, google_maps_lng, google_maps_zoom, marker_draggable)
{
   var myOptions =
   {
      zoom: google_maps_zoom,
      mapTypeId: google.maps.MapTypeId.ROADMAP
   }

   var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
   map.setCenter(new google.maps.LatLng(google_maps_lat, google_maps_lng));

   var markerOptions =
   {
      map: map,
      position: map.getCenter()
   };
   var marker = new google.maps.Marker(markerOptions);
   marker.setDraggable(marker_draggable);
   //marker
   google.maps.event.addListener(marker, 'dragend', function()
   {
      $('#google_maps_lat').val(this.getPosition().lat());
      $('#google_maps_lng').val(this.getPosition().lng());
      //alert(this.getPosition().lat());
   });
   //zoom
   google.maps.event.addListener(map, "zoom_changed", function()
   {
      $('#google_maps_zoom').val(this.getZoom());
   });


}


/*форма авторизації*/
 $(document).ready(
 function()
 {
  imagePreview();

   //delay for hover  test
   /*$("#test_a").hover(function(e)
   {
      var timer;
      if (timer)
      {
         clearTimeout(timer);
         timer = null;
      }
      timer = setTimeout(function()
      {
         //alert('gdsfgsdfgsd');
         $("body").append("<p id='img_big_preview'>Быстрый предпросмотр</p>");
         $("#img_big_preview").css("top", 200);
         $("#img_big_preview").css("left", 200);
         $("#img_big_preview").fadeIn("fast");
      }, 500)
   },
   function()
   {
      $("#img_big_preview").remove();
   }
  );*/

   // about/advertising.php
   $('#adv_mailto_a').click(function()
   {
      $('#adv_mailto_form').slideToggle("fast");
   });

  /*show-hide tags*/
  $('#tags').click(function() {
   $('#div_tags').slideToggle("fast")
  });
  /*search settings*/
  $('#ss_rubrics').click(function() {
   /*$('#div_ss_rubrics').slideToggle("fast");
   $('#div_ss_rubrics2').slideToggle("fast");*/
   $('#div_ss_rubrics').hide();
   $('#div_ss_rubrics2').show();
   $('#div_ss_button').show();
  });
  $('#ss_regions').click(function() {
   $('#div_ss_regions').hide();
   $('#div_ss_regions2').show();
   $('#div_ss_button').show();
  });
  $('#ss_types').click(function() {
   $('#div_ss_types').hide();
   $('#div_ss_types2').show();
   $('#div_ss_button').show();
  });
  $('#q').click(function() {
   $('#div_ss_button').show();
  });
  $('#q').change(function() {
   $('#div_ss_button').show();
  });
  $('#ss_additional_params').click(function() {
     $('#ss_additional_params_link').hide();
   $('#div_ss_additional_params').slideToggle("fast");
   $('#div_ss_button').show();
     $('#ss_additional_params_link2').show();
  });
  $('#ss_additional_params2').click(function() {
     $('#ss_additional_params_link2').hide();
   $('#div_ss_additional_params').slideToggle("fast");
     $('#ss_additional_params_link').show();
   $('#div_ss_button').show();
  });

   /*office/prices*/
   $('#price_sourse_www').click(function() {
      $('#div_price_sourse_www').show();
      $('#div_price_sourse_file').hide();
   });
   $('#price_sourse_file').click(function() {
      $('#div_price_sourse_file').show();
      $('#div_price_sourse_www').hide();
   });
   $('#currency_id').change(function() {
      var a=0;
      $a=$("#currency_id option:selected").val();
      if ($a!=1) {$('#div_usd_currency_rate_mode').show();}
      else {$('#div_usd_currency_rate_mode').hide();}
   });
   $('#div_usd_currency_rate_mode').change(function() {
      var a=0;
      $a=$("#div_usd_currency_rate_mode option:selected").val();
      if ($a==1) {$('#div_usd_currency_rate').show();}
      else {$('#div_usd_currency_rate').hide();}
   });
  /*$('#op_www').click(function() {
   $('#div_op_www').show();
   $('#div_op_file').hide();
   $('input:radio[name="file_types_id"]').filter('[value="1"]').attr("disabled","");
   $('#div_op_refresh_after_days').show();
  });
  $('#op_file').click(function() {
   $('#div_op_www').hide();
   $('#div_op_file').show();
   $('input:radio[name="file_types_id"]').filter('[value="2"]').attr('checked', true);
   $('input:radio[name="file_types_id"]').filter('[value="1"]').attr("disabled","disabled");
   $('#div_op_xls_settings').show();
   $('#div_op_refresh_after_days').hide();
  });
  $('#op_xml_settings').click(function() {
   $('#div_op_xls_settings').hide();
  });
  $('#op_xls_settings').click(function() {
   $('#div_op_xls_settings').show();
  });
  $('#price_currency_id').change(function() {
   var a=0;
   $a=$("#price_currency_id option:selected").val();
   if ($a!=1) {$('#div_op_price_usd_currency_rate_type').show();}
   else {$('#div_op_price_usd_currency_rate_type').hide();}
  });
  $('#price_usd_currency_rate_type').change(function() {
   var a=0;
   $a=$("#price_usd_currency_rate_type option:selected").val();
   if ($a==1) {$('#div_op_price_usd_currency_rate').show();}
   else {$('#div_op_price_usd_currency_rate').hide();}
  });*/


   /*$('#div_op_currency').show();*/

  /*login*/
  $('#login_link, #login_link2').click(
  function()
  {
   var dW = $(document).width();
   var dH = $(document).height();
   $('#mask').css({'width':dW,'height':dH});
   $('#mask').fadeIn();
   $('#mask').fadeTo('fast', 0.3, function()
   {
      $('#login_form').show();
   });
   return false;
  });
  $('#login_form_close, #mask').click(
  function ()
  {
   $('#login_form').hide();
   $('#mask').fadeOut('fast');
  });

 /*social*/
   var is_toogled = false;
   $('.jsb-wrap a').attr({target: '_blank'});
   $('.jsb-wrap').hover(
      function() {
         $(this).addClass('jsb-current');
         $('.jsb-current ul').css({opacity: 0}).hide();
         $('.jsb-current .jsb-list1').animate({opacity: 1}, 300).show();
         $('.jsb-current .jsb-title').addClass('jsb-s1').removeClass('jsb-s2');
      },
      function() {
         if( is_toogled == true ) { $('.jsb-title').click(); }
         $('.jsb-current ul').hide();
         $('.jsb-current .jsb-title').removeClass('jsb-s1').removeClass('jsb-s2');
         $('.jsb-current .jsb-title span').text('Добавить в закладки');
         $('.jsb-wrap').removeClass('jsb-current');
      }
   );
   $('.jsb-title').toggle(
      function() {
         $('.jsb-current .jsb-list1').css({opacity: 0}).hide();
         $('.jsb-current .jsb-list2').animate({opacity: 1}, 300).show();
         $('.jsb-current .jsb-title').removeClass('jsb-s1').addClass('jsb-s2');
         $('.jsb-current .jsb-title span').text('Добавить в соц. сервисы');
         is_toogled = true;
      },
      function() {
         $('.jsb-current .jsb-list2').css({opacity: 0}).hide();
         $('.jsb-current .jsb-list1').animate({opacity: 1}, 300).show();
         $('.jsb-current .jsb-title').removeClass('jsb-s2').addClass('jsb-s1');
         $('.jsb-current .jsb-title span').text('Добавить в закладки');
         is_toogled = false;
      }
   );

 }
 );

function rubrics_show_hide(id, reverse)
{
 if (reverse==null) {reverse=0;}
 //alert(reverse);
 element_id='r_'+id;
 span_id='span_'+id;
 //alert(id+'; '+element_id);
 var element=document.getElementById(element_id);
 var element_status=element.className;
 //alert(element+'; '+element_status+'; ');
 if (reverse==0)
 {
  if (element_status=='')
  {
   element.className='1';
   element.style.display='block';
   document.getElementById(span_id).innerHTML='<img src="/img/r1-minus.gif" width="9" height="9" alt="" border="0" style="margin: 0 3 0 0;">';
  }
  else
  {
   element.className='';
   element.style.display='none';
   document.getElementById(span_id).innerHTML='<img src="/img/r1-plus.gif" width="9" height="9" alt="" border="0" style="margin: 0 3 0 0;">';
  }
 }
 else
 {
  if (element_status=='')
  {
   element.className='1';
   element.style.display='none';
   document.getElementById(span_id).innerHTML='<img src="/img/r1-plus.gif" width="9" height="9" alt="" border="0" style="margin: 0 3 0 0;">';
  }
  else
  {
   element.className='';
   element.style.display='block';
   document.getElementById(span_id).innerHTML='<img src="/img/r1-minus.gif" width="9" height="9" alt="" border="0" style="margin: 0 3 0 0;">';
  }
 }
}


function show_hide(element_name, reverse)
{
 if (reverse==null) {reverse=0;}
 //alert(reverse);
 //alert(element_name);
 var element=document.getElementById(element_name);
 var element_status=element.className;
 //alert(element+'; '+element_status+'; ');
 if (reverse==0)
 {
  if (element_status=='')
  {
   element.className='1';
   element.style.display='block';
  }
  else
  {
   element.className='';
   element.style.display='none';
  }
 }
 else
 {
  if (element_status=='')
  {
   element.className='1';
   element.style.display='none';
  }
  else
  {
   element.className='';
   element.style.display='block';
  }
 }
}


function load_rubrics(level)
{
 //alert(level);
 l=''+document.F.elements["l"].value; //alert(l);
 //Показувати '- выберите рубрику -' чи '- все рубрики -'
 if (document.F.elements["all"]===undefined) {all=0;} else {all=1;} /*{alert('undefined');} else {alert('all');}*/
 //Виведення пікторгамки завантаження
 if (level==2)
 {
  document.getElementById("rubrics_res2").style.display='block';
  document.getElementById("rubrics_res3").style.display='none';
  document.getElementById("rubrics_res2").innerHTML='<img src="/img/loading-2.gif" width="220" height="19" alt="Загрузка..." border=0 style="margin: 0 0 0 0;">';
  document.getElementById("rubrics_res3").innerHTML='&nbsp;';
  //document.getElementById("rubrics_res4").innerHTML='&nbsp;';
  r_id=''+document.F.elements["r_id1"].options[document.F.elements["r_id1"].selectedIndex].value;
 }
 else if (level==3)
 {
  document.getElementById("rubrics_res3").style.display='block';
  document.getElementById("rubrics_res3").innerHTML='<img src="/img/loading-2.gif" width="220" height="19" alt="Загрузка..." border=0 style="margin: 0 0 0 0;">';
  //document.getElementById("rubrics_res4").innerHTML='&nbsp;';
  r_id=''+document.F.elements["r_id2"].options[document.F.elements["r_id2"].selectedIndex].value;
 }
 /*else if (level==4)
 {
  document.getElementById("rubrics_res4").style.display='block';
  document.getElementById("rubrics_res4").innerHTML='<img src="/img/loading-2.gif" width="220" height="19" alt="Загрузка..." border=0 style="margin: 0 0 0 0;">';
  r_id=''+document.F.elements["r_id3"].options[document.F.elements["r_id3"].selectedIndex].value;
 }*/

 JsHttpRequest.query
 ('/templates/load_rubrics.php',
  {
   'level': level,
   'l': l,
   'all': all,
   'r_id': r_id
  },
  //Function is called when an answer arrives.
  function(result, errors)
  {
   //Write errors to the debug div.
   //document.getElementById("debug").innerHTML = errors;
   //Write the answer.
   if (result)
   {
    if (level==2) {document.getElementById("rubrics_res2").innerHTML=result["js_res"];}
    else if (level==3) {document.getElementById("rubrics_res3").innerHTML=result["js_res"];}
    //else if (level==4) {document.getElementById("rubrics_res4").innerHTML=result["js_res"];}
   }
  },
  false //do not disable caching
 );
}



function load_regions(level)
{
 //alert(level);
 //alert('/templates/load_regions.php');
 l=''+document.F.elements["l"].value; //alert(l);
 //Показувати '- выберите рубрику -' чи '- все рубрики -'
 if (document.F.elements["all"]===undefined) {all=0;} else {all=1;} /*{alert('undefined');} else {alert('all');}*/
 //Виведення пікторгамки завантаження
 if (level==2)
 {
  document.getElementById("regions_res2").style.display='block';
  document.getElementById("regions_res3").style.display='none';
  document.getElementById("regions_res2").innerHTML='<img src="/img/loading-2.gif" width="220" height="19" alt="Загрузка..." border=0 style="margin: 0 0 0 0;">';
  document.getElementById("regions_res3").innerHTML='&nbsp;';
  //document.getElementById("regions_res4").innerHTML='&nbsp;';
  rgn_id=''+document.F.elements["rgn_id1"].options[document.F.elements["rgn_id1"].selectedIndex].value;
 }
 else if (level==3)
 {
  document.getElementById("regions_res3").style.display='block';
  document.getElementById("regions_res3").innerHTML='<img src="/img/loading-2.gif" width="220" height="19" alt="Загрузка..." border=0 style="margin: 0 0 0 0;">';
  //document.getElementById("regions_res4").innerHTML='&nbsp;';
  rgn_id=''+document.F.elements["rgn_id2"].options[document.F.elements["rgn_id2"].selectedIndex].value;
 }
 /*else if (level==4)
 {
  document.getElementById("regions_res4").style.display='block';
  document.getElementById("regions_res4").innerHTML='<img src="/img/loading-2.gif" width="220" height="19" alt="Загрузка..." border=0 style="margin: 0 0 0 0;">';
  rgn_id=''+document.F.elements["rgn_id3"].options[document.F.elements["rgn_id3"].selectedIndex].value;
 }*/
 //alert('load_regions.php');
 JsHttpRequest.query
 ('/templates/load_regions.php',
  {
   'level': level,
   'l': l,
   'all': all,
   'rgn_id': rgn_id
  },
  //Function is called when an answer arrives.
  function(result, errors)
  {
   //Write errors to the debug div.
   //document.getElementById("debug").innerHTML = errors;
   //Write the answer.
   if (result)
   {
    if (level==2) {document.getElementById("regions_res2").innerHTML=result["js_res"];}
    else if (level==3) {document.getElementById("regions_res3").innerHTML=result["js_res"];}
    //else if (level==4) {document.getElementById("regions_res4").innerHTML=result["js_res"];}
   }
  },
  false //do not disable caching
 );
}

