/* ----------------------------------------------------------------------------------------------------------
    E-SHOP JS SCRIPTS, v 1.0
---------------------------------------------------------------------------------------------------------- */
var hD = false;
function kosikReInit() {
    jQuery(".hide").hide();
    jQuery(".cartbox").hover(function () {
        jQuery(".show").toggleClass("show-ac").next().slideToggle("fast");
    });
}

jQuery(document).ready(function () {

    /* ROZBALOVANI --- */
    kosikReInit();


    //          jQuery(".list-hide").hide();
    //          jQuery(".list-show").click(function(){
    //                jQuery(this).toggleClass("list-show-ac").next().slideToggle("medium");
    //            });

    //    var timerCartbox;

    //    jQuery(".hide").hide();
    //    jQuery(".list-hide").hide();

    //    jQuery(".cartbox").mouseenter(function () {
    //        if (timerCartbox) {
    //            clearTimeout(timerCartbox);
    //            timerCartbox = null
    //        }
    //        else {
    //            timerCartbox = setTimeout(function () {
    //                jQuery(".show").toggleClass("show-ac").next().slideToggle("fast");
    //            }, 500);
    //        }
    //    });
    //    jQuery(".list-show").mouseleave(function () {
    //        //alert('');
    //        jQuery(".list-show").toggleClass("list-show-ac").next().slideToggle("medium");
    //    });




    /* OZNACOVANI POLOZEK --- */
    jQuery(".header .goods li:last,.fce ul li:last,.text table tbody tr:last,ul.inline li:last").addClass("last");
    jQuery(".hp .bottom dl dd:last").addClass("last");
    jQuery(".side .cats ul li:last").addClass("last");
    jQuery(".side .cats li ul li ul li:last").addClass("last");
    jQuery(".breads li.c:last,.breads li.c ul li:last").addClass("last");
});



/* TABY --- */
jQuery(document).ready(function(){
  jQuery(".sort-time-content").hide();
  jQuery(".sort-time-tabs ul li:first").addClass("ac").show();
  jQuery(".sort-time-content:first").show();
  jQuery(".sort-time-tabs ul li").click(function() {
  	jQuery(".sort-time-tabs ul li").removeClass("ac");
  	jQuery(this).addClass("ac");
  	jQuery(".sort-time-content").hide();
  	var activeTab = $(this).find("a").attr("href");
  	jQuery(activeTab).fadeIn();
  	LoadProductList(activeTab);
  	return false;
  });
  jQuery(".sort-all-content").hide();
  jQuery(".sort-all-tabs li:first").addClass("ac").show();
  jQuery(".sort-all-content:first").show();
  jQuery(".sort-all-tabs li").click(function() {
  	jQuery(".sort-all-tabs li").removeClass("ac");
  	jQuery(this).addClass("ac");
  	jQuery(".sort-all-content").hide();
  	var activeTab = $(this).find("a").attr("href");
  	jQuery(activeTab).fadeIn();
  	LoadProductList(activeTab);
  	return false;
  });
});

/* TABY --- */
jQuery(document).ready(function () {
    jQuery(".tabs-content").hide();
    jQuery(".tabs ul li:first").addClass("ac").show();
    jQuery(".tabs-content:first").show();
    jQuery(".tabs li").click(function () {
        jQuery(".tabs li").removeClass("ac");
        jQuery(this).addClass("ac");
        jQuery(".tabs-content").hide();
        var activeTab = $(this).find("a").attr("href");
        jQuery(activeTab).fadeIn();
        return false;
    });


    /* GALERIE --- */
    jQuery("a.gall-item").fancybox();
    jQuery("a.inline").fancybox({
        'hideOnContentClick': true
    });
    /* Apply fancybox to multiple items */
    $("a.group").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': false
    });

    $("#BonusPointInfo").fancybox({
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'type': 'iframe',
        width: 620,
        height: 510,
        margin: 10,
        padding: 5,
        scrolling: 'no'
    });
    $("#doporucit").fancybox({
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'type': 'ajax',
        width: 620,
        height: 510,
        margin: 10,
        padding: 5,
        scrolling: 'no'
    });

   // $("#desc-orig").hide();



    /* VYHLEDÁVÁNÍ */
    var reEscape = new RegExp('(\\' + ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'].join('|\\') + ')', 'g');
    function fnFormatResultItem(value, data, currentValue, s) {
        var pattern = '(' + currentValue.replace(reEscape, '\\$1') + ')';
        //var name = value.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>');

        if (s.Type == 'pr') {
            //jedná se o produkty
            var sleva = '';
            if (s.Discount > 0) {
                sleva = '(sleva ' + Math.round(s.Discount) + '%)'
            }
            return '<a href="' + s.Url + '" title="Detail alba"><img src="' + s.ImgUrl + '" alt="" height="40" width="40" /></a>'
                    + '<div class="itemint"><h4><a href="' + s.Url + '" title="Detail alba">' + s.Name + '</a></h4>'
                    + '<p>' + s.Description + '</p></div>'
                    + '<p class="price"><strong>' + s.PriceWithVatFormat + ' Kč</strong> ' + sleva + '</p>';


        } else if (s.Type == 'cat') {
            //jedná se o kategorie
            return '<a href="' + s.Url + '">' + s.Name + '</a>';

        }

        return '';
    }
    function fnLoadingSearch() { $("#btn-loading-search").attr("src", core_hPath + 'img/header-search-image-load.gif'); }
    function fnLoadedSearch() { $("#btn-loading-search").attr("src", core_hPath + 'img/header-search-image.gif'); }

    var sBox = $("#whisper"); //width: sBox.width(), left: 15
    options = { serviceUrl: core_hUrl + 'service-search.aspx?', width: '293px',
        headers: [{ type: 'pr', text: 'Produkty' }, { type: 'cat', text: 'Kategorie'}],
        onSelectNotSetInput: true,
        onSelect: function (s) {
            document.location = s.Url;
            return;
        },
        fnFormatResult: fnFormatResultItem
        , onLoading: fnLoadingSearch,
        onLoaded: fnLoadedSearch,
        minChars: 2,
        maxHeight: 650
    };
    $("#searchInput").autocomplete(options);

});



var loadedTab = new Array('#tento-tyden', '#nejprodavanejsi');

function LoadProductList(activeTab) {

    var h = $(activeTab).html();

    for (i = 0; i < loadedTab.length; i++) {
        if (loadedTab[i] == activeTab)
            return;
    }

    loadedTab.push(activeTab);
    var urlO = '';
    if (activeTab == '#tento-tyden') {
        urlO = 'TopWeek';
    } else if (activeTab == '#mesic') {
        urlO = 'TopMonth';
    }
    else if (activeTab == '#rok') {
        urlO = 'TopYear';
    }
    else if (activeTab == '#slevy') {
        urlO = 'Date';
    }

    $.ajax({
        url: 'product-list-ajax.aspx?c=13&t=ucc&a=&i=1&o=' + urlO + '&h=0',
        success: function (data) {
            $(activeTab).html(data);
        },
        beforeSend: function (xhr) {
            $(activeTab).html('<img src="' + core_hPath + 'img/ajax-loader.gif" style="margin-left:114px" />');
        }
    });
}

/*výběr obrázků v detailu*/
function detailImgSel(url, url2) {
    var o = document.getElementById('img-detail-prim');
    o.src = url;
    o = document.getElementById('img-detail-prim-a');
    o.href = url2;
    //změním i odkaz  
}


/* DIALOG KOSIK */
jQuery(document).ready(function () {
    $("#dialog-kosik").dialog({
        autoOpen: false,
        show: "fade",
        hide: "explode",
        modal: true,
        closeOnEscape: false,
        resizable: false,
        dialogClass: 'no-close'
    });
});

var Core_AddBasketAjaxReturnFn = function () {
    kosikReInit();
    $("#dialog-kosik").dialog("close");
}
function HM_AddBasketAjax(a, b, c) {
    $("#dialog-kosik").dialog("open");
    Core_AddBasketAjax(a, b, c);
}

