$(document).ready(function() {

//functions
//hide all empty channels by default	
jQuery.fn.oz_hide_all = function() {
	$('.empty').hide();	
	
	};
	
jQuery.fn.oz_sort_all = function() {	
	$("div[id^='cb-']").each(function(){
		cb = $(this);
		sid = $(cb).attr('id');
		
		anid = $('#c-' + sid);
		
		if (anid.hasClass('user_in')) {
			if ($(cb).is('.tree_plus_end')) {
				$(cb).removeClass("tree_plus").addClass('tree_minus_end');
			} else {
				$(cb).removeClass("tree_plus").addClass('tree_minus');
			}
		
		$(cb).parents().filter('.childbox').each(function() {
			lol = $(this).attr('id').substr(2);
			if ($("#"+lol).is('.tree_plus_end')) {
				$("#"+lol).removeClass("tree_plus").addClass('tree_minus_end');
			} else {
				$("#"+lol).addClass('tree_minus');
			}
		});
		}
	});
	
	
	$('.user_in').parents().filter('.childbox').show();
};

jQuery.fn.oz_sort_allopen = function() {	
	$("div[id^='cb-']").each(function(){
		cb = $(this);
		sid = $(cb).attr('id');
		
		anid = $('#c-' + sid);
		
			if ($(cb).is('.tree_plus_end')) {
				$(cb).removeClass("tree_plus").addClass('tree_minus_end');
			} else {
				$(cb).removeClass("tree_plus").addClass('tree_minus');
			}
		
		$(cb).parents().filter('.childbox').each(function() {
			lol = $(this).attr('id').substr(2);
			if ($("#"+lol).is('.tree_plus_end')) {
				$("#"+lol).removeClass("tree_plus").addClass('tree_minus_end');
			} else {
				$("#"+lol).addClass('tree_minus');
			}
		});
	});
	
	
	$('.user_in').parents().filter('.childbox').show();
};
	
	// show/hide channelblocks
jQuery.fn.oz_sh_chanblocks = function() {
$("div[id^='cb-']").click(function(e) {
		 var value;
		 value = $(this);
		 id = value.attr('id');
		 inner = $('#c-' + id);
		 if (inner.is(':visible')) {
			 if ($(this).is('.tree_minus_end')) {
				 inner.slideUp("fast");
				 value.removeClass("tree_minus_end").addClass('tree_plus_end');
				 $('.mumbleviewer').oz_fxscroll();
				 } else {
					 inner.slideUp("fast");
					 value.removeClass("tree_minus").addClass('tree_plus');
					 $('.mumbleviewer').oz_fxscroll();
					 }
			 } else {
				 if ($(this).is('.tree_plus_end')) {
					 inner.slideDown("fast");
					 value.removeClass('tree_plus_end').addClass('tree_minus_end');
					 $('.mumbleviewer').oz_fxscroll()
					 } else {
						 inner.slideDown("fast");
						 value.removeClass('tree_plus').addClass('tree_minus');
						 $('.mumbleviewer').oz_fxscroll()
						 }
				 }
		 
		 e.preventDefault();

	 });
};	
	//username tooltips
jQuery.fn.oz_usertooltips = function() {	
	$('a.load-ustats').cluetip({
		local:true,
		cursor: 'pointer',
		tracking:true,
		width: 180,
	    hoverIntent:
	    {
        	sensitivity:  1,
        	interval:     50,
        	timeout:      0
        },
        positionBy: 'mouse',
        fx: {
        	open:	'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
        	openSpeed:  'normal'
        	}

		});
	$('a.load-mv_footbox').cluetip({
		local:true,
		cursor: 'pointer',
		tracking:true,
		width: 180,
	    hoverIntent:
	    {
        	sensitivity:  1,
        	interval:     50,
        	timeout:      0
        },
        positionBy: 'mouse',
        fx: {
        	open:	'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
        	openSpeed:  'normal'
        	}

		});
};
jQuery.fn.oz_panel = function() {
	//show all by click
	$('.open_all').click(function(e) {
		$('.childbox').show();
		$('.tree_plus').removeClass("tree_plus").addClass('tree_minus');
		$('.tree_plus_end').removeClass("tree_plus_end").addClass('tree_minus_end');
	});
	//refresh by click
	$('.refresh').click(function(e) {
		$().oz_refresh();
	});
	
	
		//  $('a[rel*=facebox]').facebox()
	
	
};

jQuery.fn.oz_fxscroll = function() {	
	if (jQuery.url.param("simpleheight")) {
		if (jQuery.url.param("fxscroll")) {
			$('.mumbleviewer').jScrollPane();
		};
	};
	};

jQuery.fn.oz_refresh = function() {		
	$(".mumbleviewer").ajaxStart(function () {
		$(this).addClass('mv_loading');
		}); 
	
	$.ajax({
		   type: "GET",
		   url: jQuery.url.attr("source").replace(jQuery.url.param("height"), '') + '&blank',
		   //url: "http://devel.mumble-tower.de/svntest/trunk/nv.php?&serverid=1&blank",
		   dataType: "html",
		cache:false,
		start: function(){
		$('.mumbleviewer').replaceWith(html);
		},


		success: function(html){
		    $('.mumbleviewer').replaceWith(html);
			$('.mumbleviewer').oz_hide_all();
			$('.mumbleviewer').oz_sort_all();
			$('.mumbleviewer').oz_usertooltips();
			$('.mumbleviewer').oz_sh_chanblocks();
			$('.mumbleviewer').oz_panel();
			$('.mumbleviewer').oz_fxscroll()
		  }

		 });


};

//init
if ($.url.param("dontcloseempty")==1) {
    $('.mumbleviewer').oz_sort_allopen();
}
else {
    $('.mumbleviewer').oz_hide_all();
    $('.mumbleviewer').oz_sort_all();
}

$('.mumbleviewer').oz_sh_chanblocks(); 
$('.mumbleviewer').oz_usertooltips();
$('.mumbleviewer').oz_panel();
$('.mumbleviewer').oz_fxscroll()



if ($.url.param("refresh")!=null) {
var refreshId = setInterval(function() {
	$().oz_refresh();
}, $.url.param('refresh'));
};

//end
 });


