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.ini_subtitles = function (path_subtitles){
        $f().getPlugin("content").css({display: 'block'});
        $f().getPlugin("captions").loadCaptions(0,'/player/captions/'+path_subtitles);
}	

	
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.6-dev2.swf", {
		key: location.host.indexOf(".com") != -1 ? '$fac20afd1927e384866' : '$9530cacfde6f07b6baf',
			clip: {
			url: server + path_to_video_file,
			provider: 'lighttpd',
			autoplay: true,
			autoBuffering: true,
			scaling: 'fit'
		},
		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.6-dev.swf'  
	    	},

        	captions: { 
         		url: 'flowplayer.captions-3.2.3-dev.swf', 
            	captionTarget: 'content',
            	button: (caption_selector_id ? { width: 20, height: 15, right: 5, bottom: 30, label: 'CC' } : null)
 			},
            viral:	  {
            	url: 'flowplayer.viralvideos-3.2.3.swf',
            	share: { 
            		description: 'J. Krishnamurti Online' 
            	},
            	email :{
            		script: '/private/bin/process-email-video.php'
            	}
			},
        	controls: {
 				url: 'flowplayer.controls-3.2.4-dev.swf',
        		progressColor:  '#bec600',
        		bufferColor: '#737900',
        		buttonColor: '#737900',
        		buttonOverColor: '#ccd239',
        		timeColor: '#bec600',
        		backgroundColor: '#333300',
        		backgroundGradient: 'none',
        		height:30,
        		tooltipColor: '#333300',
        		tooltipTextColor: 'c8cf27',
        		autoHide: {
    				fullsccreenOnly: false,
   				 	hideDelay: 2000
				}


       		}, 	
       		content: { 
       			url:'flowplayer.content-3.2.0.swf', 
            	bottom: 30, 
            	width: '100%', 
            	height:60, 
            	backgroundColor: '#000', 
            	backgroundGradient: 'none', 
            	borderRadius: 0, 
           		border: 0,
           		display: 'none',
           		textDecoration: 'outline',
 				style: { 
              		'body': { 
                		fontSize: '18', 
                		fontFamily: 'Arial',
                		fontWeight: 'normal', 
                		textAlign: 'center', 
                		color: '#E17E10' 
                	} 
            	}
            }       			 	
   		 } 
		
	});

}

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

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

		clip: {
			url: server + path_to_video_file,
			provider: 'lighttpd',
			autoplay: true,
			autoBuffering: true,
			scaling: 'fit'
		},
		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.6-dev.swf'  
	    		},

        		captions: { 
         			url: 'flowplayer.captions-3.2.3-dev.swf', 
            			captionTarget: 'content',
            			button: (caption_selector_id ? { width: 20, height: 15, right: 5, bottom: 30, label: 'CC' } : null)
 			},
            		viral:	  {
            			url: 'flowplayer.viralvideos-3.2.3.swf',
            			share: { 
            				description: 'J. Krishnamurti Online' 
            			},
            			email :{
            				script: '/private/bin/process-email-video.php'
            			}
			},
        		controls: {
 				url: 'flowplayer.controls-3.2.4-dev.swf',
        			progressColor:  '#bec600',
        			bufferColor: '#737900',
        			buttonColor: '#737900',
        			buttonOverColor: '#ccd239',
        			timeColor: '#bec600',
        			backgroundColor: '#333300',
        			backgroundGradient: 'none',
        			height:30,
        			tooltipColor: '#333300',
        			tooltipTextColor: 'c8cf27',
        			autoHide: {
    					fullsccreenOnly: false,
   				 	hideDelay: 2000
				}


       			}, 	
       			content: { 
       				url:'flowplayer.content-3.2.0.swf', 
            			bottom: 30, 
            			width: '100%', 
            			height:60, 
            			backgroundColor: '#000', 
            			backgroundGradient: 'none', 
            			borderRadius: 0, 
           			border: 0,
           			display: 'none',
           			textDecoration: 'outline',
 				style: { 
              				'body': { 
                				fontSize: '18', 
                				fontFamily: 'Arial',
                				fontWeight: 'normal', 
                				textAlign: 'center', 
                				color: '#E17E10' 
                			} 
            			}
            		}
   		 }, 
		onLoad: function() {
			if (subtitles != ''){
        			$f().getPlugin("content").css({display: 'block'});
        			$f().getPlugin("captions").loadCaptions(0,'/player/captions'+subtitles);
			}
		}
	});

}


