﻿// Praca z Prototype
jQuery.noConflict();
var $j = jQuery;

// Obsługa sidebara
$j().ready(function() {
	$j('#main #sidebar h3').each(function(i) {
		if ($j.cookie($j(this).attr('id')) == 'off') {
			$j(this).parent().find('ul').hide();
			$j(this).attr('class', 'off');
		} else 
			$j(this).attr('class', 'on');
		}).bind('click', function() {
		if ($j(this).attr('class') == 'on') {
			$j(this).parent().find('ul').slideUp('fast');
			$j(this).attr('class', 'off');
			$j.cookie($j(this).attr('id'), 'off', {expires: 14, path: '/'});
		} else {
			$j(this).parent().find('ul').slideDown('fast');
			$j(this).attr('class', 'on');
			$j.cookie($j(this).attr('id'), 'on', {expires: 14, path: '/'});
		}
	});			
});	

// Pokaż/Ukryj tagi
 $j(document).ready(function() {
   $j('span.tags').hide();
   $j('a.toggle-tags').click(function(){
     $j('span.tags').toggle();
   });
 });


// Opcje komentarzy
// Poniższy kod jest własnością Riddle'a (http://riddle.jogger.pl), lekko zmodyfikowany na potrzeby killbox'a

function returnNick(obj) {

	var n;

	var h = obj.parentNode.parentNode.getElementsByTagName("strong")[0];

	if (h.firstChild.nodeName == "A") n = h.firstChild.firstChild.nodeValue;

	else n = h.firstChild.nodeValue;

	return n;
}



function replyComm(obj) {

	if (!$('comment-form')) { return false; }

	var nick = returnNick(obj);

	var text = $('comment-body');

	if (text.value.length == 0) text.value = nick + ': ';

	else if (text.value.match(/\n$/)) text.value += '\n' + nick + ': ';

	else text.value += '\n\n' + nick + ': ';

	text.focus();	

	return false;

}



function quoteComm(obj) {
	
	if (!$('comment-form')) { return false; }

	var txt = "";

	if (window.getSelection) {
		txt = window.getSelection();
	}

	else if (document.getSelection) {
		txt = document.getSelection();
	}

	else if (document.selection) {
		txt = document.selection.createRange().text;
	}

	if (txt == "") return false;

	var nick = returnNick(obj);
	
	txt = '[' + nick + ']: ' + '\u201E' + txt + '\u201D\n\n';

	var text = $('comment-body');

	if (text.value.length == 0) text.value = txt;
	
	else if (text.value.match(/\n$/)) text.value += '\n' + txt;

	else text.value += '\n\n' + txt;

	return false;

}
