$(document).ready(function() {
 /*$('#top_menu td').mouseover(function() {
	 id=$(this).attr('id');
	    $('#'+id+' .head_menu_falling').show();
	 });
	 $('#top_menu td').mouseout(function() {
	 id=$(this).attr('id');
		$('#'+id+' .head_menu_falling').hide();
	 });*/
	 
	$('.dopmenu .today').addClass('right');
	$('.dopmenu .down').removeClass('right');
	$('.dopmenu .today_text').hide();
	$('.dopmenu .viewnow').show();
    idclosed = $('.closed').parents().attr('id');

	$('#'+idclosed+' .today_text').hide();
	$('.dopmenu .today_text').removeClass('viewnow');
	$('.dopmenu .today').click(function() {
	    id = $(this).parents().attr('id');
		head_class = $('#'+id+' .today').attr('class');
		if (head_class=="today right") {
			showDopBlock(id);
		}else {
		
		if (head_class=="today down") {
			hideDopBlock(id);
		}			
		}
	});

	$('.dopmenu1 .today_text').hide();
	$('.dopmenu1 .today').addClass('right');
	$('.dopmenu1 .today').toggle(function() {
	  id = $(this).parents().attr('id');
	  $('#'+id+' .today_text').show();
	  $('#'+id+' .today').removeClass('right');
	  $('#'+id+' .today').addClass('down');
	
	}, function() {
	  id = $(this).parents().attr('id');
          $('#'+id+' .today').removeClass('down');
	  $('#'+id+' .today_text').hide();
	  $('#'+id+' .today').addClass('right');
	});


	ts = $('.form form input[name=name]').val();
	if (ts=='') {
		$('.form .formbody').hide();
	}
	
	/*url = window.location;
	callback = url.split('#');
	yakor = callback[0];
	alert(yakor);
	if (url.search("callback")) {
	  $('.formbody').show();
	}*/
	
	$('.form span').toggle(function() {

	  id = $(this).parents().attr('id');
	  $('#'+id+' .formbody').show();
	
	}, function() {
	  id = $(this).parents().attr('id');
	  $('#'+id+' .formbody').hide();
	});
  
  img = $('.photo_list li').first().attr('_rel');
  $('.photo_list li').first().addClass('bg_tut');
  $('#photo_preview img').attr('src',img); 
  
  $('.photo_list li').hover(function() {
  img = $(this).attr('_rel');
  $('.photo_list li').removeClass('bg_tut');
  $(this).addClass('bg_tut');
  $('#photo_preview img').attr('src',img); 
  
  });
  
  img = $('.video_list li').first().attr('_rel');
  $('.video_list li').first().addClass('bg_tut');
  $('#video_preview img').attr('src',img); 

  
  $('.video_list li').hover(function() {
  img = $(this).attr('_rel');
  $('.video_list li').removeClass('bg_tut');
  $(this).addClass('bg_tut');
  $('#video_preview img').attr('src',img); 
  
  });
  
  $('.archive_rating li:odd').addClass('blue_bg');
  $('.archive_rating1 li:odd').addClass('blue_bg');
  $('.pollresults_archive li').removeClass('blue_bg');
  
  $('.itograting tr:odd').addClass('blue_bg');

  cat_id = $('.pollcat_id a').attr("_id");
  $('#cat'+cat_id).addClass('active');
  
  $('.allpolls tr:odd').addClass('blue_bg');
  

  $('.tablename .min_info').hover(function() {
    // $('.tablename span').removeClass('supervisor');
     $(this).addClass('supervisor');
  },function() {
      $('.tablename span').removeClass('supervisor');
  });
  
  pid = $('.list_photo li:first').attr('id');
  BigImgShow(pid);
  
  //var videoid = $.getUrlVar('video');
 // alert(byName);
  //if (!videoid) {
	//videoid = $('.v_list li:first').attr('id');
 // }
  //show_player(videoid);
  $('.itograting .introtext').hide();
  $('.itograting img').hover(function(){
     personid = $(this).attr('id');
     $('#introtext'+personid).show();
  }, function() {
         personid = $(this).attr('id');
     $('#introtext'+personid).hide();

  });

  var archive_okrug = $.getUrlVar('archive_okrug');
  if (archive_okrug>0) {
    $('.list_okrug_min li a').each(function() {
      strlink = $(this).attr('href');
      ao = strlink.split('=');
      if (archive_okrug==ao[1]) {
	$(this).css("color","#9B0000");
      }

    });  
  }
//alert();
if(window.location.href.indexOf('vibori-mera') + 1) {
    $('.list_okrug_min li a').each(function() {
      strlink = $(this).attr('href');
      if (strlink=='/vibori-mera') {
	$(this).css("color","#9B0000");
      }

    });

//alert(strlink);  

}

if(window.location.href.indexOf('vibori-deputatov') + 1) {
    $('.list_okrug_min li a').each(function() {
      strlink = $(this).attr('href');
      if (strlink=='/vibori-deputatov') {
	$(this).css("color","#9B0000");
      }

    });
}

if(window.location.href.indexOf('mer') + 1) {
$('#mer').css("color","#9B0000");

}

$('.insertvideo').click(function() {
  var li;
  li = $(this).parent('li');
  vc = li.children('.video_code').html();
  $('#video_code .ins_video_code').html(vc);
  $('#video_code').show();

});



});

function TurnTriptixBlock(img_id, text_id)
                    {
                        $(".news_pics").hide();
                        $(".news_pics").removeClass("news_pics");
                        $("#"+img_id).addClass("news_pics");
                        $("#"+img_id).show();
                        $(".tut").removeClass("tut");
                        $("#"+text_id).addClass("tut");
                    }
function TurnTriptixBlockR(img_id, text_id)
                    {
                        $(".rating_pics").hide();
                        $(".rating_pics").removeClass("rating_pics");
                        $("#"+img_id).addClass("rating_pics");
                        $("#"+img_id).show();
                        $(".tut").removeClass("tut");
                        $("#"+text_id).addClass("tut");
                    }

function showMenu(id) {

	    $('#'+id+' .head_menu_falling').show();
}

function hideMenu(id) {
		$('#'+id+' .head_menu_falling').hide();
}

function showDopBlock(id) {

	    $('#'+id+' .today_text').show();
		$('#'+id+' .today').removeClass('right');
		$('#'+id+' .today').addClass('down');
}

function hideDopBlock(id) {
		$('#'+id+' .today_text').hide();
		$('#'+id+' .today').removeClass('down');
		$('#'+id+' .today').addClass('right');
}

function BigImgShow(id) {
  photo = $('#'+id).attr("_src");
  tp = $('#'+id+' img').attr("alt");
  original_photo = $('#'+id).attr("_op");
  $('#photo_big').attr("_id",id);
  $('#gpt').attr("src",photo);
  $('#zoom_photo').attr("href",original_photo);
  $('#phototext').text(tp);


}

function ShowImage(img) {
    window.open(img,'pic','width=500,height=500');
}

function ImgShowBack() {
    id = $('#photo_big').attr("_id");
	backid = $('#'+id).prev('li').attr('id');
	BigImgShow(backid);

}
function ImgShowNext() {
    id = $('#photo_big').attr("_id");
	nextid = $('#'+id).next('li').attr('id');
	BigImgShow(nextid);
}

function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
 
function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("������� CTRL-D, ����� �������� �������� � ��������.");
 return false;
}

function show_player(id) {
    url = $('#'+id+' a:first').attr('_url');
	$('div.ramka').removeClass("ramka1");
	$('#'+id+' .ramka').addClass("ramka1");
  	var flashvars = {uid:"videoplayer1","m":"video",st:"http://politika-dzr.ru/video33-1425.txt",file:"http://politika-dzr.ru/"+url};
	var params = {bgcolor:"#ffffff", allowFullScreen:"true", allowScriptAccess:"always"};
	var attributes = {id:"videoplayer1",name:"videoplayer1"};
	swfobject.embedSWF("http://politika-dzr.ru/assets/templates/main/uppod.swf", "videoplayer1", "500", "375", "9.0.0",false,flashvars, params,attributes);
	setTimeout("PlayUppod()", 6500);
	setTimeout("load_video_text('"+id+"')", 1200);
	
	
}

 function load_player(url){
	var flashvars = {uid:"videoplayer1","m":"video",st:"http://politika-dzr.ru/video33-1425.txt",file:"http://politika-dzr.ru/"+url};
	var params = {bgcolor:"#ffffff", allowFullScreen:"true", allowScriptAccess:"always"};
	var attributes = {id:"videoplayer1",name:"videoplayer1"};
	swfobject.embedSWF("http://politika-dzr.ru/assets/templates/main/uppod.swf", "videoplayer1", "500", "375", "9.0.0",false,flashvars, params,attributes);
	setTimeout("PlayUppod()", 2500);
}

function PlayUppod(){
uppodSend('videoplayer1','play');
}

function load_video_text(id){
    name = $('#'+id+'name').text();
	$('#video_name').text(name);
	date = $('#'+id+'date').text();
	$('#video_date').text(date);
	introtext = $('#'+id+'introtext').text();
	$('#video_introtext').text(introtext);
}

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});


