$(function() {
    // aktiviraj thickbox za naknadno dodane elemente. reda radi dodajem i klasu thickbox
    tb_init($("a[@href*=thickbox]").addClass("thickbox"));

    // this initialises the demo scollpanes on the page.	
    $('#scrollPanel').jScrollPane({ showArrows: true, scrollbarWidth: 11 });
    $('#mycarousel').jcarousel({
        animation: 1000
    });
    $('#mycarousel li a').click(function(e) {
        e.preventDefault();

        var source = $(this).attr("href");
        var img = document.createElement("img");
        img.src = source;
        $(img).addClass("preloadImage");
        var cnt = document.createElement("div");

        if (!img.complete) {
            $(img).load(function() {
                $('#bigPic').fadeOut(500, function() {
                    $('#bigPic')
						.attr("src", source)
						.fadeIn(500);
                });
            });
        } else {
            $('#bigPic').fadeOut(500, function() {
                $('#bigPic')
					.attr("src", source)
					.fadeIn(500);
            });
        }
    });

    var newh = parseInt($(".jScrollPaneContainer").css("height")) - ((0 | $("#content h1").attr("offsetHeight")) - 54);

    $(".jScrollPaneContainer").css("height", newh);

    $("#scrollPanel").css("visibility", "visible");
    $(".jcarousel-skin-tango").css("visibility", "visible");

    /*
    menu
    */
    var $r = $("#drvo");
    $("a[href=#]", $r).bind("click", clickHandler);
    function clickHandler(e) {  //DOM node
        $(this).parent().siblings("li").children("ul").hide();
        $(this)
            .next("ul")
                .toggle();
        return false;
    }

    // current page
    var loc = location.href;
    $("a", $r).not("[href=#]").each(function() {
        if (loc.length >= this.href.length && loc.substr(loc.length - this.href.length) == this.href) {
            // found!
            $(this)
                .addClass("active")
                .parents().each(function() {
                    if (this.nodeName == "DIV")
                        return false;
                    else if (this.nodeName == "UL")
                        $(this).show();
                });
//console.log("this=%o, next.ul=%o", $(this), $(this).next("ul"));
            $(this)
                .next("ul")
                    .show();
            return false;
        }
    });


});

