$(function() {	
	$(".external").attr('target', '_blank');
	
	
	
	var tmp = {
		komentars: ''
	}
	
	$('#lietotajvards').focus(function() {
		foo = inittmp.licence;		
		if ($('#users').hasClass('active')) foo = inittmp.lietotajvards;				
		if ($(this).attr('value') == foo) {			
			$(this).attr('value', '');
		}
	});				
	$('#lietotajvards').blur(function() {
		if ($(this).attr('value') === undefined) {
			foo = inittmp.licence;
			if ($('#users').hasClass('active')) foo = inittmp.lietotajvards;
			$(this).attr('value', foo);
		}
	});

	
	$('#parole-c, #parole-u').focus(function() {
		if ($(this).attr('value') == inittmp.parole)
			$(this).attr('value', '');
	});
	
	$('#parole-c, #parole-u').blur(function() {
		if ($(this).attr('value') === undefined) {
			$(this).attr('value', inittmp.parole);
		}
	});
	
	$('#komentars').focus(function() {
		tmp.komentars = $(this).attr('value');
		$(this).html('');
	});				
	$('#komentars').blur(function() {
		if ($(this).html() == '') {
			$(this).html(tmp.komentars);
		}
	});
			
	$('#sidebar li').hover(function(){
		if (!$(this).hasClass('active')) {
			$(this).addClass('hover');
		}		
		if ($(this).find('ul').length != 0) {					
			$(this).addClass('hassub');			
		}
	}, function() {
			$(this).removeClass('hover');
			$(this).removeClass('hassub');
	});

	$('#sidebar ul > li:first-child').addClass('first');
	
	$('#sidebar .active > a:first-child').hover(function(){
		$(this).next().addClass('show');
	}, function() {
		$(this).next().removeClass('show');
	});

	$('#sidebar .active > a:first-child').next().hover(function(){
		$(this).addClass('show');
		if($(this).hasClass('sub')) {
			$(this).prev().addClass('hover');
		}
	}, function() {
		$(this).removeClass('show');
		$(this).prev().removeClass('hover');
	});

	
	if($('#sidebar .active .active ul:not(.sub)').length == 0) {
		$('#sidebar .active').addClass('nosub');
	}
	
	
	$('.tabmenu a').click(function() {
		$('.tabmenu li').removeClass('active');
		$(this).parent().addClass('active');
		$('.startmenucontent').hide();					
		$('.startmenucontent:eq('+$(this).parent().attr('id').replace(/tab-/,'')+')').show();
		return false;	
	});
	
	$('.startmenucontent').hide();
	$('.tabmenu li').removeClass('active');
	
	$('#upload-file-label').bind("click", function() {
      $('#upload-file').click();
    });
	
	$('#myCheckbox0').bind("click", function() {
	  if (!$('.enewsmenu').attr('checked')) {	  	
	  	$('.enewsmenu:enabled').attr('checked', 'checked');
	  }
	  else {
	  	$('.enewsmenu').attr('checked', '');
	  }
    });
});
