var menu_hide_timer = 0;
var qwe;

$(document).ready(
  function()
  {
  		isIE6 = !$.support.opacity && !window.XMLHttpRequest;
  		
      $('.mod_goals-switcher').click(
        function()
        {
          var sender = $(this);
          $('.goal-tab').hide();
          if ($('#current_tab').val() == '1')
          {
            $('.goal-tab2').show();  
            $('#current_tab').val('2');
            $('.mod_goals-switcher').attr('src','/templates/juv_ftheme/images/mod_goals-tab2.png');            
          }
          else
          {          
            $('.goal-tab1').show();  
            $('#current_tab').val('1');
            $('.mod_goals-switcher').attr('src','/templates/juv_ftheme/images/mod_goals-tab1.png');            
          }              
        }
      );
      
		  $('.menu-item').hover(
		    function()
		    {
		      //menuMouseover();
		      clearTimeout(menu_hide_timer);
		      
		      $('.menu-subitems').css({left:'-10000px'});
		      $('p', $('.menu-item')).removeClass('active');
		      
		      var left = $(this).attr('offsetLeft'); 
		      var item_id = $(this).attr('class').replace(/^[\D]*/,'').replace(/[\D]*$/,'');
		      var width = $('.menu-block').width();
		            
		      $('.menu-subitems-'+item_id).css({left:left+'px'});
		      $('p', $('.menu-item-'+item_id)).addClass('active');
		    },
		    function()
		    {
		      menuMouseover();
		    }
		  );
		  
		  $('.menu-subitems').hover(
		    function()
		    {
		    	clearTimeout(menu_hide_timer);
		    },
		    function()
		    {
		    	menuMouseover();
		    }
		  );
//      
//      $('.menu-item').mousemove(
//        function()
//        {
//          menuMouseover();
//        }
//      );

      $('.mod_poll-answer-center').hover(
        function()
        {
          $(this).css('text-decoration','underline');
        },
        function()
        {
          $(this).css('text-decoration','none');
        }
      ); 
      
      $('.hn').hide();
            
      $('.inp', $('#acbook-table')).parent().parent().hide();
      
      $('.mod_tournament-table tr').show();
      var scrolls = $('.scroll-pane').jScrollPane({showArrows:true, scrollbarWidth:11, dragMaxHeight:48, animateTo:true, animateInterval:50, animateStep:5});
      setTimeout(
    			function()
    			{    	
    				var index = 1;
    				var temp = true;
    				$('.mod_tournament-table tr').each(
    						function()
								{
    							if (parseInt($('td:first', $(this)).attr('command_id')) != 28 && temp)									
    								index++;
    							else temp = false;
								}
    				);

    				if (index <= 5)
    					return;
    				
		      	scroll_to = $('.mod_tournament-table').attr('scroll_to');
		      	if (scrolls.length == 2)
		      		scrolls[1].scrollTo('.mod_tournament-table-index[command_id="'+scroll_to+'"]')
		      	else if (scrolls.length == 1)
		      		scrolls[0].scrollTo('.mod_tournament-table-index[command_id="'+scroll_to+'"]')
		      	else return;
		      }
    	,600);
      
      $('.blog_list .list .content-head').corner('6px');
      
  		if (!isIE6)
  		{
  			$('.blog_list .list .content-head').append('<img src="/templates/juv_ftheme/images/list_item_title_star1.png" title="" alt="" class="star1" /><img src="/templates/juv_ftheme/images/list_item_title_star2.png" title="" alt="" class="star2" />');
  		}
  		
  		
  		jQuery('.share-link').popupWindow({ 
  			centerScreen : 1 
  		});   		
  }
);

function menuMouseover()
{
  clearTimeout(menu_hide_timer);
  menu_hide_timer = setTimeout(
    function(){
      $('.menu-subitems').css({left:'-10000px'});
      $('p', $('.menu-item')).removeClass('active');              
    }
  ,1500);
}

function doVote(id)
{
  //$('#voteid').val($('#'+id).val());
  $('#vote-form').submit();    
}

function banner_mail()
{
  document.write("<a href='http://www.liveinternet.ru/click' target=_blank rel='nofollow'><img src='http://counter.yadro.ru/hit?t26.2;r"+escape(document.referrer)+((typeof(screen)=="undefined")?"":";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+";"+Math.random()+"' alt='' title='LiveInternet:' border=0 width=88 height=15><\/a>");
}
function banner_mail2()
{
  document.write('<a href="http://top.mail.ru/jump?from=391922" target=_top rel="nofollow"><img src="http://da.cf.b5.a0.top.list.ru/counter?id=391922;t=52;js='+js+a+';rand='+Math.random()+'" alt="Ð ÐµÐ¹Ñ‚Ð¸Ð½Ð³@Mail.ru"'+' border=0 height=31 width=88></a>');
}

function initSearchPage()
{
	$(document).ready(
		  function()
		  {
		  	$('.page-navigation-table').each(
		  			function()
						{
		  				var sender = $(this);
		  				var items_container = sender.parent().parent();
		  				var index = 1;
		  				var temp = 0;
		  				
		  				$('.item', items_container).each(
		  						function(i)
									{
		  							$(this).addClass('item-' + index);
		  							
		  							if (index > 1)
		  								$(this).hide();
		  							
		  							temp++;
		  							
		  							if (temp >= 20)		  																	
		  							{
		  								index++;
		  								temp = 0;
		  							}
									}
		  				);
		  				
		  				var pages_count = parseInt($('.pages-numbers .pagenav', sender).length);
		  				$('.pages-numbers', sender).html('');
		  				for (i = 1; i <= pages_count; i++)
		  				{
		  					$('.pages-numbers', sender).append('<a href="#" class="pagenav"><strong>'+i+'</strong></a> ');
		  				}
		  				$('.pages-numbers a:first', sender).addClass('active');
		  				
		  				$('.prev-td', sender).html('<a title="Ïðåäûäóùàÿ" class="pagenav" href="#"><&nbsp;Ïðåäûäóùàÿ</a>');
		  				$('.next-td', sender).html('<a title="Ñëåäóþùàÿ" align="right" class="pagenav" href="#">Ñëåäóþùàÿ&nbsp;></a>');
		  				$('.prev-td a', sender).hide();
						}
		  	);
		  	
		  	$('.page-navigation-table .pages-numbers a').click(
		  			function()
						{
		  				var index = parseInt(jQuery.trim($(this).text()));
		  				var table = $(this).parents('.page-navigation-table');
		  				var items_container = $(this).parents('.ui-tabs-panel');
		  				var numbers_container = $(this).parents('.pages-numbers');
		  				
		  				showSaechPagingPage(index, items_container, table);
		  				
		  				$('a', numbers_container).removeClass('active');
		  				$(this).addClass('active');		  				
		  				
		  				return false;							
						}
		  	);
		  	
		  	$('.page-navigation-table .next-td a').click(
		  			function()
		  			{
		  				var sender = $(this);
		  				var table = $(this).parents('.page-navigation-table');
		  				var items_container = $(this).parents('.ui-tabs-panel');
		  				var numbers_container = $('.pages-numbers', table);
		  				var index = parseInt(jQuery.trim($('a.active', numbers_container).text()));
		  				
		  				index++;
		  				
		  				showSaechPagingPage(index, items_container, table);
		  				
		  				target = $('a.active', numbers_container).next();
		  				$('a', numbers_container).removeClass('active');
		  				target.addClass('active');		  				
		  				
		  				return false;							
		  			}
		  	);
		  	
		  	$('.page-navigation-table .prev-td a').click(
		  			function()
		  			{
		  				var sender = $(this);
		  				var table = $(this).parents('.page-navigation-table');
		  				var items_container = $(this).parents('.ui-tabs-panel');
		  				var numbers_container = $('.pages-numbers', table);
		  				var index = parseInt(jQuery.trim($('a.active', numbers_container).text()));
		  				
		  				index--;
		  				
		  				showSaechPagingPage(index, items_container, table);
		  				
		  				target = $('a.active', numbers_container).prev();
		  				$('a', numbers_container).removeClass('active');
		  				target.addClass('active');		  				
		  				
		  				return false;							
		  			}
		  	);
		  }
	);	
}

function showSaechPagingPage(index, items_container, table)
{
	$('.item', items_container).hide();
	$(document).scrollTop(100);
	$('.item-' + index, items_container).each(
			function(i)
			{
				var sender = $(this);
				setTimeout(
						function()
						{
							sender.fadeIn(300);							
						}
				,25*i)														
			}
	);	
	
	if (index == 1)
		$('.prev-td a', table).hide();
	else 
		$('.prev-td a', table).show();
	
	if (index == $('.pages-numbers a', table).length)
		$('.next-td a', table).hide();
	else
		$('.next-td a', table).show();
}

function decode_utf8(utftext) 
{
	var plaintext = ""; var i=0; var c=c1=c2=0;
	
	// while-Schleife, weil einige Zeichen uebersprungen werden
	while(i<utftext.length)
	{
		c = utftext.charCodeAt(i);
		if (c<128) 
		{
			plaintext += String.fromCharCode(c);
			i++;
		}
		else if((c>191) && (c<224)) 
		{
			c2 = utftext.charCodeAt(i+1);
			plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
			i+=2;
		}
		else 
		{
			c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
			plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
			i+=3;
		}
	}
	return plaintext;
}
