if(typeof jkoplayer == "undefined") {
	jkoplayer = {};
}

jkoplayer.change_subtitles = function(){
	//esto es un event handler, aqui this es el control que recibe el evento
	if(this.value && this.value!="0"){
		$f().getPlugin("content").css({display: 'block'});
		$f().getPlugin("captions").loadCaptions(0,'/player/captions/'+this.value);
	}
	else if(this.value=="0"){
		$f().getPlugin("content").css({display: 'none'});
		$f().getPlugin("captions").loadCaptions(0,'/player/captions/default.xml');

	}
}		
	
jkoplayer.createVideoPlayer=function(container_id, path_to_video_file, caption_selector_id, title){
	//si va a haber subtítulos reseteamos select y registramos handler
	if(caption_selector_id){
		var caption_selector=$("#" + caption_selector_id);
		caption_selector.val("0");
		caption_selector.change(jkoplayer.change_subtitles);
	}
	var server = 'http://www.jkrishnamurti.org/videos/';

	$f(container_id, "/player/flowplayer.commercial-3.2.4.swf", {
		key: location.host.indexOf(".com") != -1 ? '$fac20afd1927e384866' : '$9530cacfde6f07b6baf',

		clip: {
			url: server + path_to_video_file,
			provider: 'lighttpd',
			autoplay: true
		},
		logo: {
			url: '/images/logo_video.png',
			fullscreenOnly: false,
			linkUrl : 'http://www.jkrishnamurti.org'
		},
		plugins: { 
	    	lighttpd: {  
    	    	url: 'http://www.jkrishnamurti.org/player/flowplayer.pseudostreaming-3.2.4.swf'  
	    	},

        	captions: { 
         		url: 'http://www.jkrishnamurti.org/player/flowplayer.captions-3.2.0.swf', 
            	captionTarget: 'content',
            	button: (caption_selector_id ? { width: 20, height: 15, right: 5, bottom: 30, label: 'CC' } : null)
 			},

        	controls: {
 				url: 'http://www.jkrishnamurti.org/player/flowplayer.controls-3.2.2.swf',
        		progressColor:  '#bec600',
        		bufferColor: '#737900',
        		buttonColor: '#737900',
        		buttonOverColor: '#ccd239',
        		timeColor: '#bec600',
        		backgroundColor: '#333300',
        		backgroundGradient: 'none',
        		height:30,
        		tooltipColor: '#333300',
        		tooltipTextColor: 'c8cf27'
       		}, 	
       		content: { 
       			url:'http://www.jkrishnamurti.org/player/flowplayer.content-3.2.0.swf', 
            	bottom: 30, 
            	width: '100%', 
            	height:50, 
            	backgroundColor: 'transparent', 
            	backgroundGradient: 'none', 
            	borderRadius: 0, 
           		border: 0,
           		display: 'none',
           		textDecoration: 'outline',
 				style: { 
              		'body': { 
                		fontSize: '18', 
                		fontFamily: 'Arial',
                		fontWeight: 'normal', 
                		textAlign: 'center', 
                		color: '#EFF12D' 
                	} 
            	}
            }       			 	
   		 } 
		
	});

}
