$(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 za posebne ponude i submenije
    var loc = location.href.substr(location.href.lastIndexOf("=") + 1);
    $("a", $r).not("[href=#]").each(function() {
        //console.log("href sub=%o, loc sub=%o ", this.href.substr(this.href.lastIndexOf("/") + 1), loc +".aspx");
        // stari uvjet je ostao //if (loc.length <= this.href.length && this.href.substr(this.href.length - loc.length) == loc) {
        // dodan je url rewrite // (this.href.substr(this.href.lastIndexOf("/") + 1) == (loc + ".aspx"))
        if (loc.length <= this.href.length &&
            (this.href.substr(this.href.lastIndexOf("/") + 1) == (loc + ".aspx"))
            || (this.href.substr(this.href.length - loc.length) == loc)
            ) {
            // 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;
        }
    });


});


