$(document).ready(function(){

    $('img').waypoint(function(event, direction){
        var objImg = this;
        setTimeout(function(){
            var deferred = objImg.getAttribute('deferred');
            if (deferred) {
                $(objImg).animate({
                    opacity: 0.1
                }, 250, function(){
                    objImg.src = deferred;
                    //console.log('Lazy loading img:', objImg.getAttribute('deferred'));
                }).animate({
                    opacity: 1.0
                }, 1000);
            }
        }, 250);
    }, {
        triggerOnce: true,
        offset: function(){
            return $.waypoints('viewportHeight') - $(this).height();
        }
    });
    
    
    $('.nyroModal').nyroModal({
        errorMsg: 'Błąd - PRZEPRASZAMY - pracujemy już nad problemem', // Error message
    });
    
    // facebook
    $("#facebookContener").mouseover(function(){
        $(this).stop().animate({
            "left": "0px"
        }, 400);
    });
    $("#facebookContener").mouseout(function(){
        $(this).stop().animate({
            "left": "-220px"
        }, 400);
    });
    

    $("#tabs").tabs();
    $("#notecontent").hide();
    
    /*
     * category box
     * lista kategorii dla zakładek w top
     * all
     */
    $(".tab").click(function(){
    
        $(".tab").removeClass('tab-active').addClass('tab-inactive');
        
        $(this).removeClass('tab-inactive').addClass('tab-active');
        //var div = $.post(getBasePath+'/brand/index/key/'+$(this).attr('id'));
        $('#banner').html('loading ...').load(getBaseUrl + '/brand/box/key/' + $(this).attr('id'));
    });
    
    
    /*
     * cluetip
     */
    $('a.category_cluetip').cluetip({
        width: '400px'
    });
    $('a.category_list_cluetip').cluetip({
        width: '400px'
    });

    $('#cluetip').draggable({
        handle: '#cluetip-title'
    });
    $('#cluetip-title').css('cursor', 'move');
    
    
});

/*
 * js error log
 */
window.onerror = function(msg, url, line){
    if (encodeURIComponent) {
        var params = "msg=" + encodeURIComponent(msg) + '&url=' + encodeURIComponent(url) + "&line=" + line;
        $.ajax({
            type: "POST",
            url: getBaseUrl + "/index/jserror",
            data: params
        });
    }
    return false;
}

//popup Lukas

var myPopupWindow = '';
function openPopupWindow(url, name, width, height){


    if (!myPopupWindow.closed && myPopupWindow.location) {
        myPopupWindow.location.href = encodeUrl(url);
    }
    else {
        myPopupWindow = window.open(url, name, "location=no, scrollbars=yes, resizable=yes, toolbar=no, menubar=no, width=" + width + ", height=" + height);
        if (!myPopupWindow.opener) 
            myPopupWindow.opener = self;
    }
    
    if (window.focus) {
        myPopupWindow.focus()
    }
    
    return false;
}

