$(document).ready(function(){
	//skrytie gangbaru ak ho nastavil ako skryty a zobrazenie cervenych obdlznikov ak tam nie je nula
	if($.cookie('gangbar')=='2') {
		$('#gangbar, #feedback, #formular').hide(); 
		$('#showbar').css('display', 'block');
	}
	if($('#nucet').html()!='0') { $('#nucet').show(); }
	if($('#nvrazdy').html()!='0') { $('#nvrazdy').show(); }
	if($('#nmisie').html()!='0') { $('#nmisie').show(); }
	if($('#nforum').html()!='0') { $('#nforum').show(); }
	if($('#ntehlicky').html()!='0') { $('#ntehlicky').show(); }
	if($('#nrodina').html()!='0') { $('#nrodina').show(); }
	
	//animacia cisel v cerv. obdlzniku
	GbNumber();
	
	//ikonky
	$('.gbikonky')
	.mouseover(function(){ $(this).css('backgroundImage', 'url(images/gangbar/units/gbunits_h.gif)'); })
	.mouseout(function(){ $(this).css('backgroundImage', 'url(images/gangbar/units/gbunits.gif)'); })
	.click(function(event) { 
		var ide = this.id;
		if($('#n'+ide).is(':visible')) {
			$.get("ajaxfiles/gangbar.php", { id: ide, action: 1 }, function(data) {
				$('#n'+ide).hide();
			});
		}
			$('.gbwindow').fadeOut(200);
			$('#w'+this.id).fadeIn(200);
			event.preventDefault(); 
	});
	$('.gbcross')
	.mouseover(function(){ $(this).css('backgroundPosition', '-303px -24px'); })
	.mouseout(function(){ $(this).css('backgroundPosition', '-303px 0px'); })
	.click(function(event) { 
			$('#w'+$(this).attr('id').substr(1)).fadeOut();
			event.preventDefault(); 
	});
	
	$('#nastavenia')
	.mouseover(function(){ $(this).css('backgroundImage', 'url(images/gangbar/units/gbunits_h.gif)');  })
	.mouseout(function(){ $(this).css('backgroundImage', 'url(images/gangbar/units/gbunits.gif)');  });
	
	// ziskanie dalsich prispevkov v okne
	$('.gbnext').click(function(event) {
		var group = $(this).attr('id').substr(1);
		$('#d'+group).hide(); $('#l'+group).show();
		$.get("ajaxfiles/gangbar.php", { group: group, action: 2, done: $('#g'+group+' .udalosti').length }, function(data) {
			$('#l'+group).fadeOut(function() {
				$('#d'+group).before(data);
				if($('#nomore'+group).length<1) { $('#d'+group).show(); }
			});
		});
		event.preventDefault(); 
	});
		
	// zobrazenie konkretnej udalosti
	$('.udalosti').live('click', function(event) {
		var id = $(this).attr('id').substr(1);
		if($('#info'+id).length && $('#info'+id).is(':visible')) { 
			$('#info'+id).hide(200, 'linear');
		}
		else if($('#info'+id).is(':hidden')) { 
			$('#info'+id).show(200, 'linear');
		}
		else {
			$('#w'+id).after('<div id="info'+id+'" class="udalostdetail"><p class="center" id="loaderr'+id+'"><img src="images/gangbar/load.gif" alt="Načítavam" /></p></div>');
			$.get("ajaxfiles/gangbar.php", { id: id, action: 3 }, function(data) {
				$('#loaderr'+id).fadeOut(200, function() {
					$('#info'+id).html(data);
				});
			});
		}
		event.preventDefault(); 
	});
	
	function GbNumber() {
		if ($('.gbnumber').is(':visible')) { 
			$('.gbnumber').animate({ color: 'white' }, 500, 'linear', function() { $('.gbnumber').animate({ color: 'black' }, 500, 'linear', GbNumber()); });
		}
	}
});
