// onDocumentReady
$(document).ready(function(){

    
    // lightbox
    $("a[rel^='lightbox']").colorbox({
        rel:'lightbox', 
        transition:'fade', 
        opacity: 0.89, 
        current: "foto {current} z {total}"
    });
    
    
    // buy button click
    $('.sys-button-buy').click(function(){
        var productCount = $(this).parent().find('input').val();
        var addToBasketLink = $(this).attr('href') + '&pocet=' + parseInt(productCount);
        $('.sys-block-basket').load(addToBasketLink, function(){
            $.notifyBar({
                html: 'Produkt byl vložen do košíku. Počet: ' + parseInt(productCount) + ' ks.',
                cls: 'success',
                delay: 2000,
                animationSpeed: 'normal'
            });
        });
        //alert(productCount);
        return false;
    });

    // on delete confirm
    $('.delete').click(function(){
        var del_record = confirm('Chcete položku opravdu smazat?');
        if(!del_record){ 
            return false; 
        }
    });




    //centerize subcategories text
    $('#podkategorie a span').each(function(){
        if($(this).height() < 20){
            $(this).parent().css('line-height', $(this).parent().height() + 'px');
        }
    });

    //sys-teaser
    // banner cycler
    numTabs = $(".sys-teaser .item").length;
    $('.sys-teaser-menu a').bind('click', function() {
        openTab($(".sys-teaser .item:eq("+$(this).index()+")"));
        return false;
    });
    autoRotate = setInterval("rotateTabs()", rotateSpeed);
    $('.sys-teaser').mouseover(function(){clearInterval(autoRotate);}).mouseout(function(){autoRotate=setInterval("rotateTabs()",rotateSpeed);});    
    
    
    // show order detail 
    // AJAX product detail open
    $('#seznam_objednavek .sys-ajax-button').live('click', function(){
        var target = '.' + $(this).attr('rel');
        $(target).load($(this).attr('href'), function(){
            $.scrollTo(target,600);
        });
        return false;
    });

    
    //form submit
    $('.sys-submit').click(function(){
        $(this).parent('form').submit();
        return false;
    });
    
});
// END onDocumentReady




// ----------------------------------------------------------------------------
// teaser setting and functions
var currentTab = 0;
var rotateSpeed = 6000;
var numTabs;
var autoRotate;
var toggleSpeed = 1000;
var toggleType = "";

function openTab(clickedTab) {

    var thisTab = $(".sys-teaser .item").index(clickedTab);
    
    $(".sys-teaser-menu a").removeClass("active");
    $(".sys-teaser-menu a:eq("+thisTab+")").addClass("active");
    
    $(".sys-teaser .item").fadeOut(toggleSpeed);
    $(".sys-teaser .item:eq("+thisTab+")").fadeIn(toggleSpeed);
    
    currentTab = thisTab;
    };

function rotateTabs() {
    var nextTab = (currentTab == (numTabs - 1)) ? 0 : currentTab + 1;
    openTab($(".sys-teaser .item:eq("+nextTab+")"));
};

