function toggle(link,obj,texts) {
	
	if($(obj).css('display') == 'none') {
		link.text(texts[0]);
		$(obj).show('slow');
	} else {
		link.text(texts[1]);
		$(obj).hide('slow');
	}
}
function externalLinks(){
    if (!document.getElementsByTagName) return;
    
    var anchors = document.getElementsByTagName("a");
    
    for (var i=0; i<anchors.length; i++){
        var anchor = anchors[i];
        if(anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
            anchor.target = "_blank";
        }
    }
}

function add_vote(id) {
	var optionId;

	$('div#sonda_cnt_'+id+' input[type=radio]').each(function() {
		if(this.checked==true) {
			optionId = this.value;
		}
	});

	$.post(
		"add_vote.php",
		{poll_id: id,question_id:optionId},
		function(data) {
			$('#sonda_cnt_'+id).empty();
			$('#sonda_cnt_'+id).append(data);
		}
	);
}

function switch_tabs_callback(obj) {
    $(obj).addClass('active');
}

function swich_tabs() {
    $('#submenu > ul > li > a').click(function() {
        $('#submenu > ul > li > a.active').removeClass();
        $(this).addClass('active');
        //$('.cont_item_active').hide();
        $('.cont_item_active').removeClass().addClass('cont_item_hidden');

        $('#cont_'+$(this).attr('rel')).removeClass();
        $('#cont_'+$(this).attr('rel')).addClass('cont_item_active');

    });
}

function init_actions() {
    $('ul#center_adds').innerfade({ speed: 2000, timeout: 5000, type: 'sequence', containerheight: '150px'});
}

var count_chars = 0;
var count_words = 0;

function init_offer(num) {
    $('#cmp_oferta_p').unbind();
    $('#cmp_oferta_p').charsCount({'maxChars':num, 'counterElement':"chars_count"});
}


function init_words(num) {
    $('#cmp_slowa_p').unbind();
    $('#cmp_slowa_p').wordCount({'maxWords':num, 'counterElement':"slowa_count"});
}

function init_cats(num) {
    var max=0;
    var i = 0;
    var j = 0;

    $('#cmp_cats_p').unbind();
    $('#cmp_cats_p').click(function(){
        max = $(this).selectedValues().length;
        if(max > num) {
            alert("Nie można wybrać większej ilości kategorii");
            op = $(this).selectedOptions();
            j = op.length;
            for(i = j; i > num; i--) {
                $(op[i - 1]).removeAttr('selected');
            }
            //$(op[max - 1]).removeAttr('selected');
            return false;
        }
    });
}

