/**
 * @author sergeyk
 */


jQuery(document).ready(function()
{
    jQuery('#k-annonce-up').css('visibility', 'hidden');
    var number = parseFloat(jQuery("#tv-annonce-list li").size());      //Количество файлов в анонсе
    var visible_list = 5;  
                                        //Количество видемой области
    var position_list = (number - visible_list)*1;
    //alert(position_list); 
    var down = 0;
                                                                        
    if(position_list <= 0)
    {
        jQuery('#k-annonce-down').css('visibility', 'hidden');
    }
    else
    {  
        jQuery('#k-annonce-down').click(function()
        {   
            jQuery('#tv-annonce-list li').eq(down).slideUp();
            down++;
                                                                                
            jQuery('#k-annonce-up').css('visibility', 'visible');
            position_list--;
            if (position_list <= 0)
            {
                jQuery(this).css('visibility', 'hidden');   
            }
        });
                                                                            
        jQuery('#k-annonce-up').click(function()
        {
            jQuery('#tv-annonce-list li').eq(down-1).slideDown();
            down--;
                                                                                
            jQuery('#k-annonce-down').css('visibility', 'visible');
            position_list++;
            if(position_list == number - visible_list)
            {
                jQuery(this).css('visibility', 'hidden');   
            } 
        });
    }                                                                            
                                                                                
//});


//jQuery(document).ready(function()
//{
    var chLabel = jQuery('#channelslabel');
    var chSlider = jQuery('#channelwrap');
    var chSliderHstart = chSlider.height();
    var chSliderHend = '-' + chSlider.height() + 'px';
    chLabel.toggle(function()
    {
        chSlider.animate(
        {
            bottom:'-' + chSlider.height() + 'px'
        },'slow');
    },function()
    {
        chSlider.animate(
        {
            bottom:'-10px'
        },'slow');
    })
	jQuery('#nav li')
	.hover(function(){
					jQuery(this).addClass('hover');
					},function(){
						jQuery(this).removeClass('hover')
						})
	jQuery('#onflash-ico-open').click(function(e)
	{
		jQuery('#flash-section').slideDown('hide');
		jQuery(this).fadeOut();
		e.preventDefault();
	})
	jQuery('#onflash-ico-close').click(function(e)
	{
		jQuery('#flash-section').slideUp('hide');
		jQuery('#onflash-ico-open').fadeIn();
		e.preventDefault();
	})
	/*var down = 0;
    jQuery('#k-annonce-down').click(function()
    {
    	jQuery('#tv-annonce-list li').eq(down).slideUp();
        down=down+2;
        jQuery('#k-annonce-up').css('visibility', 'visible');
        var bLast = false;
        var list_height = 0;
        jQuery('#tv-annonce-list li:visible').each(function () {
        	list_height = list_height + jQuery(this).height();
        });
        bLast = (list_height <= jQuery('#flash-pager-slider').height());
        if (bLast) {
        	jQuery(this).css('visibility', 'hidden');
        }
    })
	jQuery('#k-annonce-up').click(function()
    {
        if(down > 0 ) down--;
        if (!down) {
        	jQuery(this).css('visibility', 'hidden');
        }
        jQuery('#tv-annonce-list li').eq(down).slideDown();
        jQuery('#k-annonce-down').css('visibility', 'visible');
    })*/
		jQuery('.ij_list .ij_preview').hover(function(e)
        {
			//console.log(window.innerHeight);
            var ij_previewPos = jQuery(this).offset();
			var pageX = e.pageX - 1 + 'px';
			var pageY = e.pageY - 1 + 'px';
            jQuery('#ij_tooltip').css(
            {
                left: pageX,
                top:  pageY
            }).hover(function()
			{
				jQuery(this).css(
					{
						left: pageX,
						top:  pageY
					}
				)
			},function()
			{
				jQuery(this).css(
					{
						left: '-9999px',
						top:  '-9999px'
					}
				)
			});
        },function()
		{
			jQuery('#ij_tooltip').css(
            {
                left:'-9999px',
                top:'-9999px'
            });
		})
        
        
    $('#logo h2 a').mouseover(function(){
        var poloj=parseFloat($(".ptic").css('left'));
     //   if(poloj>-499 && poloj>1499)
     //   {
            var x=rand( 50, 600); 
            if(poloj<0)
                {var y=4000;$(".ptic img").attr('src','/img/pchel_r.png');}
            else
                {var y=-500;$(".ptic img").attr('src','/img/pchel_l.png');}
           // alert(y);    
            $(".ptic").animate({"left": y+"px","top": x+"px"}, 3500);
            
       // }
              
    });   
    
        function rand( min, max ) 
        {	// Generate a random integer
        	// 
        	// +   original by: Leslie Hoare
        
        	if( max ) {
        		return Math.floor(Math.random() * (max - min + 1)) + min;
        	} else {
        		return Math.floor(Math.random() * (min + 1));
        	}
        }     
})

