$(document).ready(function() {
	/**
	 * previous-btn png-bg
	 */
	 $("#slider").easySlider({
		 continuous:		true, 
		 numeric: 		false,
		 numericId: 		'controls',
		 auto:true,
		 pause:			5000
 	});     
	 
	 $("#slider").height('287');
	 
	 
	 $("#sliderNoticias").easySlider({
		 prevId: 		'prevNotBtn',
		 nextId: 		'nextNotBtn',	
		 continuous:		true, 
		 numeric: 		false,
		 numericId: 		'controls'
 	});     
	 $("#sliderNoticias").css('width', '880px');
	 
	 $("#sliderEmpresas").easySlider({
		 continuous:		true, 
		 numeric: 		true,
		 vertical:		false,
		 numericId: 		'controls'
 	});     
	 
	 var imgvideo = 'img/consejeros.jpg';
    if($('body.emprendedor .plandenegocio').length || $('body.videos').length || $('body.vision-dad').length || $('body.informacion').length) {
    	imgvideo = false;
    	
    }
    
    
	 $.each($('.videos_plan_negocio'),function(k, v) {
		 
		 var video = '';
		 	if($(v).html()) {
		 		video = $(v).html();
		 	} else {
		 		video = $(v).attr('href');
		 	}
	        $(v).after('<div id="video_plan'+k+'"><div>');
	        
	        _imgvideo = $(v).attr('id');
	        if($('body.emprendedor .plandenegocio').length) {
	        	_imgvideo = $(v).attr('id').replace(new RegExp( " +", "g" ), '_');
	        	_imgvideo = _imgvideo.replace(new RegExp("á+"), 'a');
	        	_imgvideo = _imgvideo.replace(new RegExp("é+"), 'e');
	        	_imgvideo = _imgvideo.replace(new RegExp("í+"), 'i');
	        	_imgvideo = _imgvideo.replace(new RegExp("ó+"), 'o');
	        	_imgvideo = _imgvideo.replace(new RegExp("ú+"), 'u');
	        	_imgvideo = _imgvideo.replace(new RegExp("Á+"), 'A');
	        	_imgvideo = _imgvideo.replace(new RegExp("É+"), 'E');
	        	_imgvideo = _imgvideo.replace(new RegExp("Í+"), 'I');
	        	_imgvideo = _imgvideo.replace(new RegExp("Ó+"), 'O');
	        	_imgvideo = _imgvideo.replace(new RegExp("Ú+"), 'U');
	        }
	        
	        var flashvars = {
	            'file':               video,
	            'skin':               'js/jwplayer/lightrv5.zip',
	            'autostart':          'false',
	            'image':(imgvideo ? imgvideo : _imgvideo),
	            'icons': false,
	             plugins: {
	            	"sharing-1": {}
	            	}
	        };

	        var params = {
	            'allowfullscreen':    'true',
	            'allowscriptaccess':  'always',
	            'bgcolor':            '#ffffff',
	            'wmode':              'transparent'
	        };

	        var attributes = {
	            'id':                 'player1',
	            'name':               'player1'
	        };

	        var w = 300;
	        var h = 294;
	        if(seccion == 'informacion') {
	            var w = 620;
	            var h = 450;
	        } else if(seccion == 'inversor') {
	            var w = 220;
	            var h = 150;
	        } else if(seccion == 'vision-dad') {
	            var w = 620;
	            var h = 450;
	        }
	        
	        var swfwplayer = 'js/jwplayer/player.swf';
	         if(video.search(/<iframe/i) != -1) {
	        	$('#video_plan'+k).html(video);
	        } else {
	        	swfobject.embedSWF(swfwplayer, 'video_plan'+k, w, h, '9', 'false', flashvars, params, attributes);
		    
	        }
	        
	        $('#video_plan'+k).find('iframe').attr('width', w).attr('height', h);
	        $(v).hide();
	        
	 });
	 
	 $('[id^="20"]').hide();
	 $('[id^="20"]:first').show();
	 
	 $('#flechaeneltiempo ul li h2').css('cursor', 'pointer').click(function() {
		 var text = $(this).text();
		 $("#"+text).slideToggle();
	 });
	 
	 
	 $('.tab-content').hide();
	    objTabsPaises = $('.tab-content:first');
	    objTabsPaises.show();
	    $('#tabsPaises a').click(function (){
	        $('#tabsPaises a.active').removeClass('active');
	        $(this).addClass('active');
	        objTabsPaises.hide();
	        objTabsPaises = $($(this).attr('href'));
	        objTabsPaises.show();
	        return false;
	    });
	    

	    sumLiControls = 0;
	    if($('ol#controls li').length) {
		    wLi = $('ol#controls li').css('width').replace('px', '');
		    lLi = $('ol#controls li').length;
		    
		    wControls = lLi * (parseInt(wLi) + 47);
		    
		    
		    $('ol#controls').width(wControls);
		    
		    $('ol#controls li').click(function() {
		    	wLi = $('ol#controls li').css('width').replace('px', '');
		    	n = parseInt($(this).find('a').text());
		    	n = n - 2;
		    	margin = n * (parseInt(wLi) + 47);
		    	$('ol#controls').animate({
		    	    'margin-left': '-'+margin+'px'
		    	  }, 4000, function() {
		    	    // Animation complete.
		    	  });
		    });
	    }
	    
	    
	    $('.faq h2').click(function() {
	    	$(this).next('.content').slideToggle();
	    });
	 
	    $('.handlerDatosClave').click(function() {
	    	
	    	$('#handlerDatosClave').remove();
	    	var position = $(this).position();
	    	var pdfs = $(this).parent('li').find('.pdfsDatosClave').html();
	    	
	    	if(!$(this).parent('li').find('.pdfsDatosClave').find('a').length) {
	    		pdfs = 'no contiene ningun contenido.';
	    	}
	    	$('body').append('<div id="handlerDatosClave" style="border:1px solid #dcdcdc;font-size:15px;color:black;position:absolute;top:'+(parseInt(position.top)-20)+'px;left:'+parseInt(position.left)+'px;background:#fff;opacity:0.8;filter:alpha(opacity=80);padding:10px;"><a style="padding-left:10px;float:right;" onclick="$(\'#handlerDatosClave\').remove();" href="javascript:void(0);">Cerrar</a> <strong>Descargar contenido:</strong> <br><br><br> '+pdfs+'</div>');
	    });
	    
});

