/*
 *		plik: 		js/scripts.js
 *		autor: 		Technetium [Tc]
 *             	Kamil Zawada
 *						16 marzec 2010
 *		system:		T.CMS-4.0-SEO
 */

var style_fontsize;
style_fontsize = 0;

function vIE(){return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;}

function obsluzIe6()
{
    $("body").css("background", "#000");
    $("body").html("<div id='ie6_info'><p class='p1'>Używasz starej wersji programu Internet Explorer. Aby skorzystać ze wszystkich funkcji naszej strony,</p> <p class='p2'>pobierz najnowsze: <a href='http://www.microsoft.com/poland/windows/internet-explorer/' title='Internet Explorer'>Internet Explorer</a> / <a href='http://www.mozilla-europe.org/pl/firefox/' title='Mozilla Firefox'>Mozilla Firefox</a> / <a href='http://www.opera.com/portal/choice/?language=pl' title='Opera'>Opera</a></p> <p class='p3'>Przepraszamy za kłopoty.</p></div>");
}

function incFontsize()
{
    style_fontsize = style_fontsize + 1;
    if(style_fontsize >= 2)
    {
        style_fontsize = 2;
    }

    chgFontsize(style_fontsize);
}


function decFontsize()
{
    style_fontsize = style_fontsize - 1;
    if(style_fontsize <= 0)
    {
        style_fontsize = 0;
    }

    chgFontsize(style_fontsize);
}

function autoChgFontsize()
{
    style_fontsize = parseInt(GetCookie("tc_fontsize"));

    if(style_fontsize)
    {
    }
    else
    {
       style_fontsize = 0;
    }

    chgFontsize(style_fontsize);
}

function chgFontsize(nr)
{

    $("link.style_fontsize").attr("href", "");
    $("link.style_fontsize").attr("rel", "alternate stylesheet");
    $("link#style_"+nr).attr("href", TPL_URL+"/css/style_"+nr+".css");
    $("link#style_"+nr).attr("rel", "stylesheet");

    style_fontsize = nr;

    $(".fontsize").children("a").removeClass("act");
    if(nr==2)
    {
        $(".fontsize").children("a#fontsize_max").addClass("act");
    }
    else
    {
        if(nr==1)
        {
            $(".fontsize").children("a#fontsize_eq").addClass("act");
        }
        else
        {
            $(".fontsize").children("a#fontsize_min").addClass("act");
        }
    }

    SetCookie("tc_fontsize", style_fontsize);
}



function setSpolOpis(o)
{
    var id = o.parents("div");
    id = id.attr("id").replace("spol_linki_", "");

    $("#spol_opis_"+id).html("| "+o.attr("title"));
}

function hideSpolOpis(o)
{
    var id = o.parents("div");
    id = id.attr("id").replace("spol_linki_", "");

    $("#spol_opis_"+id).html("");
}

function hideCalosc(id)
{
    $("#wpisy_item_calosc_"+id).hide(500);
    $("#wpisy_item_calosc_"+id).html(" ");
    $("#czytaj_calosc_"+id).html("czytaj całość");
    $("#czytaj_calosc_"+id).attr("onclick", "");
    $("#czytaj_calosc_"+id).unbind("click");
    $("#czytaj_calosc_"+id).click(function() { showCalosc(id); });

}

function showCalosc(id)
{
    advAJAX.get({
            url: BASE_URL +'/ajax_wpis.html?id=' + id,
            onInitialization : function()
            {
                    $("#wpisy_item_calosc_"+id).html("<div class='ajax_loading'></div>");
            },
            onSuccess : function(obj)
            {
                    $("#wpisy_item_calosc_"+id).hide();
                    $("#wpisy_item_calosc_"+id).html(obj.responseText);
                    $("#wpisy_item_calosc_"+id).show(500);
                    $("#czytaj_calosc_"+id).html("schowaj całość");
                    $("#czytaj_calosc_"+id).attr("onclick", "");
                    $("#czytaj_calosc_"+id).unbind("click");
                    $("#czytaj_calosc_"+id).click(function() { hideCalosc(id); });
            },
            onError : function(obj)
            {
                    $("#wpisy_item_calosc_"+id).html("error:");
            }
    });
}

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
        path = '/';
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}







