var currentUserSetPopupTop = 10;
var tempScrollTop, currentScrollTop = 0;

$(function () {
    
    /*
        -----------------------------
        HOVER EFEKT NAD MENU
        -----------------------------
    */
    $('li[rel=category-list]').hover(
        function () {
            if($(this).attr('class') === 'active'){
                $(this).removeClass().addClass('active category-hover');
            } else {
                $(this).removeClass().addClass('category-hover');
            }
        }, 
        function () {
            if($(this).attr('class') === 'category-hover'){
                $(this).removeClass();
            } else {
                $(this).removeClass().addClass('active');
            }
        }
    );
    
    /*
        -----------------------------
        ORAMOVANIE FIELDOV
        -----------------------------
    */
    
    var color1 = '#DBDBDB';
    var color2 = '#FF8400';
    
    $('#right form input:text, #right form input:password, #right form textarea').hover(
        function () {
            $('#right form input:text').css({'border' : '1px solid ' + color1});
            $(this).css({'border' : '1px solid ' + color2});
        }, 
        function () {
            $(this).css({'border' : '1px solid ' + color1});
        }
    );
    
    
    /*
        -----------------------------
        CART SUMMARY ITEMS
        -----------------------------
    */
    $('body').append('<div id="eshop-cart-summary-items"></div>');
    
    $('#eshop-cart-summary a').mouseover(
        function(){
            var offset = $('#eshop-cart-summary').offset();
            $.get(
                LANGROOT + "/eshop/cart/popup/"
               ,function(result){
                   $('#eshop-cart-summary-items').css({
                       'top' : offset.top + 78,
                       'left' : offset.left - 301
                   }).html(result).slideDown(1000);
                   
                   $('#eshop-cart-summary-items img.close').click(function(){
                       $('#eshop-cart-summary-items').hide();
                   }).css({
                       'cursor':'pointer'
                       ,'position' : 'absolute'
                       ,'top' : '10px'
                       ,'right' : '10px'
                   });
               }
           );
        }
    );
    
    $('#eshop-cart-summary-items').draggable().css({'cursor' : 'move'});
    
    
    /* 
        -----------------------------
        VASA ZOSTAVA - POPUP OKNO
        -----------------------------
    */
    var window_width = $(window).width();
    var body_width = $('#body').width();
    var user_set_popup_width = $('#eshop-user-set-popup').width();
    var right_outer_width = parseInt((window_width - body_width) / 2, 10);
    var user_set_popup_right = 15;
    if (right_outer_width - 15 > user_set_popup_width) {
        user_set_popup_right = right_outer_width - user_set_popup_width;
        user_set_popup_right -= 15;
    }
    $('#eshop-user-set-popup').css({
        top: 10,
        right: user_set_popup_right
    });
    $('#eshop-user-set-popup img.close').click(function() {
        $('#eshop-user-set-popup').hide();
    }).css({
         'cursor':'pointer'
        ,'position' : 'absolute'
        ,'top' : '10px'
        ,'right' : '10px'
    });
    $('#eshop-user-set-popup').show();
    $('#eshop-user-set-popup').draggable({
        stop: function () {
            currentUserSetPopupTop = $('#eshop-user-set-popup').position().top - $(document).scrollTop();
        }
    });
    $('#eshop-user-set-popup').draggable().css({'cursor' : 'move'});
    
    $(window).scroll(function () {
        $('#eshop-user-set-popup').css({
            top: currentUserSetPopupTop + $(document).scrollTop()
        });
    });
    
    /* 
        -----------------------------
        DARCEK - POPUP OKNO
        -----------------------------
    */
    $('.eshop-product-gift-popup img.close').click(function() {
        $(this).parent().hide();
    }).css({
         'cursor':'pointer'
        ,'position' : 'absolute'
        ,'top' : '10px'
        ,'right' : '10px'
    });
    $('.productGift').hover(function () {
        var product_id = $(this).attr('rel');
        var offset = $(this).offset();
        $('.epgp_' + product_id).css({
            top: offset.top - 10,
            left: offset.left + 345
        });
        $('.epgp_' + product_id).show()
    }, function () {
        var product_id = $(this).attr('rel');
        $('.epgp_' + product_id).hide();
    });
    $('.productGiftList').hover(function () {
        var product_id = $(this).attr('rel');
        var offset = $(this).offset();
        $('.epgp_' + product_id).css({
            top: -50,
            left: 188
        });
        $('.epgp_' + product_id).show()
    }, function () {
        var product_id = $(this).attr('rel');
        $('.epgp_' + product_id).hide();
    });
    // $('#eshop-product-gift-popup').draggable();
    
    /* 
        -----------------------------
        VIDEO K PRODUKTU - POPUP OKNO
        -----------------------------
    */
    $('#product-video-popup img.close').click(function() {
        $('#product-video-popup').hide();
        $('#product-video-overlay').remove();
    }).css({
         'cursor':'pointer'
        ,'position' : 'absolute'
        ,'top' : '10px'
        ,'right' : '10px'
    });
    
    $('#productVideo')
    .css('cursor','pointer')
    .click(function () {
        restoreVideoPopupPosition();
        $('#product-video-popup').show();
        $('body').append($('<div id="product-video-overlay"></div>'));
        $('#product-video-overlay').css({
            width: $(document).width(),
            height: $(document).height(),
            opacity: 0.7
        });
    });
});

function restoreVideoPopupPosition() {
    var video_top = parseInt(($(window).height() / 2) + $(document).scrollTop() - ($('#product-video-popup').height() / 2), 10);
    var video_left = parseInt(($(window).width() / 2) - ($('#product-video-popup').width() / 2),10);
    $('#product-video-popup').css({
        top: video_top,
        left: video_left
    });
}
