(function ($, sk)
{
    //$.fn.pdTabs = function (option) { option = jQuery.extend({ tabSelector: '.tab-fragment', tabNameSelector: '.tab-name', defTab: 0, tabPosition: 'top', hideTabClass: 'hide-tab', activeTabClass: 'active', callFunction: function () { }, prefix: 'hi_' }, option); var helpHash = ''; var sdiak = "áäčďéěíĺľňóôöŕšťúůüýřžÁÄČĎÉĚÍĹĽŇÓÔÖŔŠŤÚŮÜÝŘŽ/"; var bdiak = "aacdeeillnooorstuuuyrzAACDEEILLNOOORSTUUUYRZ."; function bezdiak(str) { var tx = ""; var txt = str; for (p = 0; p < txt.length; p++) { if (sdiak.indexOf(txt.charAt(p)) != -1) { tx += bdiak.charAt(sdiak.indexOf(txt.charAt(p))) } else tx += txt.charAt(p) } return tx }; $(this).each(function () { var element = $(this); $(element).addClass('js'); var tabConstruct = { name: function () { var i = 0; var arr = []; $('' + option.tabSelector, element).each(function () { var size = $('' + option.tabNameSelector, this).size(); if (size > 0) { if ($('' + option.tabNameSelector + ':eq(0)', this).attr('title') != '') { arr[i] = $('' + option.tabNameSelector + ':eq(0)', this).attr('title') } else { arr[i] = $('' + option.tabNameSelector + ':eq(0)', this).text() } } else { var j = i + 1; arr[i] = 'Tab ' + j } i++ }); return arr }, id: function () { var arr = this.name(); for (var i = 0; i < arr.length; i++) { arr[i] = bezdiak(arr[i].toLowerCase()); arr[i] = arr[i].replace(/\s/g, "-").replace(/[-]{2,}/g, "-").replace(/\.|\{|\}|\(|\)|\[|\]|\\|@|:|\d/g, "").replace(/^-/, "").replace(/-$/, "") } return arr }, size: $('' + option.tabSelector, element).size(), tabList: function () { var arrName = tabConstruct.name(); var arrId = tabConstruct.id(); var list = '<ul class="tab-list">'; for (var i = 0; i < this.size; i++) { if ($('' + option.tabSelector, element).eq(i).hasClass('special')) { list += '<li class="tab-' + (i + 1) + ' tab-' + arrId[i] + ' tab-special"><a href="#' + arrId[i] + '"><span>' + arrName[i] + '</span></a></li>' } else { list += '<li class="tab-' + (i + 1) + ' tab-' + arrId[i] + '"><a href="#' + arrId[i] + '"><span>' + arrName[i] + '</span></a></li>' } } list += '</ul>'; return list } }; if (option.tabPosition == 'bottom') { $(element).append(tabConstruct.tabList()); $('.tab-list a').each(function () { $(this).attr('href', '#' + $(this).attr('href').split('#')[1]) }) } else { $(element).prepend(tabConstruct.tabList()); $('.tab-list a').each(function () { $(this).attr('href', '#' + $(this).attr('href').split('#')[1]) }) } var i = 0; var arrId = tabConstruct.id(); $('' + option.tabSelector, element).each(function () { $(this).attr('id', arrId[i]); i++ }); function makeTabByHash(hash) { if (typeof hash != 'undefined') { var hash = hash } else { var hash = '' } if (hash != '') { var onlyHash = hash; hash = option.prefix + hash } else { hash = window.location.hash.slice(1) } if (hash == '' && helpHash == '') { var index = typeof option.defTab == 'number' ? option.defTab : 0; $('' + option.tabSelector, element).eq(index).removeClass(option.hideTabClass); $('' + option.tabSelector, element).not(':eq(' + index + ')').addClass(option.hideTabClass); $('.tab-list li', element).not(':eq(' + index + ')').removeClass(option.activeTabClass); $('.tab-list li', element).eq(index).addClass(option.activeTabClass) } else { if ($('#' + hash, element).is(option.tabSelector) == true) { $('#' + hash, element).filter('.hide-tab').removeClass(option.hideTabClass); $('' + option.tabSelector, element).not('#' + hash + '').addClass(option.hideTabClass); var index = $('' + option.tabSelector, element).index($('#' + hash)); $('.tab-list li', element).not(':eq(' + index + ')').removeClass(option.activeTabClass); $('.tab-list li', element).eq(index).addClass(option.activeTabClass); helpHash = hash } else if ($('' + option.tabSelector + ' #' + hash, element).size() > 0 || $('' + option.tabSelector + ' #' + onlyHash, element).size() > 0) { if ($('' + option.tabSelector + ' #' + hash, element).size() > 0) { var index = $('' + option.tabSelector, element).index($('#' + hash).parents('' + option.tabSelector)) } else { var index = $('' + option.tabSelector, element).index($('#' + onlyHash).parents('' + option.tabSelector)) } $('' + option.tabSelector, element).eq(index).removeClass(option.hideTabClass); $('' + option.tabSelector, element).not(':eq(' + index + ')').addClass(option.hideTabClass); $('.tab-list li', element).not(':eq(' + index + ')').removeClass(option.activeTabClass); $('.tab-list li', element).eq(index).addClass(option.activeTabClass); helpHash = $('' + option.tabSelector + ' #' + hash, element).parents('' + option.tabSelector).attr('id') } else { if (helpHash == '') { var index = typeof option.defTab == 'number' ? option.defTab : 0 } else { var index = $('' + option.tabSelector, element).index($('#' + helpHash)) } $('' + option.tabSelector, element).not(':eq(' + index + ')').addClass(option.hideTabClass); $('.tab-list li', element).not(':eq(' + index + ')').removeClass(option.activeTabClass); $('.tab-list li', element).eq(index).addClass(option.activeTabClass) } option.callFunction(); if ($('' + option.tabSelector + ' #' + hash, element).size() > 0) { var top = $('#' + hash).offset().top; $('html, body').scrollTop(top) } } }; $('a[href^="#"]').each(function () { var hash = $(this).attr('href').split('#'); hash = hash[hash.length - 1]; if (hash != '' && $('#' + hash, element).size()) { $('#' + hash).each(function () { this.id = option.prefix + this.id }); $('label[for="' + hash + '"]').each(function () { this.htmlFor = option.prefix + this.htmlFor }); $(this).click(function () { $.history.load(hash); return false }) } }); $.history.init(makeTabByHash); var hash = window.location.hash; hash = hash.replace(/^.*#/, ''); if (hash != '') { $.history.load(hash) } else { makeTabByHash() } }) };


    var widgets = sk.widgets,
		Carousel = widgets.Carousel,
		Thickbox = widgets.Thickbox,
		Checkbox = widgets.Checkbox,
		Radio = widgets.Radio,
		Ajax = widgets.Ajax,
		ToggleBox = widgets.ToggleBox,
		Dialog = widgets.Dialog,
		Tabs = widgets.Tabs;

    $.fn.skGet = function (get, dimension, callback)
    {
        if (!this.length)
        {
            return this;
        }

        var result;
        var m = Math[get];
        this.each(function (index)
        {
            var newResult = $(this)[dimension]();
            result = index ? m(result, newResult) : newResult;
        });

        if (typeof callback == 'function')
        {
            callback.call(this, result);
            return this;
        }

        return result;
    };



    $(document).ready(function ()
    {
        // Reset input
        $('.resetInt').inputText({});

        // Trigger click
        $('.product-list li, .rank-table tr, .guide-box, .box-click').click(function ()
        {
            window.location = $(this).find('.title a').attr('href');
        });
        /*$('span.inline-btn').click(function(){
        $(this).find('input').click();
        });*/

        // Params search height fix
        $('.param-search p').each(function ()
        {
            var $this = $(this);
            if ($this.height() > 200 && $(window).width() > 768)
            {
                $this.addClass('scroll');
            }
        });

        // Thickbox
        var thickbox = new Thickbox();
        thickbox.control($('.thickbox'));
        thickbox.autoWidth = true;

        // Equal Heights
        function eq($element, item, count1)
        {
            $element.each(function ()
            {
                var $items = $(this).find(item),
					end = $items.length,
					count = count1 ? count1 : parseInt($(this).attr('name'));

                for (var i = 0; i < end; i = i + count)
                {
                    $items.slice(i, i + count).skGet('max', 'height', function (val)
                    {
                        this.height(val);
                    });
                };
            });
        };

        if ($(window).width() > 768)
        {
            eq($('.tabs-wrap'), '.tab-fragment', 4);
            eq($('.product-list.eq-3, .product-list-other.eq-3'), '.title a', 3);
            eq($('.product-list.eq-3, .product-list-other.eq-3'), '.in', 3);
            eq($('.product-list-other.eq-4, .product-list.eq-4'), '.title a', 4);
            eq($('.category-list.eq-4'), '.title', 4);
            eq($('.category-list.eq-4, .product-list.eq-4'), '.in', 4);
            eq($('.nayExtra-sale .eq-3'), 'li', 3);
        }
        else if ($(window).width() > 600)
        {

            eq($('.tabs-wrap'), '.tab-fragment', 4);
            eq($('.category-list'), '.title', 3);
            eq($('.nayExtra-sale .eq-3'), 'li', 3);

            eq($('.product-list, .product-list-other'), '.title a', 3);
            eq($('.category-list, .product-list, .product-list-other'), '.in', 3);
        }
        else if ($(window).width() > 320)
        {
            eq($('.tabs-wrap'), '.tab-fragment', 4);
            eq($('.category-list'), '.title', 2);
            eq($('.nayExtra-sale .eq-3'), 'li', 2);

            eq($('.product-list, .product-list-other'), '.title a', 2);
            eq($('.category-list, .product-list, .product-list-other'), '.in', 2);
        }

        // AJAX - PRODUCT LIST
        //        $('.param-search').each(function () {
        //            var $this = $(this);
        //            $(window).delegate('.param-search input, select', 'change', function () {
        //                var $this = $(this).closest('.param-search');
        //                var ajaxParamSearch = $.ajax({
        //                    type: "GET",
        //                    url: '/ajax/product-list',
        //                    data: $this.serialize(),
        //                    beforeSend: function () {
        //                        ajaxParamSearch && ajaxParamSearch.abort();
        //                        this.$special = $('.product-list');
        //                        this.$special.wrap('<div class="ajax-wrap"></div>');
        //                        $('<div class="ajax-loader"></div>').appendTo(this.$special).css('opacity', 0).fadeTo(250, 1);
        //                    },
        //                    success: function (response) {
        //                        this.$special = $('.product-list');
        //                        this.$special.html(response);
        //                        this.$special.unwrap('<div class="ajax-wrap"></div>');
        //                        this.$special.find('.ajax-loader').fadeTo(250, 0, function () { $(this).remove() });
        //                        eq($('.product-list.eq-3'), '.title a', 3);
        //                        eq($('.product-list.eq-3'), '.in', 3);
        //                    }
        //                });
        //            });

        //            if ($(window).width() < 769) {
        //                var $clone = $this.clone();
        //                $this.remove();
        //                $('.product-list').before($clone);
        //                $clone.find('fieldset').hide();
        //                $clone.find('h2').addClass('close');

        //                $(window).delegate('.param-search h2', 'click', function () {
        //                    if ($(this).hasClass('close')) {
        //                        $clone.find('fieldset').show();
        //                        $(this).removeClass('close');
        //                        $(this).addClass('open');
        //                    }
        //                    else {
        //                        $clone.find('fieldset').hide();
        //                        $(this).addClass('close');
        //                        $(this).removeClass('open');
        //                    }
        //                })
        //            }
        //        });

        //        $('.productList').delegate('.filter a, .paging .prev, .paging .next', 'click', function () {
        //            var abortAjax = $.ajax({
        //                type: "GET",
        //                url: '/ajax/product-list',
        //                data: $(this).attr('href'),
        //                beforeSend: function () {
        //                    abortAjax && abortAjax.abort();
        //                    this.$special = $('.product-list');
        //                    this.$special.wrap('<div class="ajax-wrap"></div>');
        //                    $('<div class="ajax-loader"></div>').appendTo(this.$special).css('opacity', 0).fadeTo(250, 1);
        //                },
        //                success: function (response) {
        //                    this.$special = $('.product-list');
        //                    this.$special.html(response);
        //                    this.$special.unwrap('<div class="ajax-wrap"></div>');
        //                    this.$special.find('.ajax-loader').fadeTo(250, 0, function () { $(this).remove() });
        //                    eq($('.product-list.eq-3'), '.title a', 3);
        //                    eq($('.product-list.eq-3'), '.in', 3);
        //                }
        //            });
        //        });

        // JS submit form
        $('.jsSubmit').each(function ()
        {
            var $this = $(this);

            $this.find('input, select').change(function ()
            {
                $this.submit();
            });
        });

        // MULTISLIDER CALL
        $('.multislider').each(function ()
        {
            $(this).multislider({
                fromTo: true,  // Povolení Od Do
                checkbox: false,
                minVal: $('p.title input:first', this).attr('title'),     // Minimální hodnota
                maxVal: $('p.title input:last', this).attr('title'),  // Maximální hodnota
                toolText: $('p.title', this).attr('title') // Popisek v nápovědě za číslem
            });
        });

        $(".slider1, .slider2").each(function ()
        {
            var slidervalue = $(".tool-tip > .tip-spc > span", this).html().replace(" ", "");
            //slidervalue = slidervalue.replace("+", "");
            if (slidervalue == "")
            {
                slidervalue = 0;
            }
            if ($(this).attr("class") == "slider1") slidersLeftCursorValues.push(slidervalue);
            else slidersRightCursorValues.push(slidervalue);
        });

        // Carousel	
        if ($(window).width() > 600)
        {
            var homeCarousel = new Carousel('.homepage .services-box .scroll', {
                item: '.item',
                visible: 1,
                animation: 500,
                htmlPager: '.homepage .services-box .pager',
                pause: false,
                pauseOnHover: '',
                timeout: 5000,
                repeat: true,
                auto: true
            });
            homeCarousel.init();
        }
        var imageCarousel = new Carousel('.images-scroll', {
            item: '.item',
            visible: 1,
            animation: 500,
            htmlPager: '.images-pager',
            pause: false,
            pauseOnHover: '',
            timeout: 5000,
            repeat: true,
            auto: true
        });
        imageCarousel.init();

        // Tabs
        $('.tabs-box').each(function ()
        {
            var $box = $(this);

            if ($(this).find('.countTab').length == 3)
                var $tabMenu = $('<p class="nav2"></p>');
            else
                var $tabMenu = $('<p class="nav"></p>');

            //alert($(this).find('.countTab').length); 
            $(this).find('.tab-fragment').each(function (index)
            {
                var id = $(this).attr('id');
                var name = $(this).find('.tab-name').attr('title') ? $(this).find('.tab-name').attr('title') : $(this).find('.tab-name').text();
                if ($box.is('#tab-box'))
                {
                    $('<a></a>').attr('href', '#' + id).text(name).appendTo($tabMenu);
                }
                else
                {
                    $('<a></a>').attr('href', '#' + id).text(name).addClass('before').appendTo($tabMenu);
                }
            });
            $tabMenu.prependTo($(this));

            var tabs = new sk.widgets.Tabs($tabMenu).init()
            $(window).hashchange(function (e)
            {
                tabs.hash();
            });
        });

        if (Dialog && $(window).width() > 600)
        {
            // POPUP
            $('.dialogue-control').each(function ()
            {

                var $link = $(this),
					hash = $link.prop('hash'),
					position = {
					    anchor: $link,
					    align: [0, 0],
					    place: [0, 1],
					    offset: [0, 0],
					    speed: 0,
					    fixed: false
					};

                if (hash === '#prihlasit' || hash === '#kosik' || hash === '#moj-ucet')
                {
                    position.anchor = '#user-menu',
					position.align = [1, 0];
                    position.place = [1, 1];
                    position.offset = [10, -26];
                }

                var dialog = new Dialog($link, {
                    animate: false,
                    position: position
                    //closeSelector: '.panel-dialogue-close, .panel-dialogue .reset',	
                }).init();

            });
            // Popovers close - out click
            $(document).bind('click', function (e)
            {
                if (!$(e.target).closest('.popup').length && !$(e.target).closest('.dialogue-control').length)
                {
                    Dialog.close();
                }
            })
        }
        else if ($(window).width() < 600)
        { // pokud jmen na screenu menším než 600 tak nezobrazuju popup, ale přesměruji na hlavní stránku
            $('.dialogue-control').click(function ()
            {
                window.location = $(this).attr('href').split('#')[1];
            });
        }

        // Menu		
        if ($(window).width() > 600)
        {
            $('#main-menu').each(function (i)
            {

                // generování html
                var html = '<div class="submenu-holder">';

                for (var i = 0, l = mainMenu.length; i < l; i++)
                {
                    html += mainMenu[i]; //+ '</div>';		
                }

                html += '</div>';

                // proměné
                var $menu = $(this);
                var $submenu = $(html).appendTo('body');
                var position = new sk.utils.Position({
                    element: $submenu
                });
                var $subs = $submenu.find('.submenu').hide();
                var $li = $menu.find('li');
                var index = -1;
                var isShow = false;
                var timer = {
                    on: null,
                    off: null
                };


                var over = function ()
                {
                    var $this = $(this);
                    var liIndex = $this.index();

                    // smazání časovače off
                    timer.off = clearTimeout(timer.off);

                    // pozice
                    var pos = function (width)
                    {

                        $submenu.width(width);

                        if ($this.position().left + width > 955)
                        {
                            $submenu.addClass('right');
                            position.$anchor = $this.closest('ul');
                            position.options.align = [1, 0];
                            position.options.place = [1, 1];
                            position.options.offset = [-5, 0];
                        }
                        else
                        {
                            $submenu.removeClass('right');
                            position.$anchor = $this;
                            position.options.align = [0, 0];
                            position.options.place = [0, 1];
                            position.options.offset = [4, 0];
                        }

                        position.init();
                    }

                    // ošetří opětovné najetí na stejnou položku - vzniká díky časovačům
                    if (index != liIndex)
                    {
                        if (isShow)
                        {
                            var $sub = $subs.stop(true, true).hide().eq(liIndex).show();

                            // aktivace položky v menu
                            $li.removeClass('active').eq(liIndex).addClass('active');

                            // nastavení hlavního indexu
                            index = liIndex;

                            pos($sub.width());
                        }
                        else
                        {
                            // nastavení časovače on - pouze pokud menu ještě není vidět
                            timer.on = setTimeout(function ()
                            {
                                var $sub = $subs.hide().eq(liIndex).slideDown(250);

                                isShow = true;

                                // aktivace položky v menu
                                $li.removeClass('active').eq(liIndex).addClass('active');

                                // nastavení hlavního indexu
                                index = liIndex;

                                pos($sub.width());
                            }, 150);
                        }
                    }

                }

                var out = function ()
                {
                    // smazání časovače off
                    timer.on = clearTimeout(timer.on);
                    // nastavení časovače off
                    timer.off = setTimeout(function ()
                    {
                        $subs.eq(index).slideUp(250, function ()
                        {
                            $li.removeClass('active');
                            isShow = false;
                            index = -1;
                        });
                    }, 150);
                };

                $(this).delegate('li', 'mouseenter mouseleave', function (e)
                {
                    if (e.type == 'mouseenter')
                    {
                        over.call(this)
                    }
                    else
                    {
                        out.call(this)
                    }
                });

                $submenu.bind('mouseenter mouseleave', function (e)
                {
                    if (e.type == 'mouseenter')
                    {
                        // smazání časovače off
                        timer.off = clearTimeout(timer.off);
                    }
                    else
                    {
                        out.call(this)
                    }
                });
            });
        }

        // Suggest
        if ($(window).width() > 768)
        {
            $('#search-box').each(function ()
            {
                var $box = $(this),
		    		$inp = $('.int-text', $box),
			    	data = $inp.attr('name') + '=',
			    	time = null,
			    	blur = true,
			    	suggest = {
			    	    el: '.suggest-box',
			    	    item: 'li',
			    	    hClass: 'active'
			    	};

                $inp.attr('autocomplete', 'off');
                $box.append('<span class="loader hidden"></span>');

                var ajaxSuggest = function ()
                {
                    var aData = $inp.attr('name') + '=' + $inp.val();
                    if (data != aData && $inp.val().length > 2)
                    {
                        data = aData;
                        $('.loader', $box).show();
                        var abortAjax = $.ajax({
                            type: "GET",
                            url: '/ajax/suggest/',
                            data: 'exps=' + $inp.val(),
                            beforeSend: function ()
                            {
                                abortAjax && abortAjax.abort();
                            },
                            success: function (xml)
                            {
                                $('.loader', $box).hide();
                                $(suggest.el).hide().remove();
                                $box.append(xml);

                                $(suggest.el).find(suggest.item).mouseover(function ()
                                {
                                    $(suggest.el).find(suggest.item + '.' + suggest.hClass).removeClass(suggest.hClass);
                                    $(this).addClass(suggest.hClass);
                                    blur = false;
                                }).mouseout(function () { blur = true; })

                                $(suggest.el).find('.more').mouseover(function () { blur = false; }).mouseout(function () { blur = true; })
                            }
                        });
                    }
                    else if ($inp.val().length <= 2)
                    {
                        $(suggest.el).remove();
                    }
                }


                $inp
		    		.bind('keydown keyup', function (e)
		    		{

		    		    var maxI = $(suggest.el).find(suggest.item).size() - 1;

		    		    if (e.keyCode == 40 && e.type == 'keydown')
		    		    {
		    		        if ($(suggest.el).find(suggest.item + '.' + suggest.hClass).size() == 0 || $(suggest.el).find(suggest.item + ':eq(' + maxI + ')').is('.' + suggest.hClass))
		    		        {
		    		            $(suggest.el).find(suggest.item + '.' + suggest.hClass).removeClass(suggest.hClass);
		    		            $(suggest.el).find(suggest.item + ':first').addClass(suggest.hClass);
		    		            i = 0;
		    		        }
		    		        else
		    		        {
		    		            var i = $(suggest.el).find(suggest.item).index($(suggest.el).find(suggest.item + '.' + suggest.hClass))

		    		            $(suggest.el)
		                            .find(suggest.item)
		                            .filter('.' + suggest.hClass)
		                                .removeClass(suggest.hClass)
		                                .end()
		                            .eq(++i)
		                                .addClass(suggest.hClass);
		    		        }
		    		        return false;
		    		    }

		    		    else if (e.keyCode == 38 && e.type == 'keydown')
		    		    {
		    		        if ($(suggest.el).find(suggest.item + '.' + suggest.hClass).size() == 0 || $(suggest.el).find(suggest.item + ':eq(0)').is('.' + suggest.hClass))
		    		        {
		    		            $(suggest.el).find(suggest.item + '.' + suggest.hClass).removeClass(suggest.hClass);
		    		            $(suggest.el).find(suggest.item + ':last').addClass(suggest.hClass);
		    		            i = maxI;
		    		        }
		    		        else
		    		        {
		    		            var i = $(suggest.el).find(suggest.item).index($(suggest.el).find(suggest.item + '.' + suggest.hClass))

		    		            $(suggest.el)
		                            .find(suggest.item)
		                            .filter('.' + suggest.hClass)
		                                .removeClass(suggest.hClass)
		                                .end()
		                            .eq(--i)
		                                .addClass(suggest.hClass);
		    		        }
		    		    }
		    		    else if (e.keyCode == 13)
		    		    {
		    		        if ($(suggest.el).find(suggest.item + '.' + suggest.hClass).size())
		    		        {
		    		            window.location = $(suggest.el).find(suggest.item + '.' + suggest.hClass + ' a:first').attr('href');
		    		            e.preventDefault();
		    		            return false;
		    		        }
		    		    }
		    		    else if (e.keyCode == 9)
		    		    {
		    		        blur = true;
		    		    }
		    		})
		    		.bind('focus', function ()
		    		{
		    		    time = setInterval(ajaxSuggest, 750);
		    		})
		    		.bind('blur', function ()
		    		{
		    		    if (blur)
		    		    {
		    		        $(suggest.el).remove();
		    		        time = clearInterval(time);
		    		    }
		    		});
            });
        }

        // COMPARE
        $('.product-list').each(function ()
        {

            var $box = $('.availability-popup');
            var position = new sk.utils.Position({
                element: $box,
                align: [1, 0],
                place: [1, 1],
                offset: [0, 0]
            });

            var timer = {
                on: null,
                off: null
            };

            var over = function ()
            {
                var $this = $(this);

                // smazání časovače off
                timer.off = clearTimeout(timer.off);

                position.$anchor = $this;
                position.$element
                //.stop()
					.css({ 'left': '', 'top': '', 'opacity': 0 })
                //.removeClass('loader')
                //.children()
                //.empty(); 

                timer.on = setTimeout(function ()
                {
                    position.init();
                    position.$element.fadeTo(250, 1);
                }, 150);

                $(".s-avail-at").html($this.attr("sAvailAt"));
                $(".n-avail-count").html($this.attr("nAvailCount"));
                $(".s-avail-text").html($this.attr("sAvailText"));
                $(".s-avail-text-courier").html($this.attr("sAvailTextCourier"));
                $(".s-avail-market").html($this.attr("sAvailMarket"));

                //				$.ajax({
                //					type: "GET",
                //                    url: '/ajax/availability',
                //                    dataType: 'html',
                //                    //data: 'item='+$this.closest('li').find('.title a').prop('href'),
                //                    success: function(html){
                //						position.$element.removeClass('loader').children().html(html); 	
                //					}
                //				})
            }

            var out = function ()
            {
                // smazání časovače off
                timer.on = clearTimeout(timer.on);

                position.$element.stop().fadeTo(250, 0, function ()
                {
                    $(this).css({ 'left': '', 'top': '' });
                });
            };

            $(this).delegate('.availability', 'mouseenter mouseleave', function (e)
            {
                if (e.type == 'mouseenter')
                {
                    over.call(this)
                }
                else
                {
                    out.call(this)
                }
            });

        });

        $('#main').each(function ()
        {

            var $box = $('.tooltip-popup');
            var position = new sk.utils.Position({
                element: $box,
                align: [0, 0],
                place: [0, 1],
                offset: [0, 0]
            });

            var timer = {
                on: null,
                off: null
            };

            var over = function ()
            {
                var $this = $(this);

                // smazání časovače off
                timer.off = clearTimeout(timer.off);

                position.$anchor = $this;
                position.$element
					.stop()
					.css({ 'left': '', 'top': '', 'opacity': 0 })
					.children()
						.empty()
						.text($this.data('tooltip-title'));

                timer.on = setTimeout(function ()
                {
                    position.init();
                    position.$element.fadeTo(250, 1);
                }, 150);

            }

            var out = function ()
            {
                // smazání časovače off
                timer.on = clearTimeout(timer.on);

                position.$element.stop().fadeTo(250, 0, function ()
                {
                    $(this).css({ 'left': '', 'top': '' });
                });
            };

            $(this)
				.delegate('.tooltip', 'mouseenter mouseleave', function (e)
				{
				    if (e.type == 'mouseenter')
				    {
				        over.call(this)
				    }
				    else
				    {
				        out.call(this)
				    }
				})
            //		        .find('.tooltip').attr('title', function(i, old){
            //		        	$(this).data('tooltip-title', old);
            //					return '';
            //				})				
        });

        // Table corners
        var tableCorner = function (selector)
        {
            $(selector + ' table').each(function ()
            {
                $(this).wrap('<div class="table-wrap" />')
                $(this).find('tr:first td:first-child, tr:first th:first-child').addClass('bdrztl')
                $(this).find('tr:first td:last-child, tr:first th:last-child').addClass('bdrztr')
                if ($(this).find('tfoot').size() == 0)
                {
                    $(this).find('tr:last').addClass('last')
                    $(this).find('tr:last td:first-child, tr:last th:first-child').addClass('bdrzbl')
                    $(this).find('tr:last td:last-child, tr:last th:last-child').addClass('bdrzbr')
                }
            });
        }
        tableCorner('body');

        // Transport & payment
        $('.trasport-pay-list p').each(function ()
        {
            var $this = $(this),
	    		$input = $this.find('label input');

            $input.change(function ()
            {
                var $closest = $(this).closest('label');
                $this.find('label').removeClass('active');
                $closest.addClass('active');
            }).each(function ()
            {
                if ($(this).is(':checked'))
                {
                    $(this).closest('label').addClass('active');
                }
            });
        });

        // Basket product show
        $('.product-list-basket').each(function ()
        {
            var $this = $(this),
	    		$li = $this.find('li.jsHide'),
	    		$btn = $this.find('.btn'),
	    		open = false;


            $btn.click(function ()
            {
                if (open)
                {
                    $li.slideUp();
                    $btn.find('.show').removeClass('jsHide');
                    $btn.find('.hide').addClass('jsHide');
                    open = false;
                }
                else
                {
                    $li.slideDown();
                    $btn.find('.show').addClass('jsHide');
                    $btn.find('.hide').removeClass('jsHide');
                    open = true;
                }
                return false;
            });
        });

        // Step list
        $('.steps-list').each(function ()
        {
            var $this = $(this);
            $this.find('.prev').click(function ()
            {
                $('.buttons .l .inline-btn span, .buttons .l .inline-btn input').click();
            });
            $this.find('.next').click(function ()
            {
                $('.buttons .r input').click();
            });
        });

        // Open box
        $('.open-box').each(function ()
        {
            var $this = $(this);
            var $chck = $('.heading input', this);
            var $box = $('.box', $this);
            var boxHeight = $box.height();
            var attr = $chck.attr('checked')
            var size = 0;

            if ($chck.attr('checked') != undefined)
            {
                size++;
            }
            if (size != 0)
            {
                $chck.attr('checked', true);
                $this.data('status', true);
                $('.heading', $this).addClass('open');
                $box.show();
            }
            else
            {
                $chck.attr('checked', false);
                $this.data('status', false);
                $('.heading', $this).removeClass('open');
                $box.hide();
            }
            $chck.click(function ()
            {
                if ($this.data('status'))
                {
                    $chck.attr('checked', false);
                    $box
						.animate({
						    'height': '0px'
						}, 500, function ()
						{
						    $(this).css('display', 'none');
						});
                    $this.data('status', false);
                    $('.heading', $this).removeClass('open');
                }
                else
                {
                    $chck.attr('checked', true);
                    $box
						.css({
						    'display': 'block',
						    'height': '0'
						})
						.animate({
						    'height': boxHeight + 'px'
						}, 500);
                    $this.data('status', true);
                    $('.heading', $this).addClass('open');
                }
            });
        });

        // Compare table
        $('.compare-table').each(function ()
        {
            var $this = $(this),
				$faketh = $this.find('.fake-th'),
				$th = $this.find('tr');

            $th.each(function ()
            {
                $faketh.append('<p style="height:' + $(this).find('th').height() + 'px; line-height:' + $(this).find('th').height() + 'px;">' + $(this).find('th .holder').text() + '</p>');
            });
        });

        // Antispam
        $('form .antispam').each(function ()
        {
            var $this = $(this);

            $this.find('input').attr('value', $this.find('label span').text());
        });

        // Prebasket ajax
        $('.add-service').each(function ()
        {
            var $that = $(this);
            $('li', $that).each(function ()
            {
                var $this = $(this);
                $('.inline-btn', $this).click(function ()
                {
                    var $btn = $(this),
	                    $closest = $btn.closest('li');

                    var $idZaruka = $closest.find('input[name="zar"]').length > 0 ? $closest.find('input[name="zar"]').val() : "0";
                    var $idPojisteni = $closest.find('input[name="poj"]').length > 0 ? $closest.find('input[name="poj"]').val() : "0";
                    var $idBasketItem = $closest.find('input[name="basketItemID"]').val();

                    $.ajax({
                        type: "POST",
                        url: '/exec/prebasketAssurance.aspx',
                        dataType: 'text',
                        data: 'do=addassurance&count=' + ($(this).prev().is('.tick') ? '0' : '1') + '&selzaruka=' + $idZaruka + '&selpojisteni=' + $idPojisteni + '&idBasketItem=' + $idBasketItem,
                        beforeSend: function ()
                        {
                            $('img, .tick', $this).remove();
                            $btn.before('<img alt="" src="/img/pd/bg/ajax.gif" />');
                        },
                        success: function (text)
                        {
                            $('img', $that).remove();
                            $('.tick', $this).remove();
                            if (text)
                            {
                                if ($closest.hasClass('guarantee'))
                                {
                                    $('.guarantee .tick', $that).hide();
                                    $('.guarantee', $that).css('opacity', 1);
                                    $('.guarantee', $that).not($this).css('opacity', .5);
                                    //$closest.css('opacity', 1)
                                }
                                $btn.before('<span class="tick"></span>');
                            }
                            else
                            {
                                if ($closest.hasClass('guarantee'))
                                {
                                    $('.guarantee .tick', $that).hide();
                                    $('.guarantee', $that).css('opacity', 1);
                                }
                            }
                        }
                    });
                    return false;
                });
            })
        });

        // STORE SEARCH
        //        $('.stores-search').each(function () 
        //        {
        //            var $this = $(this),
        //	    		 storeDetail = function (name) {
        //	    	  	    $.ajax({
        //	    		        type: "GET",
        //	    		        url: '/ajax/store',
        //	    		        dataType: 'html',
        //	    		        data: 'storeName=' + name,
        //	    		        beforeSend: function () {
        //	    		            $this.find('.col-r').html('').append('<img src="./img/pd/bg/ajax.gif" />');
        //	    		        },
        //	    		        success: function (html) {
        //	    		            $this.find('.col-r').append(html);
        //	    		            $this.find('.col-r img').remove();
        //	    		        }
        //	    		    });
        //	    		};

        //            $this.find('form .inline-btn input').click(function () {
        //                var $closest = $(this).closest('form');
        //                $.ajax({
        //                    type: "GET",
        //                    url: '/ajax/zip',
        //                    dataType: 'text',
        //                    data: $closest.serialize(),
        //                    beforeSend: function () {
        //                        $closest.find('.fix-int').append('<img src="./img/bg/ajax.gif" />');
        //                    },
        //                    success: function (text) {
        //                        $this.find('.sk-map a').removeClass('active');
        //                        $this.find('.sk-map .' + text).addClass('active');
        //                        $closest.find('.fix-int img').remove();
        //                        storeDetail(text);
        //                    }
        //                });

        //                return false;
        //            });

        //            $this.find('.sk-map a').click(function () {
        //                var $closest = $(this).closest('.sk-map');

        //                $closest.find('a').removeClass('active');
        //                storeDetail($(this).attr('class'));
        //                $(this).addClass('active');

        //                return false;
        //            });
        //        });

        // STAR RATING
        $('.star-rating-wrap').each(function ()
        {
            var $this = $(this),
				$stars = $this.find('.star-rating a'),
				$rating = $this.find('.star-rating .rating'),
				$rate = $('.rating-input'),
				$name = $this.find('.rating-name');
            $('.star-rating')
				.delegate('a', 'click', function ()
				{
				    var i = $(this).index();
				    $rating.width(i * 24);
				    $rate.find('input').val(i);
				    $name.text($(this).attr('title'));
				    return false;
				})
				.delegate('a', 'mouseenter', function ()
				{
				    $name.text($(this).attr('title'));
				})
				.delegate('a', 'mouseleave', function ()
				{
				    $name.text($stars.eq($rate.find('input').attr('value') - 1).attr('title'));
				});
        });

        // Product detail img
        if ($(window).width() < 601)
        {
            $('.product-detail').each(function ()
            {
                var $clone = $('.product-images').clone();
                $('.product-images').remove();
                $('.product-detail').prepend($clone);
            });


        }

        // Small screen main menu
        if ($(window).width() < 800)
        {
            $('#main-menu').each(function ()
            {
                $(this).append('<select><option>Vyberte z hlavného menu</option></select>');
                var $select = $(this).find('select');
                $(this).find('li a').each(function ()
                {
                    if ($(this).closest('li').hasClass('active'))
                    {
                        $select.append('<option value="' + $(this).attr('href') + '" selected="selected">' + $(this).find('strong').text() + '</option>');
                    }
                    else
                    {
                        $select.append('<option value="' + $(this).attr('href') + '">' + $(this).find('strong').text() + '</option>');
                    }
                });
                $select.change(function ()
                {
                    window.location = $(this).find('option:selected').attr('value');
                });
            });
        }


    }); // end document ready

})(jQuery, sk);






