jQuery(document).ready(function(){

	jQuery("#tree").treeview();
	
	
	var timer;
	
	jQuery("#treetrigger").hover(
							function(){
								jQuery("#tree").fadeIn();
							},
							function(){
								if(timer) {
									clearTimeout(timer);
									timer = null;
								}
								timer = setTimeout(function() {
										jQuery("#tree").fadeOut();
								}, 500);
							});
	
	jQuery("#tree").hover(
							function(){
							clearTimeout(timer);
							timer = null;
							},
							function(){
							jQuery("#tree").fadeOut();
							});
	
	// CSS TRICKS - dynamic page load / AJAX
	
	// navigacija
	jQuery("body").delegate(".linker","click",function(){
		window.location.hash = jQuery(this).attr("href").substring(4);
		return false;
		});
	
	// postavljanje sadržaja u elemente
	jQuery(window).bind("hashchange",function(){
		
		var newHash = "do=" + window.location.hash.substring(1) + '&ajax=true';

		var ret = jQuery.ajax({
		  type: 'GET',
		  url: 'x.php',
		  data: newHash,
		  contentType: 'application/json; charset=utf-8',
		  async: false,
		  processData: false,
		  cache: false,
		  dataType: 'json'
		 });
		
		obj = eval('('+ret.responseText+')');
		
		jQuery.each(obj,function(id,val){
			
			jQuery("#" + id).fadeOut(100,function(){
				jQuery("#" + id).html(val);
			});
			
			jQuery("#" + id).fadeIn(1000);
		
		});
			
	});


	jQuery(".rbutton").hover(
							function(){
							jQuery(this).attr("src",jQuery(this).attr("src").replace("_.png","_hover.png"));	
							},
							function(){
							jQuery(this).attr("src",jQuery(this).attr("src").replace("_hover.png","_.png"));
							});
});
