$(document).ready(function(){
    	$('.play').mouseover(function() {
		$('.darken').css('display', 'block');
		$('.darken').fadeTo("slow", 0.8);		
	});
	$('.play').mouseout(function() {
		$('.darken').fadeTo("slow", 0);
	});

$('.play').click(function() {
		$('.trailer_film_block').fadeTo("slow", 0);
		$('.trailer_film_block').css('display', 'none');
		$('.trailer_video').css('display', 'block');		
		$('.trailer_video').fadeTo("slow", 1);
		
		$('#trailer_flash').flash(
				{
				swf: 'http://tr.kinopoisk.ru/js/jw/player-licensed.swf',
				width: 580,
				height: 268,
				allowfullscreen: 'true',
				allowscriptaccess: 'always',
				wmode: 'transparent',
				
				flashvars: 'file=http://tr.kinopoisk.ru/trailers/flv/171728/kinopoisk.ru-Piranha-3-D-57463.flv&image=http://tr.kinopoisk.ru/trailers/flv/171728/1_57463.jpg&skin=http://tr.kinopoisk.ru/js/jw/overlay.swf&controlbar=over&frontcolor=ffffff&lightcolor=ff6600&stretching=unified&provider=video&vn_profile_id=66375&vn_category_id=16'
				}
		);
		
	});

$('.ee').each( function() { 		
		$(this).hover( 			
			function() { 
						$('.ee').each( function() { $(this).stop(true) ; $(this).fadeTo("fast", 1) } ) ;
						$(this).fadeTo("slow", 0.1); 						
						}, 
			function() { $(this).fadeTo("slow", 1) } 
		) 
	});

$('.aa').each( function() { 
		$(this).hover( 
			function() { $(this).fadeTo("slow", 1) }, 
			function() { $(this).fadeTo("slow", 0.4) } 
		) 
	});

$('.bb').each( function() { 
		$(this).hover( 
			function() { $(this).fadeTo("slow", 0.6) }, 
			function() { $(this).fadeTo("slow", 1) } 
		) 
	});

$('.play').mouseover(function() {
		$('.play').fadeTo("slow", 1);
		
	});

$('.play').mouseout(function() {
		$('.play').fadeTo("slow", 0.8);
		
	});

$('.s_1').mouseover(function() {
		$('.lighten_1').fadeTo("slow", 0.5);
		
	});

$('.s_1').mouseout(function() {
		$('.lighten_1').fadeTo("slow", 0);
		
	});

$('.s_2').mouseover(function() {
		$('.lighten_2').fadeTo("slow", 0.5);
		
	});

$('.s_2').mouseout(function() {
		$('.lighten_2').fadeTo("slow", 0);
		
	});

$('.s_3').mouseover(function() {
		$('.lighten_3').fadeTo("slow", 0.5);
		
	});

$('.s_3').mouseout(function() {
		$('.lighten_3').fadeTo("slow", 0);
		
	});






$('.menu a').click(function(){//$.scrollTo works EXACTLY the same way, but scrolls the whole screen
		$.scrollTo( this.hash, 1500);
		$(this.hash).find('span.message').text( this.title );
		return false;
	});

  $('.closest, .schedule li, .closest_inside').each(function () {
    // options
    var distance = 10;
    var time = 250;
    var hideDelay = 500;

    var hideDelayTimer = null;

    // tracker
    var beingShown = false;
    var shown = false;
    
    var trigger = $('.rc, .bc', this);
    var popup = $('.popup', this).css('opacity', 0);

    // set the mouseover and mouseout on both element
    $([trigger.get(0), popup.get(0)]).mouseover(function () {
      // stops the hide event if we move from the trigger to the popup element
      if (hideDelayTimer) clearTimeout(hideDelayTimer);

      // don't trigger the animation again if we're being shown, or already visible
      if (beingShown || shown) {
        return;
      } else {
        beingShown = true;

        // reset position of popup box
        popup.css({
          top: -40,
          left: -74,
          display: 'block' // brings the popup back in to view
        })

        // (we're using chaining on the popup) now animate it's opacity and position
        .animate({
          top: '-=' + distance + 'px',
          opacity: 1
        }, time, 'swing', function() {
          // once the animation is complete, set the tracker variables
          beingShown = false;
          shown = true;
        });
      }
    }).mouseout(function () {
      // reset the timer if we get fired again - avoids double animations
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      
      // store the timer so that it can be cleared in the mouseover if required
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        popup.animate({
          top: '-=' + distance + 'px',
          opacity: 0
        }, time, 'swing', function () {
          // once the animate is complete, set the tracker variables
          shown = false;
          // hide the popup entirely after the effect (opacity alone doesn't do the job)
          popup.css('display', 'none');
        });
      }, hideDelay);
    });
  });


  });