var GeneralStartup =
{
    run: function () {
        /*	Izpostavljeno na vstopni strani	*/
        if ($('#entry_slider .slides').length)
            $('#entry_slider .slides').cycle({
                speed: 'fast',
                timeout: 5000,
                pager: '#entry_slider .tabs',
                activePagerClass: 'active',
                pagerAnchorBuilder: function (idx, slide) {
                    return '#entry_slider .tabs li:eq(' + idx + ')';
                }
            });

        /*	Citati v glavi	*/
        if ($('#head_quotes ul').length)
            $('#head_quotes ul').cycle({
                cleartypeNoBg: true,
                speed: 'fast',
                timeout: 0,
                prev: $('#head_quotes a.prev'),
                next: $('#head_quotes a.next')
            });

        /*	Izbira jezika	*/
        $('#lang_selector li.active').click(function () {
            $('#lang_selector li:not(.active)').slideToggle();
        });
        if ($('#side_nav li ul li').hasClass('active')) {
            var z = $('#side_nav li ul li.active').parent().parent();
            $(z).addClass('active');
            $(z).find('a').first().addClass('b');
            //$('#side_nav li ul li.active').parent().parent().addClass('b');
        }
        $('#side_nav li').each(function () {
            if ($(this).hasClass('active')) {

            } else {
                $(this).find('ul').hide();
            }
        });
        /*	Carousel galerije	*/
        $('.gallery').each(function () {
            $(this).find('.scrollable').scrollable().navigator($(this).find('.navi'));
        })
        $('#slides').cycle({
            //fx: 'turnDown',
            timeout: 0,
            pager: '#d_nav',
            prev: '#prev',
            next: '#next',
            after: onAfter1
        });
        function onAfter1(curr, next, opts) {
            $("#p_current").html(opts.currSlide + 1);
            $("#p_all").html(opts.slideCount);
            //$("#slides img").lazyload({ placeholder: "/Content/images/photo 2.PNG", container: $("#slides") });
        }
        $('#slides').hover(
			function () {
			    $('#slides').cycle('pause');
			},
			function () {
			    $('#slides').cycle('resume');
			}
		);
        /*if ($("#logo").attr('width') < 220) {
            $("#logo").attr('width', 'auto');
        }*/

        var href = window.location.href.slice(window.location.href).split('/');
        var link = '';
        for (var i = 3; i < href.length; i++) {
            if ((href[i] == 'page') | (href[i] == 'trgovina')) {
                break;
            }
            link = link + '/' + href[i];
        }
        $("#side_nav a").each(function () {
            if ($(this).attr('href') == link) {
                $(this).addClass('b active');
                $(this).parent().addClass('active');
            }
        });
    }
}
StartUp(GeneralStartup);

/*	Colorbox: na link s classom .colorbox obesi colorbox. Opcije se dodajo s classom cb_opcija_vrednost	*/
var CbLauncher =
{
	crx: /^cb_([a-z]+)_?(.*)?$/,
	run: function()
	{
		if ($.colorbox) {
			$("a.colorbox").each(function () {
				var options = new Object;
				$.each ($(this).attr("class").split(' '), function () {
					if (result = this.match(CbLauncher.crx))
						options[result[1]] = result[2] ? result[2] : true;
				});
				if ($(this).attr("rel")) {
					options['rel'] = $(this).attr("rel");
				}
				$(this).colorbox (options);
			});
		}
	}
}
StartUp (CbLauncher);

/* Start Up */
function StartUp(runnable)
{
	$(document).ready(runnable.run);
}
