<?
	//$x = get_data('select guid, Naziv from library order by Naziv', 1);
?>

	<script type="text/javascript" src="http://www.google.com/jsapi"></script>
	<script type="text/javascript">
		google.load('visualization', '1', {packages: ['orgchart']});
	</script>
	<script type="text/javascript">
		var viz;
		
		var a_data = new Array();
<?
		$l_cnt = 0;
		//for($i = 0; $i < sizeof($x['guid']); $i++){
		for($i = 0; $i < 1; $i++){
			$y = get_data('select B.guid, B.FolderName as Naziv, B.parent_guid
				from folder A RIGHT outer join folder B On A.guid = B.parent_guid
				order by A.FolderName, B.FolderName ', 1);
				
			for($j = 0; $j < sizeof($y['guid']); $j++){
?>
				a_data[<?=$l_cnt++?>] = new Array({v:'<?=$y['guid'][$j]?>', f:'<?=$y['Naziv'][$j]?>'}, '<?=$y['parent_guid'][$j]?>', '<?=$y['Naziv'][$j]?>');
<?
			}
		}
?>
		
		function drawVisualization(a_data_a){
			var data = new google.visualization.DataTable();
			data.addColumn('string', 'Name');
			data.addColumn('string', 'Manager');
			data.addColumn('string', 'ToolTip');
			data.addRows(a_data_a);
			
			// Create and draw the visualization.
			viz = new google.visualization.OrgChart(document.getElementById('visualization'));
			viz.draw(data, {allowHtml: true,nodeClass:'nodeStyle',selectedNodeClass:'sNodeStyle',size:'medium'});
		
			google.visualization.events.addListener(viz, 'select', function() {
				// grab a few details before redirecting
				var selection = viz.getSelection();
				if(selection == ''){
					close_layers();
					var la_query = document.location.href.split('#');
					document.location = la_query[0] + '#';
				}else{
					var row1 = selection[0].row;
					var la_query = document.location.href.split('#');
					document.location = la_query[0] + '#3/1/' + data.getValue(row1, 0);
					
					a_is_redak_set[0] = 0;
					
					//display_layer(data.getValue(row1, 0), '', 0, 0);
				}
			});
		}
		
		function close_layers(){
			document.getElementById('visBottomFolder').style.display = 'none';
			document.getElementById('mapSpan').innerHTML = '';
			document.getElementById('menuButtons').innerHTML = '';
			document.getElementById('menuAction').innerHTML = '';
			
			drawVisualization(a_data);
		}
		
		function display_layer(value, layer, column, reverse){
			//makerequest('<?=$g_path_sl?>res/aj/document_get.php?value=' + value + '&aj=' + layer + '&column=' + column + '&reverse=' + reverse, 'visBottomFolder');
			makerequest_4('<?=$g_path_sl?>res/aj/document_get.php?value=' + value + '&aj=' + layer + '&column=' + column + '&reverse=' + reverse, 'visBottomFolder', 'mapSpan', 'menuAction', 'menuButtons');
			
			document.getElementById('visBottomFolder').style.display = 'block';
			for(i = 0; i < a_data.length; i++){
				if(a_data[i][0]['v'] == value){
					viz.setSelection([{'row': i}]);
					break;
				}
			}
			
			//redak = 0;
			//is_redak_set = 0;
		}
		
		google.setOnLoadCallback(function(){
			drawVisualization(a_data);
		});
		
	</script>
