$(document).ready(function() {
	if($('#cycleNews .newsText').length>2){
		$('#cycleNews').jCarouselLite({  
			vertical: true,  
			visible: 3,  
			auto:5000,  
			speed:1500,		
		    btnNext: "#cycleNews_nextSlideShow",
	        btnPrev: "#cycleNews_prevSlideShow"
		});
	}  
	
	// slide show - hover
	$('#slideShow .slide').hover(
		function(){
			if(!$(this).hasClass('current'))
				$(this).addClass('active');
		},
		function(){
			if(!$(this).hasClass('current'))
				$(this).removeClass('active');
		}
	);
	
	// slide show - karuzela	
	$('#slideShow .slide').first().addClass('active current');
	$('#slideShow').jCarouselLite({  
		vertical: true,  
		visible: 4,  
		auto:5000,  
		speed:1500,
	    afterEnd: function(a) {
	    	$('#slideShow .slide').removeClass('active current');
	    	$(a).eq(0).addClass('active current');
	    },		
	    btnNext: "#nextSlideShow",
        btnPrev: "#prevSlideShow"
	    
	});  
	$("#nextSlideShow").hover(function(){$(this).addClass('nextSlideShowActive');},function(){$(this).removeClass('nextSlideShowActive');});
	$("#prevSlideShow").hover(function(){$(this).addClass('prevSlideShowActive');},function(){$(this).removeClass('prevSlideShowActive');});
	
	if($('#Videos') && $('#Videos .image').length > 0){
		// Scroll myszką
		var cont = $('#Videos .list_outer');
		var div = $('#Videos .list');
		var divMargin = 0;
		var contWidth = cont.outerWidth() - divMargin;
		var lastA = div.find('div:last');
		cont.mousemove(function(e){
			var divWidth = lastA.get(0).offsetLeft + lastA.outerWidth() - divMargin;
			var left = ((e.pageX - cont.offset().left) * (divWidth-contWidth) / contWidth);
			cont.scrollLeft(left);
		});
		
		// Otwieranie odtwarzaczy
		$('#Videos .video').click(function(){
			
			// Dla strony RU:
			$.post('mainpage.html', {'is_ajax':1, 'act':'get_video', 'id':$(this).attr('rel')}, function(data){
					if(data != "" && data != "ERROR"){
						playVideo(data);
					}
			});
			
			return false;
		});
	}
	
});

var $video, $video_bg;
function playVideo(code){
	// CLOSE ANIMATION
	if($video){
		$video_bg.fadeOut('fast', function(){$video_bg.remove();});
		$video.fadeOut('fast', function(){$video.remove();});
	}
	
	// BACKGROUND
	$vimeo_bg = $('<div id="vimeo_player_bg" style="background:#000000;top:0;left:0;position:absolute;z-index:99;display:none;"></div>');
	$vimeo_bg.width($(document).width());
	$vimeo_bg.height($(document).height());
	$vimeo_bg.css('opacity',0.7);
	$vimeo_bg.prependTo('body').fadeTo('fast', 0.7);
	$vimeo_bg.click(function(){
		$vimeo_bg.remove();
		$vimeo.remove();
	});
	// PLAYER
	$vimeo = $(''+
		'<div id="vimeo_player" style="background:#000000;position:absolute;width:404px;height:225px;display:none;z-index:1000;">'+
		'	<div style="padding:2px;background:#000000;">'+code+'</div>'+
		'	<div class="vimeo_close" style="background:url(\'/css/gfx/hector-close.png\') no-repeat top right #000000;cursor:pointer;height:22px;line-height:22px;clear:both;">&nbsp;</div>'+
		'</div>'+
	'');
	$vimeo.css({
		'left': ( $(window).width() - 400) / 2,
		'top': ( $(window).height() - 225) / 2
	});
	$vimeo.prependTo('body').fadeIn('fast');
	// CLOSE
	$vimeo.find('.vimeo_close').click(function(){
		$vimeo_bg.fadeOut('fast', function(){$vimeo_bg.remove();});
		$vimeo.fadeOut('fast', function(){$vimeo.remove();});
	});
}
