jQuery.noConflict();

var cos=0;

function rotationMultiboxDefault(multiBoxHolder) {
    
    var _rotation_cb = undefined;
    var mbHolder = jQuery('#' + multiBoxHolder.id);
    
    function _rotate() {
        var selectedId = jQuery('#' + mbHolder.attr('id') + ' > div > .c-multibox-default-navigator > .c-multibox-selected').attr('id');
        var idPrefix = selectedId.replace(/[0-9]+$/g, '');
        var idNumber = parseInt(selectedId.substr(idPrefix.length));
        var nextElem = jQuery('#' + idPrefix + (idNumber + 1));
        if (nextElem.length == 0) {
            nextElem = jQuery('#' + idPrefix + (1));
        }
        nextElem.children('a').click();
    }
    
    function _startRotation() {
        if (_rotation_cb == undefined) {
            _rotation_cb = window.setInterval(_rotate, 16000);
        }
    }
    
    function _stopRotation() {
        if (_rotation_cb != undefined) {
            window.clearInterval(_rotation_cb);
            _rotation_cb = undefined;
        }
    }
    
    mbHolder.hover(_stopRotation, _startRotation);
    //(function () {_startRotation();});
    //mbHolder.mouseover(_stopRotation);
    _startRotation();
}


function onInitRotationMultibox() {
    jQuery('.c-multibox-default-navigator > div > a').click(
        function () {
            var curr = jQuery(this);
            var navigator = curr.parent().parent();
            var boxroot = navigator.parent().parent();
            jQuery('#' + boxroot.attr('id') + ' > div > .c-multibox-default-navigator > div').removeClass('c-multibox-selected');
            jQuery('#' + boxroot.attr('id') + " .c-multibox-default-content").hide();
            jQuery('#'+curr.parent().attr('id') + '-content').fadeIn(1000);
            this.parentNode.className += ' c-multibox-selected';
        }
    );
    jQuery.each(jQuery('.c-multibox-default'), function() {new rotationMultiboxDefault(this);});
}



function rotationMultiboxZadzwon(multiBoxHolder) {
    
    var _rotation_cb = undefined;
    var mbHolder = jQuery('#' + multiBoxHolder.id);
    
    function _rotate() {
        var selectedId = jQuery('#' + mbHolder.attr('id') + ' > div > .c-multibox-zadzwon-navigator > .c-multibox-selected').attr('id');
        var idPrefix = selectedId.replace(/[0-9]+$/g, '');
        var idNumber = parseInt(selectedId.substr(idPrefix.length));
        var nextElem = jQuery('#' + idPrefix + (idNumber + 1));
        if (nextElem.length == 0) {
            nextElem = jQuery('#' + idPrefix + (1));
        }
        nextElem.children('a').click();
    }
    
    function _startRotation() {
        if (_rotation_cb == undefined) {
            _rotation_cb = window.setInterval(_rotate, 10000);
        }
    }
    
    function _stopRotation() {
        if (_rotation_cb != undefined) {
            window.clearInterval(_rotation_cb);
            _rotation_cb = undefined;
        }
    }
    
    mbHolder.hover(_stopRotation, _startRotation);
    //(function () {_startRotation();});
    //mbHolder.mouseover(_stopRotation);
    _startRotation();
}


function onInitRotationMultiboxZadzwon() 
{
    jQuery('.c-multibox-zadzwon-navigator > div > a').click(
        function () {
            var curr = jQuery(this);
            var navigator = curr.parent().parent();
            var boxroot = navigator.parent().parent();
            jQuery('#' + boxroot.attr('id') + ' > div > .c-multibox-zadzwon-navigator > div').removeClass('c-multibox-selected');
            jQuery(this).parent().addClass('c-multibox-selected');
            jQuery('#' + boxroot.attr('id') + " .c-multibox-zadzwon-content").hide();
            jQuery('#'+curr.parent().attr('id') + '-content').fadeIn(1000);
        }
    );
    jQuery.each(jQuery('.c-multibox-zadzwon'), function() {new rotationMultiboxZadzwon(this);});
}

jQuery(document).ready(onInitRotationMultiboxZadzwon);
jQuery(document).ready(onInitRotationMultibox);
