function usun(link,comm){
 var agree=confirm(comm);
 if (agree) document.location=link;
}
$.fn.insertAtCaret = function (myValue) {
        return this.each(function(){
                //IE support
                if (document.selection) {
                        this.focus();
                        sel = document.selection.createRange();
                        sel.text = myValue;
                        this.focus();
                }
                //MOZILLA/NETSCAPE support
                else if (this.selectionStart || this.selectionStart == '0') {
                        var startPos = this.selectionStart;
                        var endPos = this.selectionEnd;
                        var scrollTop = this.scrollTop;
                        this.value = this.value.substring(0, startPos)
                                      + myValue
                              + this.value.substring(endPos,
this.value.length);
                        this.focus();
                        this.selectionStart = startPos + myValue.length;
                        this.selectionEnd = startPos + myValue.length;
                        this.scrollTop = scrollTop;
                } else {
                        this.value += myValue;
                        this.focus();
                }
        });

};
	function przewin(){
		var chat = document.getElementById('chat_data');
		chat.scrollTop = chat.scrollHeight;
	}
// JavaScript Document
$(document).ready(function(){
   $(".top_logotyp,.top_logowanie,#polls-container").pngFix();
	$(".mini_match tr, .league_table tr").hover(
		function () {
			$(this).children("td").each(function(i){
				$(this).addClass("tr_hover");
				$(this).children("a").eq(0).addClass("tr_hover");
			});
		},
		function () {
			$(this).children("td").each(function(i){
				$(this).children("a").eq(0).removeClass("tr_hover");
				$(this).removeClass("tr_hover");
			});
		}
	);
	$(".mini_match tr").click(function(){
		var relocate = $(this).children().eq(0).children().eq(0).attr('href');
		if ( relocate != undefined ) window.location.href = relocate;
	});
	$(".league_table tr").click(function(){
		var relocate = $(this).children().eq(1).children().eq(0).attr('href');
		if ( relocate != undefined ) window.location.href = relocate;
	});
	$(".poll-submit").click(function(){
		$(this).parent().parent().submit();
		return false;
	});
	$("#league-select,#season-select").change(function(){
		$(this).parent().parent().submit();
	})
	
	$(".answer").tooltip({
		bodyHandler: function() {
			return $(this).children().eq(0).html();
		},
		track: true,
		top: -40
	});
	
	$("a.lb").fancybox({
		overlayOpacity: 0.7,
		centerOnScroll: false
	});
	
	var linkLiga = $(".match_shedule a").eq(0).attr("href");
	if ( linkLiga != "" && linkLiga != undefined && linkLiga != null ) $(linkLiga).show();
	
	$(".match_shedule a").eq(0).addClass("akt_zakladka");
	
	$(".match_shedule a").click(function(){
		$(".match_shedule a").removeClass("akt_zakladka");
		$(this).addClass("akt_zakladka");
		$(".shedule_container table").hide();
		$($(this).attr('href')).show();
		return false;
	});
	
	$("#emots_container .add_emot").click(function(){
		$("#emots_container .emot_list").toggle('slide');
	});
	$(".emoticon").click(function(){
		$(".comment_form textarea").insertAtCaret($(this).attr('title'));
		return false;
	});
	
	$(".emoticon").hover(
		function(){ $("#emots_preview").html($(this).html()); },
		function(){ $("#emots_preview").html(""); }
	);
	
	$(".bb-ukryj").click(function(){
		$(this).next('div').slideToggle('slow');
	});
	
	$(".gwiazdor_guzik").click(function(){
		$(this).next('div').slideToggle('slow');
	});
	
	$(".kto_glos1,.kto_glos2").click(function(){
		$.post(
			"match_vote.php",
			{ values: $(this).attr('id') },
			function(data) { alert(data); location.reload(); }
		);
		return false;
	});
	
	$(".motm_vote").click(function(){
		$.post(
			"motm_vote.php",
			{ values: $(this).attr('id') },
			function(data) { alert(data); location.reload(); }
		);
		return false;
	});
	
	$(".add_gtv,.add_shout").click(function(){
		$.post(
			"match_tv.php",
			{ values: $(this).attr('id') },
			function(data) { alert(data); }
		);
	});
	$(".remove_tv").click(function(){
		$.post(
			"match_tv.php",
			{ values: $(this).attr('id') },
			function(data) { alert(data); location.reload(); }
		);
	});
	$('#chat_data').load('irc/irc.html?randval='+ Math.random());

	setTimeout('przewin()',1000);

	var refreshId = setInterval(function()
	{
		$('#chat_data').load('irc/irc.html?randval='+ Math.random());
		var chat2 = document.getElementById('chat_data');
		chat2.scrollTop = chat2.scrollHeight;
	}, 30000);
});
