var flowPlayerConfiguration = {
	plugins: {
		controls: {
			autoHide: true
		}
	},
    clip: {
        autoPlay: true,
        autoBuffering: true
    }
};
var openVisor = false;

var LayerSeccionVideosActivateEvent = function(){
	$('#imagen_icono_cerrar_seccion_videos').click(function(){
		if(openVisor){
			$f('player_video').stop();
			$f('player_video').close();
			$('#pane_visor_video').fadeOut('fast');
			openVisor = false;
		}else{
			application.show('layer_home');	
		}
	});	
	$('#imagen_icono_cerrar_seccion_videos').hover(
			function(){$(this).attr('src','application/resources/images/go_back_over.png');},
			function(){$(this).attr('src','application/resources/images/go_back.png');}
	);
	
	$('#pane_visor_video').css('left',application.dimension.calculateCenterHorizontal($('#layer_seccion_videos'),$('#pane_visor_video'))+'px');
	$('#pane_visor_video').css('top',(application.dimension.calculateCenterVertical($('#layer_seccion_videos'),$('#pane_visor_video')) -5)+'px');

	$('#titulo_video').css('left',application.dimension.calculateCenterHorizontal($('#player_video'),$('#titulo_video'))+'px');
	
	$('#pane_lista_videos').css('left',application.dimension.calculateCenterHorizontal($('#layer_seccion_videos'),$('#pane_lista_videos'))+'px');
	$('#pane_lista_videos').css('top',(application.dimension.calculateCenterVertical($('#layer_seccion_videos'),$('#pane_lista_videos'))+ 10)+'px');

	configListaVideos();
	
	$('div.ResumenVideo').hover(
		function(){//this.className = 'ResumenVideoOver Event';
			$(this).switchClass('ResumenVideo','ResumenVideoOver',100);
			$(this).find('span.DescripcionVideo').switchClass('TextoEfectoOut','TextoEfectoOver',100);
			$(this).children('span.PlayVideo').children('img.ThumbVideo').animate({
				'left':'110px',
				'margin-top':'10px',
				'height':'90px'
			},100);
		},
		function(){//this.className = 'ResumenVideo Event';
			$(this).switchClass('ResumenVideoOver','ResumenVideo',100);
			$(this).find('span.DescripcionVideo').switchClass('TextoEfectoOver','TextoEfectoOut',100);
			$(this).children('span.PlayVideo').children('img.ThumbVideo').animate({
				'left':'130px',
				'margin-top':'32px',
				'height':'76px'
			},100);
		}
	);

	$('div.ResumenVideo').click(function(){
			var url = $(this).children('span.InfoHidden').children('span[title=url]').text();
			var videoWidth = parseInt($(this).children('span.InfoHidden').children('span[title=width]').text());
			var videoHeight = parseInt($(this).children('span.InfoHidden').children('span[title=height]').text());
			var text = $(this).find('span.InfoHidden > span[title=titulo]').html();
			
			$('#pane_visor_video > div.Titulo3').html(text);

			$('#pane_visor_video').fadeIn('slow');

			$('#player_video').attr('href',url);
			$('#player_video').width(videoWidth);
			$('#player_video').height(videoHeight);

			$('#player_video').css('left',application.dimension.calculateCenterHorizontal($('#pane_visor_video'),$('#player_video'))+'px');
			$('#player_video').css('top',(application.dimension.calculateCenterVertical($('#pane_visor_video'),$('#player_video'))) - 10 +'px');

			$('#player_video').flowplayer('application/libs/flowplayer/flowplayer-3.2.2.swf',flowPlayerConfiguration);
			openVisor = true;			
		}
	);

	$('#imagen_icono_cerrar_pane_visor_video').hover(
			function(){$(this).attr('src','application/resources/images/close_over.png');},
			function(){$(this).attr('src','application/resources/images/close.png');}
	);
	
};
var indexList = 0;
var indexEndList = 0;
var currentIndexNavigator = 0;
var configListaVideos = function(){
	$('#pane_lista_videos').scrollable({ vertical: true, mousewheel: true });
	
	indexEndList = $('#control_slide_videos > div.Event').size() - 1;
	
	$('#control_up_list_videos').hide();
	$('#control_up_list_videos').click(function(){
		if(indexList > 0){	indexList--;}
		$('#pane_lista_videos').scrollable().seekTo(indexList);
		updateNavigatorVideos();
	});
	$('#control_up_list_videos').hover(
			function(){
				$(this).attr('src', 'application/resources/images/up_over.png');
			},
			function(){
				$(this).attr('src', 'application/resources/images/up.png');
			}
	);
	
	$('#control_down_list_videos').click(function(){
		if(indexList < indexEndList){	indexList++;}
		$('#pane_lista_videos').scrollable().seekTo(indexList);
		updateNavigatorVideos();
	});

	$('#control_down_list_videos').hover(
			function(){
				$(this).attr('src', 'application/resources/images/down_over.png');
			},
			function(){
				$(this).attr('src', 'application/resources/images/down.png');
			}
	);
	
	$('#control_slide_videos > div.Event').click(function(){
		indexList = parseInt($(this).attr('title'));
		$('#pane_lista_videos').scrollable().seekTo(indexList);
		updateNavigatorVideos();
	});
	
	$('#control_slide_videos > div.Event').hover(
			function(){
				$(this).attr('class', 'PositionSlideCV Event TextoEfectoOver');
			},
			function(){
				if($(this).attr('title')==currentIndexNavigator || $(this).attr('title')==indexList){
					$(this).attr('class', 'PositionSlideCV Event TextoEfectoResaltado');
				}else{
					$(this).attr('class', 'PositionSlideCV Event TextoEfectoOut');
				};
			}
	);
};
var updateNavigatorVideos = function(){
	if(indexList > 0 && indexList <= indexEndList){
		$('#control_up_list_videos').show();
	}else{
		$('#control_up_list_videos').hide();
	}
	if(indexList >= 0 && indexList < indexEndList){
		$('#control_down_list_videos').show();
	}else{
		$('#control_down_list_videos').hide();
	}

	$('#control_slide_videos > div.Event[title='+currentIndexNavigator+']').attr('class', 'PositionSlideCV Event TextoEfectoOut');
	currentIndexNavigator = indexList;
$('#control_slide_videos > div.Event[title='+currentIndexNavigator+']').attr('class', 'PositionSlideCV Event TextoEfectoResaltado');

};
