﻿/// <reference path="/scripts/jquery-1.4.1-vsdoc.js" />
/// <reference path="/scripts/scriptsdefinition.debug.js" />
/*!
* © 2010 internetová agentura voatt
*/

(function () {
    function execute() {

        window.runcarousel = function () {
            var start = $.cookie('jcarousel_akcninabidka');
            if (start == null) {
                start = 1;
            }
            start = Number(start);
            $('#galleri').jcarousel({
                // Configuration goes here
                start: start,
                vertical: false,
                scroll: 1,
                auto: 5,
                wrap: 'both',
                initCallback: jcarousel_initCallback,
                itemFirstOutCallback: jcarousel_itemFirstOutCallback,
                itemFirstInCallback: jcarousel_itemFirstInCallback,
                itemVisibleInCallback: {
                    onBeforeAnimation: mycarousel_itemVisibleInCallbackBeforeAnimation,
                    onAfterAnimation: mycarousel_itemVisibleInCallbackAfterAnimation
                }
            });
        }

        function jcarousel_initCallback(carousel) {
            // Pause autoscrolling if the user moves with the cursor over the clip.
            carousel.container.hover(function () {
                carousel.stopAuto();
            }, function () {
                carousel.startAuto();
            });

            jQuery('.jcarousel-control a').bind('click', function () {
                carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
                return false;
            });
        };

        function jcarousel_itemFirstOutCallback(carousel, panel, index, d) {
            //if (d == 'next') {
            //	$.cookie('jcarousel_akcninabidka', index + 1);
            ///}
        }



        function jcarousel_itemFirstInCallback(carousel, panel, index, d) {
            //if (d == "prev") {
            $.cookie('jcarousel_akcninabidka', index, { path: '/' });
            //}
        }

        /**
        * This is the callback function which receives notification
        * when an item becomes the first one in the visible range.
        * Triggered before animation.
        */
        function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {
            $(".jcarousel-control a.active").removeClass("active");
            $(".jcarousel-control a:eq(" + (parseInt(idx) - 1) + ")").addClass("active");

        };

        /**
        * This is the callback function which receives notification
        * when an item becomes the first one in the visible range.
        * Triggered after animation.
        */
        function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {


        };

    } // execute

    if (window.Sys && Sys.loader) {
        Sys.loader.registerScript("runcarousel", null, execute);
    }
    else {
        execute();
    }
})();
