$('body').prepend('<div id="loader" style="position: fixed; top: 47%; z-index: 801; left: 47%; background: #fff;-moz-border-radius: 50px;-o-border-radius: 50px;-webkit-border-radius: 50px;border-radius: 50px;opacity: 0.5"><img src="/i/ajax-loader-big.gif" /></div>');



var popup;

var close = function() {
    popup.animate({opacity:0},300);
    setTimeout( "popup.remove();", 300);

    setTimeout( "$('#xs').animate({opacity: 0},200);", 400);
    setTimeout( "$('#xs').css({display: 'none'},1);", 600);
}

$(document).ready(function() {

	$('#loader').fadeOut(function() {$(this).remove()})

    $(document.body).prepend($("#xs").remove());
    $('.cat_item').hover(function() {
        $(this).children('.hov').show();
    }, function() {
        $(this).children('.hov').hide();
    });
    $('.cat_item').css({cursor: 'pointer'});
    $('.cat_item').click(function() {
        $("#xs").css({display: "block"},1);
        $("#xs").animate({opacity: "0.8", height: $(".ttb").height()}, 200);
        popup = $(this).children(".ima").clone();
        $(document.body).prepend(popup);
        $('.crs:visible').live('click',close);
        popup.css({display: "block", top: $(window).scrollTop() + Math.floor(($(window).height() - popup.height()) / 2)},1);
        popup.find('.mat_item').hover(function() {
            $(this).children('.hov').show();
        }, function() {
            $(this).children('.hov').hide();
        });
        setTimeout("popup.animate({opacity: 1},300);", 300);
    });
    $('.preview_img').css({cursor: 'pointer'}).click(function() {
        $(this).parent('div').parent('td').parent('tr').find('.cat_item').click();
    });
});
