var opacityStartBool = false;
var opacityStartCount = 0.1;
var lastElement = 'Wszystko';
var size = 0;
var i;

$(function() {
    $('.offerBoxImg a').lightBox();
});

$(document).ready(function(){
    $('span.oferta').click(function(){
        if ( lastElement != $(this).attr('id') ) {
            lastElement = $(this).attr('id');
            opacityStart();
            if ( lastElement == 'Wszystko' ) {
                i = 0;
                $('#offer').children('div').css('display', 'block');
                $('div.offerSeparatorKomputer, div.offerSeparatorNotebook, div.offerSeparatorMonitor, div.offerSeparatorDrukarka, div.offerSeparatorPodzespol').each(function(){
                    i++;
                    if ( i % 4 == 0 )$(this).css('display', 'none');
                });
            }
            else {
                i = 0;
                $('#offer').children('div').css('display', 'none');
                $('div.offerBox' + lastElement).css('display', 'block');
                $('div.offerBox' + lastElement).each(function(){
                    i++;
                    if ( i % 4 != 0 )$(this).siblings('div.offerSeparator' + lastElement).css('display', 'block');
                });
            }
            
        }
    });
    $('span.oferta').mouseover(function(){
        $(this).css('color', '#b9cbe1');
    });
    $('span.oferta').mouseout(function(){
        $(this).css('color', '#fff');
    });
    $('#idealny_prezent').click(function(){$(this).css('display', 'none')});
});


function opacityStart() {
    if ( opacityStartBool ) {
        $('#offer').css('opacity', '1');
    }
    else {
        opacityStartTrue();
    }
}

function opacityStartTrue() {
    if ( opacityStartCount <= 1 ) {
        $('#offer').css('opacity', opacityStartCount);
        opacityStartCount = opacityStartCount + 0.1;
        setTimeout('opacityStartTrue()', 10);
    }
    else {
        opacityStartCount = 0.1;
        opacityStartBool = false;
    }
}


