	function print_r(arr, level)
	{
		var print_red_text = "";
	    if(!level) level = 0;
	    var level_padding = "";
	    for(var j=0; j<level+1; j++) level_padding += "    ";
	    if(typeof(arr) == 'object')
	    {
	        for(var item in arr) {
	            var value = arr[item];
	            if(typeof(value) == 'object') {
	                print_red_text += level_padding + "'" + item + "' :\n";
	                print_red_text += print_r(value,level+1);
				}
	            else print_red_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
	        }
	    }
	    else  print_red_text = "===>"+arr+"<===("+typeof(arr)+")";
	    return print_red_text;
	}

	function loadVideo(video_id, wsdl_url, directory_id)
	{
        $("#player").hide();
        $("#localPlayer").hide();
		$.get(wsdl_url, { action: "videoload", id: video_id, directory_id: directory_id }, 
			function on_VideoXMLPosted(data)
		    {
		        var resultXML = data;
		        var output = '';
		        
		        directory = resultXML.getElementsByTagName('directory');
		        if ((directory[0] != undefined) && (typeof(directory[0]) == "object"))
		        {
		        	directoryId = directory[0].getAttribute('id');
		        	directoryTitle = directory[0].getAttribute('title');
		        }
		        else
		        {
		        	directoryId = 0;
		        	directoryTitle = '';
		        }
		        
		        video = resultXML.getElementsByTagName('video');
		        if ((video[0] != undefined) && (typeof(video[0]) == "object"))
		        {
		        	video_type = video[0].getAttribute('type');   	
			    	video_id = video[0].getAttribute('id');
			    	video_title = video[0].getAttribute('title');
			    	video_output = video[0].getAttribute('videoHTML');
			    	video_preview = video[0].getAttribute('videoPreview');
			        video_thumbnailURL = video[0].getAttribute('thumbnailURL');			        
			        video_description = video[0].getAttribute('description');
			        video_duration = video[0].getAttribute('duration');
			        
			        if(video_type == 'LOCAL')
			        {
			        	var videoName = video_output;
			        	$("#localPlayer").show();
						$f("localPlayer", 
							{
								src: '/flash/flowplayer-3.1.1.swf',
								wmode: 'transparent'}, 
							{ 							
								clip: { 
									url: videoName, 
									autoPlay: false, 
									autoBuffering: true 
								},
							}
						);
			        }
			        else if(video_type == 'LINK')
			        {
			        	var videoName = video_output;
			        	$("#localPlayer").show();
						$f("localPlayer", 
							{
								src: '/flash/flowplayer-3.1.1.swf',
								wmode: 'transparent'}, 
							{ 							
								clip: { 
									url: videoName, 
									autoPlay: false, 
									autoBuffering: true 
								},
							}
						);
			        }	        
			        else
			        {
			        	$("#player").empty();
			        	$("#player").show();
			        	$("#player").html(video_output);
			        	
			        }
			        init(video_type);
			        
			    	if(video_preview) $("#preview").show();
			    	else $("#preview").hide();
			        $("#videoTitle").html(video_title);
			        $("#tooltip").html(video_description);
			        $('#videoCategory').html(directoryTitle);
			        $('#videoDuration').html(video_duration);
		        }
	
		        return true;
		    }
		);
	}	
	
	function play(video_type)
	{
		$('#playButton').unbind('click');
        if(video_type == 'LOCAL')
        {
        	$f(0).play();
        }
        else if(video_type == 'LINK')
        {
        	$f(0).play();
        }	        
        else
        {
        	document.getElementById('youtube_video').playVideo();
        }
        $('#playButton').click(function() {pause(video_type);});
        $('#playButton').attr('src', '/images/stop.gif');
	}
	
	function pause(video_type)
	{
		$('#playButton').unbind('click');
        if(video_type == 'LOCAL')
        {
        	$f(0).pause();
        }
        else if(video_type == 'LINK')
        {
        	$f(0).pause();
        }	        
        else
        {
        	document.getElementById('youtube_video').pauseVideo();
        }
        $('#playButton').click(function() {play(video_type);});
        $('#playButton').attr('src', '/images/play.gif');
	}
	
	function stop(video_type)
	{
		$('#playButton').unbind('click');
        if(video_type == 'LOCAL')
        {
        	$f(0).stop();
        }
        else if(video_type == 'LINK')
        {
        	$f(0).stop();
        }	        
        else
        {
        	document.getElementById('youtube_video').stopVideo();
        }
        $('#playButton').click(function() {play(video_type);});
        $('#playButton').attr('src', '/images/play.gif');
	}
	
	function init(video_type)
	{
		$('#playButton').unbind('click');
        if(video_type == 'LOCAL')
        {
        }
        else if(video_type == 'LINK')
        {
        }	        
        else
        {
        }
        $('#playButton').click(function() {play(video_type);});
        $('#playButton').attr('src', '/images/play.gif');
	}	
	
