var inmenu = false;
var insalemenu = false;

$(document).ready(function(){
    //katalogas
	$('#sub .first > a').click(function(e){
		e.preventDefault();
        inmenu = true;
        $('#sub .last').removeClass('show-last');
		$(this).parent().addClass('show-first');
	});
    $('#sub .first').mouseover(function(){
       inmenu = true;
    });
	$('#sub .first').mouseleave(function(){
        inmenu = false;
        setTimeout(hidemenu, 700);
		//$(this).removeClass('show-first');
	});

	$('#sub .first div a').mouseenter(function(){
		$(this).parent().parent().addClass('hover');
		$(this).find('img').attr('src',$(this).find('img').attr('rel'));
	}).mouseleave(function(){
		$(this).parent().parent().removeClass('hover');
		$(this).find('img').attr('src',$(this).find('img').attr('rev'));
	});

    // akcijos
	$('#sub .last > a').click(function(e){
		e.preventDefault();
        insalemenu = true;
        $('#sub .first').removeClass('show-first');
		$(this).parent().addClass('show-last');
	});
    $('#sub .last').mouseover(function(){
       insalemenu = true;
    });
	$('#sub .last').mouseleave(function(){
        insalemenu = false;
        setTimeout(hidesalemenu, 700);
		//$(this).removeClass('show-last');
	});

	$('#akcijos li').mouseenter(function(){
		$(this).addClass('hover');
	}).mouseleave(function(){
		$(this).removeClass('hover');
	});

    $('.hovermage').hover(function(){
        if ($(this).attr('rel') != '')        
            $(this).css(
                'background-image', 'url(' + $(this).attr('rel') + ')'
            );        
    }, function(){
        if ($(this).attr('rev') != '')
            $(this).css(
                'background-image', 'url(' + $(this).attr('rev') + ')'
            );
    });
    
    $('.hovermagecat').hover(function(){
        $(this).find('img').attr('src',$(this).find('img').attr('rel'));
    }, function(){
        $(this).find('img').attr('src',$(this).find('img').attr('rev'));
    });
    
    
});

function hidemenu()
{
    if (inmenu == false)
        $('#sub .first').removeClass('show-first');
}

function hidesalemenu()
{
    if (insalemenu == false)
        $('#sub .last').removeClass('show-last');
}
