// JavaScript Document

// google_analitics
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-2914633-2']);
  _gaq.push(['_setDomainName', 'rau.am']);
  _gaq.push(['_setAllowHash', false]);
  _gaq.push(['_trackPageview']);

  (function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();



// Audio on news
AudioPlayer.setup("gazeta/audio-player/player.swf", {width: 200,transparentpagebg:"yes"});





jQuery.noConflict();
jQuery(document).ready(function(){

// hor_menu
var closetimer = 0;
	if(jQuery(".menu_horizont")) {
		jQuery(".menu_horizont b").mouseover(function() {
		clearTimeout(closetimer);
			if(this.className.indexOf("clicked") != -1) {
				jQuery(this).parent().next().slideUp(100);
				jQuery(this).removeClass("clicked");
			}
			else {
				jQuery(".menu_horizont b").removeClass();
				jQuery(this).addClass("clicked");
				jQuery(".menu_horizont ul:visible").slideUp(100);
				jQuery(this).parent().next().slideDown(500);
			}
			return false;
		});
		jQuery(".menu_horizont").mouseover(function() {
		clearTimeout(closetimer);
		});
		jQuery(".menu_horizont").mouseout(function() {
			closetimer = window.setTimeout(function(){
			jQuery(".menu_horizont ul:visible").slideUp(100);
			jQuery(".menu_horizont b").removeClass("clicked");
			}, 2000);
		}); 
	}


// news list								
	jQuery('.news_slideup').
	click(function(event){
				   var $news_more=jQuery('.openly > .news_more');
				   var $news_short=jQuery('.openly > .news_short');
				   var $news_text=jQuery('.openly > .news_text');
				   var $news_slideup=jQuery('.openly > .news_slideup');
				   $news_more.slideDown("slow");
				   $news_short.fadeIn("slow");
				   $news_slideup.slideUp("slow");
				   $news_text.slideUp("slow", function() {
					   $news_text.empty();
				   });
				   jQuery('.news_item').removeClass("openly");
						});
	
	jQuery('a[rel=news_link]').
	click(function(event){
				   
				   var isopenly=false;
				   var $news_more=jQuery('.openly > .news_more');
				   var $news_short=jQuery('.openly > .news_short');
				   var $news_text=jQuery('.openly > .news_text');
				   var $news_slideup=jQuery('.openly > .news_slideup');

				   
				   var news_id=jQuery(this).parent().parent().attr('id');
				   
				   if(jQuery(this).parent().parent().is('.openly'))
				   {
					   isopenly=true;
				   }
				   $news_more.slideDown("slow");
				   $news_short.fadeIn("slow");
				   $news_slideup.slideUp("slow");
				   $news_text.slideUp("slow", function() {
					   $news_text.empty();
				   });
				   jQuery('.news_item').removeClass("openly");
				   if(!isopenly)
				   {
					   jQuery(this).parent().parent().addClass("openly");
					   jQuery('.openly > .news_text').
					   load("news_from_id.php",{nid: news_id}, function(){
							jQuery('.openly > .news_slideup').slideDown("slow");
							jQuery('.openly > .news_short').slideUp("slow");
							jQuery('.openly > .news_more').slideUp("slow");
							jQuery('.openly > .news_text').slideDown("slow");
							});
				   }
				   return false;
				   });
	
	jQuery('a[rel=video_link]').
	click(function(event){
				   
						var video_okno=jQuery(this).attr('rev');
						var news_id=jQuery(this).parent().parent().attr('id')
						jQuery(video_okno).fadeIn('slow');
						jQuery(video_okno).
						load("news_video.php",{nid: news_id}, function(){
							});
						return false;
						});
	
	jQuery('.news_video_win').
	click(function(event){
						jQuery(this).fadeOut('slow');
						jQuery(this).empty();
						});
	
// search

			  var def_val_str = jQuery("#def_val").val();
		jQuery("#gsearch_btn").click(function () {
			  if(jQuery("#gsearch").val()=="" || jQuery("#gsearch").val()==def_val_str)
			  return false;			  
			});
    		jQuery("#gsearch").focus(function () {
			  if(jQuery("#gsearch").val()==def_val_str)
			  jQuery("#gsearch").val("");
			});
		function defvalstr()
		{
			  if(jQuery("#gsearch").val()=="")
			  jQuery("#gsearch").val(def_val_str);
		}

		jQuery("#gsearch").blur(defvalstr());
		defvalstr();

// right column

		jQuery(".right_block_item > a[href]").hover(
			  function () {
				  jQuery(this).find(".right_block_item_more").fadeIn("fast");
			  }, 
			  function () {
				  jQuery(this).find(".right_block_item_more").fadeOut("fast");
			  }
		  );
// photorep_n						
/*
	function showWidth(w) {
      $("#shirina").text(w);
    }
*/	
		var $shirina=0;
		var $item_width=0;
		var $kratnoe=0;
		var $raschetnyj=0;
		
			$shirina=jQuery(".all_year_gal").parent().width();
			$item_width=190;
			$kratnoe=Math.floor($shirina/$item_width);
			$raschetnyj=Math.floor(($shirina-($kratnoe*190))/2)+"px";
			jQuery(".all_year_gal").css("padding-left",$raschetnyj);
		//  	showWidth("shirina: "+$shirina+", kratnoe: "+$kratnoe+", raschetnyj: "+$raschetnyj); 
		jQuery(window).resize(function() {
			$shirina=jQuery(".all_year_gal").parent().width();
			$item_width=190;
			$kratnoe=Math.floor($shirina/$item_width);
			$raschetnyj=Math.floor(($shirina-($kratnoe*190))/2)+"px";
			jQuery(".all_year_gal").css("padding-left",$raschetnyj);
		//  	showWidth("shirina: "+$shirina+", kratnoe: "+$kratnoe+", raschetnyj: "+$raschetnyj); 
			
		
		});
	jQuery(".all_year_gal").fadeIn('slow');
	/*
	jQuery(".gallery:first a[rel^='lightbox']").prettyPhoto({animation_speed:'normal',theme:'light_square',slideshow:3000, autoplay_slideshow: true});
	jQuery(".gallery:gt(1) a[rel^='lightbox']").prettyPhoto({animation_speed:'fast',slideshow:10000, hideflash: true});
	*/
	jQuery(".gallery a[rel^='lightbox']").prettyPhoto({animation_speed:'normal',theme:'facebook',slideshow:10000, hideflash: true, autoplay_slideshow: false});


	var soc_str="";
	var ii=0;
	var	u=location.href, t=document.title, soc_shirina=0;
	var soc_ar=new Array(
				'"http://www.facebook.com/sharer.php?u='+u+'&t='+t+'" title="Поделиться в Facebook"',
				'"http://vkontakte.ru/share.php?url='+u+'&title='+t+'" title="Поделиться В Контакте"',
				'"http://twitter.com/share?text='+t+'&url='+u+'" title="Добавить в Twitter"',
				'"http://www.odnoklassniki.ru/dk?st.cmd=addShare&st._surl='+u+'&title='+t+'" title="Добавить в Одноклассники"',
				'"http://www.livejournal.com/update.bml?event='+u+'&subject='+t+'" title="Опубликовать в LiveJournal"',
				'"http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk='+u+'&title='+t+'" title="Сохранить закладку в Google"');
	kakie=new Array(1,1,1,0,1,1);
	jQuery.each(soc_ar, function(key, value) {
		if(!kakie[key]) return true; 
      soc_str+='<a rel="nofollow" class="share_link" style="background-position:-'+32*key+'px 0;" href='+value+' target="_blank"></a>';
	  soc_shirina+=32+7;
   });

	jQuery("#share").width(soc_shirina);
	jQuery("#share").html(soc_str);


});

