function getAJAX(element, div_id) {

	if (div_id == null)
		div_id = 'ajaxDIV';

	$.ajax({
		type: "POST",
		url: $(element).attr('href'),
		data: "ajax=true",
		async: false,
		success: function(msg) {
			$('#' + div_id).html(msg);
		}
	});
	return false;	
}
function slideAJAX(element, div_id) {
	$('#' + div_id).slideUp('slow', function() {
		getAJAX(element, div_id);
		$('#' + div_id).slideDown();
	});
	return false;
}

function toggleEditor(id) {
	if (!tinyMCE.getInstanceById(id))
		tinyMCE.execCommand('mceAddControl', false, id);
	else
		tinyMCE.execCommand('mceRemoveControl', false, id);
	return false;
}

function advertisementClick(id) {
	window.open('/advertisement/reload/' + id);
	return false;
}

function mainmenu() {
	$("#menu ul").css({display: "none"}); // Opera Fix
	$("#menu li").hover(
		function() {
			$(this).find('ul:first').css({visibility: "visible", display: "none", width: "130px"}).show(300);
		},
		function() {
			$(this).find('ul:first').css({visibility: "visible",display: "block"}).hide(300);
/*			$(this).find('ul:first').css({visibility: "hidden"});*/
		}
	);
}
$(document).ready(function(){
	mainmenu();
});

function focus_blur(element, text) {
	element.focus(function() {
		if (element.val() == text)
			element.val('');
	});
	element.blur(function() {
		if (element.val() == '')
			element.val(text);
	});
}


function usercontextmenu(id, name) {
	$('.userFriends a').attr('href', '/znajomi/' + id);
	$('.userProfile a').attr('href', '/profil/' + id + '-' + name);
	$('.userPw a').attr('href', '/pw/wyslij/' + id);
	$('.userForumProfile a').attr('href', '/forum/index.php?action=profile;u=' + id);
	$('.userBan a').attr('href', '/forum/index.php?action=ban;sa=add;u=' + id);
	$('.userWarn a').attr('href', '/dodaj-ostrzezenie/' + id);
	return false;
}

$(document).ready(function() {
	$('#nastepny a').click(function() {
		if ($('.panel-mecze-content').eq(0).is(':hidden')) {
			$('#nastepny').addClass('active');
			$('#poprzedni').removeClass('active');
			$('.panel-mecze-content').hide();
			$('.panel-mecze-content').eq(0).show();
		}
		return false;
	});
	$('#poprzedni a').click(function() {
		if ($('.panel-mecze-content').eq(1).is(':hidden')) {
			$('#poprzedni').addClass('active');
			$('#nastepny').removeClass('active');
			$('.panel-mecze-content').hide();
			$('.panel-mecze-content').eq(1).show();
		}
		return false;
	});
	$('#reset').click(function() {
		$('#ShoutboxContent').val('');
		return false;
	});
	$('#CommentReset').click(function() {
		$('#CommentContent').val('');
		return false;
	});
	$('#comment_emoticons_link').click(function() {
		$('#comment_emoticons').slideToggle();
		return false;
	});
	$('#comment_emoticons a').click(function() {
		$('#CommentContent').focus();
		$('#CommentContent').val($('#CommentContent').val() + $(this).children('img').eq(0).attr('alt'));
		return false;
	});
	
	var t;
	$('#przewin .top').hover(function() {
		t = setInterval(function() {$('#shouts').scrollTop($('#shouts').scrollTop() - 1); }, 8);
	}, function() { clearInterval(t) });
	$('#przewin .bottom').hover(function() {
		t = setInterval(function() {$('#shouts').scrollTop($('#shouts').scrollTop() + 1); }, 8);
	}, function() { clearInterval(t) });
	
	$('#shoutbox_emoticons_link').click(function() {
		$('#shoutbox_emoticons').slideToggle();
		return false;
	});
	$('#shoutbox_emoticons a').click(function() {
		$('#ShoutboxContent').val($('#ShoutboxContent').val() + $(this).children('img').eq(0).attr('alt'));
		$('#ShoutboxContent').focus();
		return false;
	});
	
	$('.slide_box a.nav').click(function() {
		index = $(this).parents('.slide_box').find('a.nav').index($(this));
		element = $(this).parents('.slide_box').find('div.prawa');
		if (element.eq(index).is(':hidden')) {
			element.hide();
			element.eq(index).show();
		}
		return false;
	});
	$('div.admin-photo').mousemove(function(e) {
		$(this).find('div').css({'top': e.pageY, 'left': e.pageX});
		$(this).find('div').show();
	});
	$('div.admin-photo').mouseleave(function() {
		$(this).find('div').hide();
	});
	
	focus_blur($('#CommentContent'), 'Nie używaj wulgaryzmów; nie obrażaj kibiców innych drużyn; nie odpowiadaj na ich prowokacje; staraj trzymać się zasad ortografii; nie przesadzaj z wykrzyknikami; nie pisz dużymi literami; nie reklamuj innych serwisów;  nie pisz, że jesteś pierwszy, drugi itp.; w komentarzu nie używaj samych emotikon - w przeciwnym razie ostrzeżenie, a potem BAN!');
	
	focus_blur($('#NewsletterEmail'), 'Wpisz swój email');
	
	$('#flashBox .img').eq(0).show();
	if ($('#flashBox .img').size() > 1) {
		$('#flashBox #flashNextNav').addClass('active');
	}
	
	$('#flashBox #flashNextNav').click(function() {
		index = $('#flashBox .img').index($('#flashBox .img:visible'));
		index = index + 1;
		$('#flashBox .img').fadeOut();
		$('#flashBox .img').eq(index).fadeIn();
		$('#flashBox a').removeClass('active');
		if (index > 0) {
			$('#flashBox #flashPrevNav').addClass('active');
		}
		if (index +1 < $('#flashBox .img').size()) {
			$('#flashBox #flashNextNav').addClass('active');
		}
		
		return false;
	});
	$('#flashBox #flashPrevNav').click(function() {
		index = $('#flashBox .img').index($('#flashBox .img:visible'));
		index = index - 1;
		$('#flashBox .img').fadeOut();
		$('#flashBox .img').eq(index).fadeIn();
		$('#flashBox a').removeClass('active');
		if (index > 0) {
			$('#flashBox #flashPrevNav').addClass('active');
		}
		if (index +1 < $('#flashBox .img').size()) {
			$('#flashBox #flashNextNav').addClass('active');
		}
		return false;
	});
	$('#transfery-select').change(function() {
		selected = $("#transfery-select option:selected");
		index = selected.val() - 1;
		$('#transfery-div .transfery').hide();
		$('#transfery-div .transfery').eq(index).show();
		return false;
	});
	
	$('#menu-1>li').hover(function() {
		index = $('#menu-1>li').index($(this)) / 2;
		$('.menu-2').hide();
		$('.menu-2.menu_' + index).show();
	
	}, function() {
	});
	$('p.comment-edit a').click(function() {
		textar = $('<textarea>');
		text = $(this).parents('.commentbox').find('p.comment-text').html();
		href = $(this).attr('href');
		subm = '<form action="' + href + '" method="post"><textarea name="Comment[content]">' + text + '</textarea><input type="image" src="/img/wyslij-btn.png" /></form>';
		
		$(this).parents('.commentbox').find('p.comment-text').html(subm);
	
		return false;
	});
	
});
  
  

