// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License

function parseUri (str) {
    var	o   = parseUri.options,
    m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
    uri = {},
    i   = 14;

    while (i--) uri[o.key[i]] = m[i] || "";

    uri[o.q.name] = {};
    uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
        if ($1) uri[o.q.name][$1] = $2;
    });

    return uri;
};

parseUri.options = {
    strictMode: false,
    key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
    q:   {
        name:   "queryKey",
        parser: /(?:^|&)([^&=]*)=?([^&]*)/g
    },
    parser: {
        strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
        loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
    }
};



function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};


$(document).ready(function() {
    
    
    $("a.prettyPhoto").prettyPhoto({
        theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square / facebook */
    });
    
    $('#mycarousel').jcarousel({
        auto: 2,
        wrap: 'circular',
        animation:500,
        scroll:5,
        initCallback: mycarousel_initCallback
    });


    //    if(window.location.hash !== '') {
    //        alert (window.location.hash);
    //    }


    $('#mycarousel a').click(function() {
        var elementClicked = '#'+parseUri($(this).attr("href")).anchor;
        //var elementClicked = $(this).attr("href");
        //console.info(elementClicked);

        var destination = $(elementClicked).offset().top;
        $("html:not(:animated),body:not(:animated)").animate({
            scrollTop: destination-20
        }, 2000 );
        return false;
    });



    if(window.location.hash !== '') {
        $("html, body").scrollTop(0);
        var elementClicked = window.location.hash;
        var destination = $(elementClicked).offset().top;
        $("html:not(:animated),body:not(:animated)").animate({
            scrollTop: destination-20
        }, 2000 );
        return false;
    }


    $('#ponukaBtn').toggle(
        function()
        {

            $(this).animate({
                right: '120'
            }, 500);

            $('#ponukaContent').animate({
                right: "0",
                opacity:.8
            }, 500);

        },
        function()
        {
            $('#ponukaContent').animate({
                right: "-100",
                opacity:.2
            }, 500);
            $(this).animate({
                right: "1"
            }, 500);

        });


});
