function addCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? ',' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + '.' + '$2');
    }
    return x1 + x2;
}

function changeMotivna(arr, arr2, arr3, arr4, kam, imgpath, steviloslik, showdirect) {

    var blendtime = 1200;
    if (showdirect == 0 && manual) return;

    var st = motivnacounter;
    // preklop naprej
    if (kam == 1) if (st < steviloslik - 1) st++; else st = 0;
    // preklop nazaj
    if (kam == -1) if (st > 0) st--; else st = steviloslik - 1;


    if (showdirect > 0) {
        st = showdirect - 1;
        blendtime = 100;
        manual = true;
    }

    motivnacounter = st;

    if (arr[st]) {
        blendimage("motivna", "motivnaimg", imgpath + arr[st], blendtime);
    }

    var link = document.getElementById("motivnalink");
    if (link) {
        if (arr2[st])
            link.href = arr2[st];
        else
            link.href = "";

        if (arr3[st])
            link.title = arr3[st];
        else
            link.title = "";

    }

    var motimg = document.getElementById("motivnaimg");
    if (motimg) {
        if (arr4[st])
            motimg.alt = arr4[st];
        else
            motimg.alt = "";
    }

    // oznacim link
    for (var f = 1; f <= steviloslik; f++) {
        var lnk = document.getElementById("bannerstevilkalink" + f);
        if (lnk) lnk.className = f == st + 1 ? "selected" : "";
    }
}

function blendimage(divid, imageid, imagefile, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //set the current image as background 
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";

    //make image transparent 
    changeOpacVita(0, imageid);

    //make new image 
    document.getElementById(imageid).src = imagefile;

    //fade in image 
    for (i = 0; i <= 100; i++) {
        setTimeout("changeOpacVita(" + i + ",'" + imageid + "')", (timer * speed));
        timer++;
    }
}


//change the opacity for different browsers 
function changeOpacVita(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}


function showClanek(counter, all) {
    for (var r = 1; r <= all; r++) {
        var el1 = document.getElementById("claneklnk" + r);
        var el2 = document.getElementById("clanektxt" + r);

        if (el1) el1.className = r==counter ? "link linkopen" : "link";
        if (el2) el2.className = r == counter ? r == all ? "vsebina vsebinaopen vsebinalast" : "vsebina vsebinaopen" : "vsebina";
    }
}
