function toggleText(boxClass,boxId) {
	box = document.getElementById(boxClass+boxId);
	var boxes = box.parentNode.getElementsByTagName('div');
	for (var i=0; i<boxes.length; i++) {
		if (boxes[i].className == boxClass) {
			boxes[i].className += ' none';
		}
	}
	box.className=box.className.replace(new RegExp(' none\\b'), '');
}

$(document).ready(function() {
	
	$('table tr:odd').addClass('tr2');
	
	//grupowanie alfabetyczne
	$('#groupAZ').show();
	$('#groupAZ .groups div:not(:first)').hide();
	$('#groupAZ').insertBefore($('div.blog'));
	$('.groupblog .article_row').each(function() {
		var letter = $(this).find('.article_column h2').text().substring(0, 1).toUpperCase();
		if (letter == 'Ć') letter = 'C00';
		if (letter == 'Ł') letter = 'L00';
		if (letter == 'Ó') letter = 'O00';
		if (letter == 'Ś') letter = 'S00';
		if (letter == 'Ź') letter = 'X00';
		if (letter == 'Ż') letter = 'Z00';
		$(this).appendTo($('#groupAZ .groups').find('div.'+letter));
	});
	$('#groupAZ ul.letters a').each(function() {
		if ($(this).text() == 'Ć') $(this).addClass('C00'); else
		if ($(this).text() == 'Ł') $(this).addClass('L00'); else
		if ($(this).text() == 'Ó') $(this).addClass('O00'); else
		if ($(this).text() == 'Ś') $(this).addClass('S00'); else
		if ($(this).text() == 'Ź') $(this).addClass('X00'); else
		if ($(this).text() == 'Ż') $(this).addClass('Z00'); else
		$(this).addClass($(this).text());
	});
	$('#groupAZ ul.letters a:first').addClass('active');
	$('#groupAZ .groups').children().each(function() {
		if ($(this).text() == '') {
			var letter = $(this).attr('class');
			$('#groupAZ ul.letters a.'+letter).hide();
		}
	});
	$('#groupAZ ul.letters a').click(function() {
		var letter = $(this).attr('class');
		$('#groupAZ .groups').children().hide();
		$('#groupAZ .groups div.'+letter).show();
		$('#groupAZ ul.letters a').removeClass('active');
		$(this).addClass('active');
		return false;						  
	});
	
	//przewijanie klientow
	$('.brandsBar div:first').show().addClass('active');
	setInterval(function() {
		$('.brandsBar div.active').fadeOut('slow', function() {
			if ($(this).hasClass('col8')) {
				var n = $(this).parent().find('div:first');
			} else {
				var n = $(this).next();	
			}
			$(n).fadeIn('slow').addClass('active');
		}).removeClass('active');
	}, 3000);
	//$('.brandsBar li a').css('cursor', 'default').attr('href', '#');
	
	//wyszukiwarka
	$('.homepage form.searchForm input.text, #leftCol form.searchForm input.text').focus(function() {
		if ($(this).val() == 'przeszukaj netsprint.eu...') $(this).addClass('textNormal').val('');
		if ($(this).val() == 'search netsprint.eu...') $(this).addClass('textNormalEng').val('');
		if ($(this).val() == 'suche netsprint.eu...') $(this).addClass('textNormalDe').val('');
	}).blur(function() {
		if ($(this).val() == '' && $(this).hasClass('textNormalDe')) $(this).removeClass('textNormalDe').val('suche netsprint.eu...');
		if ($(this).val() == '' && $(this).hasClass('textNormalEng')) $(this).removeClass('textNormalEng').val('search netsprint.eu...');
		if ($(this).val() == '' && $(this).hasClass('textNormal')) $(this).removeClass('textNormal').val('przeszukaj netsprint.eu...');



});
	
	$('body.szukaj #leftCol form.searchForm').hide();
	
	//na skroty
	$('form.boxNaSkroty select').change(function() {
		document.location.href = 'http://'+$(this).val();											 
	});
});

function urlencode (str) {

    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // +      input by: Ratheous
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Joris
    // %          note 1: This reflects PHP 5.3/6.0+ behavior
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'

    var hexStr = function (dec) {
        return '%' + (dec < 16 ? '0' : '') + dec.toString(16).toUpperCase();
    };
    var ret = '',
    unreserved = /[\w.-]/; // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead
    str = (str+'').toString();
    for (var i = 0, dl = str.length; i < dl; i++) {
        var ch = str.charAt(i);
        if (unreserved.test(ch)) {
            ret += ch;
        }
        else {
            var code = str.charCodeAt(i);
            if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters); https://developer.mozilla.org/index.php?title=en/Core_JavaScript_1.5_Reference/Global_Objects/String/charCodeAt
                ret += ((code - 0xD800) * 0x400) + (str.charCodeAt(i+1) - 0xDC00) + 0x10000;
                i++; // skip the next one as we just retrieved it as a low surrogate
            }
            // We never come across a low surrogate because we skip them, unless invalid
            // Reserved assumed to be in UTF-8, as in PHP
            else if (code === 32) {
                ret += '+'; // %20 in rawurlencode
            }
            else if (code < 128) { // 1 byte
                ret += hexStr(code);
            }
            else if (code >= 128 && code < 2048) { // 2 bytes
                ret += hexStr((code >> 6) | 0xC0);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 2048) { // 3 bytes (code < 65536)
                ret += hexStr((code >> 12) | 0xE0);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
        }
    }

    return ret;
}
